Troubleshooting a Fortran 77 Program with OpenMP

Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a Fortran 77 program that aims to utilize OpenMP for parallel processing on a dual-core processor. Participants explore compilation issues, compatibility of the g77 compiler with OpenMP, and the necessary commands to successfully compile and link the program.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant is attempting to compile a Fortran 77 program using OpenMP but encounters linking errors related to undefined references to OpenMP functions.
  • Another participant suggests that the unresolved references may indicate that the OpenMP library is intended for C/C++ programs rather than Fortran, proposing the need for a Fortran interface library.
  • A different participant inquires about the version of GCC being used, implying that compatibility may be an issue.
  • One participant advises using the -l option to link to the OpenMP library, indicating that the correct library name must be specified.
  • Another participant mentions successfully building a program using GCC 4.2, noting that earlier versions of GCC may not support OpenMP.
  • One participant shares their experience with g77 and its limitations, specifically mentioning that the version being used (3.4.6) may not support OpenMP extensions.
  • Another participant expresses uncertainty about the existence of an OpenMP library, suggesting that OpenMP might be built into the compiler.
  • One participant raises a question about running a gfortran executable in a Unix environment, indicating a lack of familiarity with Unix commands.

Areas of Agreement / Disagreement

Participants generally agree that the version of g77 being used may not support OpenMP, but there is no consensus on the exact nature of the solution or whether an OpenMP library is necessary. The discussion remains unresolved regarding the best approach to compile the program successfully.

Contextual Notes

Limitations include the potential lack of OpenMP support in the g77 version being used, uncertainty about the availability of an OpenMP library, and the need for specific compiler flags that may not be recognized by the current setup.

JoAuSc
Messages
197
Reaction score
1
I'm trying to get a fortran 77 program to run faster on a computer with a dual-core processer, so I'm trying to learn how OpenMP works. Unfortunately, I can't get the "hello world" file on the wikipedia page to compile.

(Here's the code:
Code:
      PROGRAM HELLO
      INTEGER ID, NTHRDS
      INTEGER OMP_GET_THREAD_NUM, OMP_GET_NUM_THREADS
!$OMP PARALLEL PRIVATE(ID)
      ID = OMP_GET_THREAD_NUM()
      PRINT *, 'HELLO WORLD FROM THREAD', ID
!$OMP BARRIER
      IF ( ID .EQ. 0 ) THEN
        NTHRDS = OMP_GET_NUM_THREADS()
        PRINT *, 'THERE ARE', NTHRDS, 'THREADS'
      END IF
!$OMP END PARALLEL
      END

I'm using G77 as a compiler. I think I'm supposed to compile it as

Code:
...> g77 HelloWorld.f -openmp

I get the following error:

Code:
/tmp/cc2XahMo.o(.text+0xe): In function 'MAIN__':
: undefined reference to 'omp_get_thread_num__'
/tmp/cc2XahMo.o(.text+0x75): In function 'MAIN__':
: undefined reference to 'omp_get_num_threads__'
collect2: ld returned 1 exit status

I don't think the problem's that g77 doesn't accept openmp, because if I have

Code:
...> g77 -openmp

without the filename, it has a different error message than replacing "-openmp" with "-gdfgs" or something, specifically,
Code:
g77: no input files; unwilling to write output files
rather than
Code:
g77: no input files

Could someone who knows something about g77 or openMP help me?
 
Technology news on Phys.org
Most likely the problem is that the openMP library is meant to link to C or C++ programs not Fortran.

The clue is the fact that the unresolved reference is omp_get_thread_num__ (with some underscores at the end) not omp_get_thread_num which is presumably the C function you are trying to call.

Either you need a Fortran interface library, or you need to tell your compiler these are C functions. I expect there's a way to do that, but I don't have g77.

FWIW the command g77 -openmp is probably trying to create an object file called penmp.o, or an executable called penmp or penmp.exe, independent of the name of your .f file - which is a legal command, but not what you wanted to do!

Also FWIW some compiler systems understand the option -mp (not -openmp).
 
What version of GCC are you using? (i.e. g77 -v)
 
You need to tell g77 to link to your OpenMP library file with the -l option. something like
Code:
g77 helloworld.f -o helloworld -l<openmp library name>
where you replace <openmp library name> with the name of the OpenMP library minus the leading 'lib' and the extension
i.e. if your openMP library is called libopenmp.so (or libopenmp.a), then you use libopenmp

you might also have to specify the path to your OpenMP library with -L if it's not in the compiler's library search path

It's been a while since I worked with g77, but since it's just a front-end to gcc now, it should work. I've also not worked with OpenMP before, so I'm not positive there's a library that goes with it but if there is this is what you'd need to do.
 
Last edited:
I was able to build using GCC 4.2. As far as I understand, GCC did not support openmp prior to 4.2 (although some people built it into 4.1 on a provisional basis, e.g. fedora core 5/6).

I built GCC 4.2, than ran

/my/gcc4.2dir/gfortran -fopenmp hello_f77.f

with GCC 4.2 directories (including gmp and mpfr) at the front of LD_LIBRARY_PATH.

Not sure g77 will do that for you, as g77 is an artifact of pre-4.0 (unless you renamed your GCC 4.2 gfortran g77).

Maybe simply linking against the openmp lib will do it, pls let us know if that works.
 
Aleph:
Yes, -openmp was apparently trying to create a file named penmp.out or something. I must've read this site, which has the tag as -fopenmp, and forgot the f. Unfortunately, here's what I got:
Code:
...> g77 HelloWorld.f -fopenmp
f771: error: unrecognized command line option "-fopenmp"

I also tried -mp and -MP, but neither worked.

FYI, I'm using g77 which was installed on my school's computers, and I'm using tera term (unix).


nmtim, here's what I got for g77 -v:
Code:
...> g77 -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/u
sr/shar/info --enable-shared --enable-threads=posix --disable-checking --with-s
ystem-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-aw
t=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)
So, to answer your question, version 3.4.6.

imabug: I'd try that, but I'm not sure where the OpenMP library is.
 
After doing a little more reading, I get the impression that OpenMP is a set of compiler extensions that's usually built in, so there may not be a library. nmtim is probably correct and your compiler version may not support the OpenMP extensions.
 
I'm guessing nmtim is right about openMP not being included.


So, next question: A while back I installed gfortran on the computer in my directory. However, I can't figure out how to use it in unix. (The file is gfortran.exe, and I've used it in the DOS command prompt without problems.) Can you run .exe files in a unix terminal?
 
JoAuSc said:
I'm guessing nmtim is right about openMP not being included.


So, next question: A while back I installed gfortran on the computer in my directory. However, I can't figure out how to use it in unix. (The file is gfortran.exe, and I've used it in the DOS command prompt without problems.) Can you run .exe files in a unix terminal?

It might run through WINE, but generally, no
 

Similar threads

  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
10K
  • · Replies 8 ·
Replies
8
Views
4K