问题
I am trying to compile a Fortran code including OpenMP. I am replicating the use of OpenMP from a different code. It built successfully once yesterday and then the next time I built it I get the following error:
../MAXBRG3D.f90:3:4:
USE OMP_LIB ! USED WITH OMP FUNCTIONS
1
Fatal Error: Can't open module file 'omp_lib.mod' for reading at (1): No such file or directory
compilation terminated.
subdir.mk:329: recipe for target 'MAXBRG3D.o' failed
make: *** [MAXBRG3D.o] Error 1
The only changes I made to the code where to comment out a few sections of code unrelated to the OpenMP capabilities. I have since removed the comments but am still getting the same error. My compilation command is as follows.
gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -fopenmp -o "MAXBRG3D.o" "../MAXBRG3D.f90"
I have seen the following link: gfortran can't find OpenMP library (omp_lib.mod) under MinGW
and when I run gfortran -v, --enable-libgomp
does show up.
>gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
I was able to run the following little Fortran code.
PROGRAM TEST
INTEGER M
REAL C(3), D(3)
M=3
C(1) = 2
C(2) = 5
C(3) = 10
call A1(M,C,D)
write(*,5)D(3)
5 format(1x,'D3=',G12.5)
END PROGRAM
SUBROUTINE A1(N, A, B)
INTEGER I, N
REAL B(N), A(N)
!$OMP PARALLEL DO !I is private by default
DO I=2,N
B(I) = (A(I) + A(I-1)) / 2.0
ENDDO
!$OMP END PARALLEL DO
END SUBROUTINE A1
Also I do have libgomp.a, libgomp.dll.a, libgomp.spec, (located in MinGW\lib\gcc\mingw32\6.3.0) and libgomp-1.dll (located in MinGW\bin).
回答1:
I have solved this problem. I commented out the USE OMP_LIB
line and I just initialized the functions that I wanted to use.
Previously I found an example which initialized the functions as
INTEGER FUNCTION OMP_GET_THREAD_NUM()
This was not working. However I found a different example which initialized the functions just as integers. So
INTEGER OMP_GET_THREAD_NUM
This seems to have solved the problem and now the code is compiling and running.
来源:https://stackoverflow.com/questions/46849793/gfortran-cant-find-openmp-library-omp-lib-mod-using-mingw