I have a program that worked fine in parallel in FORTRAN 95. At the start of the code I used OMP_SET_NUM_THREADS(2). I have added functionality from a library that requires -Miface-cref to be used and now get “unresolved external symbol OMP_SET_NUM_THREADS” when linking. Any help?
BTW, Vista 64-bit.
Add “use omp_lib” at the top of the subroutine in order to get the correct cref naming.
Hope this helps,
Thank you for your reply.
I tried adding that but I get more unresolved externals (omp_lib and omp_lib_kinds). Do I need to specify the omp_lib in the command line manually given my situation? I am trying to call all of these functions from within the main program. Does that complicate the matter?
Can you please post more information such as your link line and output and/or a small reproducing example?
I was unable to reproduce the issue here and given that omp_lib and omp_lib_kinds are just module names, I don’t know why you would get unresolved external references.
Note: I read in one of the manuals last night that you can only use one type of referencing when calling libraries. Might this be the problem? Are the OpenMP functions like OMP_SET_NUM_THREADS called from a library that doesn’t use cref?
I used some example code from the manual and was able to reproduce the error (my program is big, complicated and definitely not a good example of good programming practice).
INTEGER I, N, OMP_GET_THREAD_NUM
REAL*8 V(1000), GSUM, LSUM
TEC = TecIni112(‘LBE DATASET’//CHAR(0), &
‘X Y Z BNUM RHO U V W SPEED’//CHAR(0), &
GSUM = 0.0D0
N = 1000
DO I = 1, N
V(I) = DBLE(I)
!$OMP PARALLEL PRIVATE(I,LSUM) SHARED(V,GSUM,N)
LSUM = 0.0D0
DO I = 1, N
LSUM = LSUM + V(I)
!$OMP END DO
print *, "Thread “,OMP_GET_THREAD_NUM(),” local sum: ",LSUM
GSUM = GSUM + LSUM
!$OMP END CRITICAL
!$OMP END PARALLEL
PRINT *, "Global Sum: ",GSUM
The include file contains interfaces for the functions in the library tecio.lib. To get the library working I add the following to both the FORTRAN and Linker command lines in Visual Studio: “C:\Program Files\tecplot\Tec360 2009\bin\tecio.lib” -Miface=cref. When I try to compile I get:
hello.obj : error LNK2019: unresolved external symbol OMP_SET_NUM_THREADS referenced in function MAIN_
hello.obj : error LNK2019: unresolved external symbol OMP_GET_THREAD_NUM referenced in function MAIN_
C:\Users\Dale\Documents\Research\PVFProject2\PVFProject2\x64\Debug\PVFProject2.exe : fatal error LNK1120: 2 unresolved externals
PVFProject2 build failed.
All you need to do is add “use omp_lib” just after “PROGRAM MAIN” and remove the declaration of OMP_GET_THREAD_NUM.
For example, I removed the “TECIO.F90” stuff and added omp_lib:
PGI$ cat omp.f90 PROGRAM MAIN use omp_lib INTEGER I, N REAL*8 V(1000), GSUM, LSUM CALL OMP_SET_NUM_THREADS(2) GSUM = 0.0D0 N = 1000 DO I = 1, N V(I) = DBLE(I) ENDDO !$OMP PARALLEL PRIVATE(I,LSUM) SHARED(V,GSUM,N) LSUM = 0.0D0 !$OMP DO DO I = 1, N LSUM = LSUM + V(I) ENDDO !$OMP END DO !$OMP CRITICAL print *, "Thread ",OMP_GET_THREAD_NUM()," local sum: ",LSUM GSUM = GSUM + LSUM !$OMP END CRITICAL !$OMP END PARALLEL PRINT *, "Global Sum: ",GSUM STOP END PGI$ pgf90 -Miface=cref omp.f90 Creating library omp.lib and object omp.exp
If it still fails, can you send the full code to PGI Customer Service (email@example.com)?
Hope this helps,