Fortran uses implicit typing by default, meaning that undeclared variables/functions starting with (a-h,o-z)
are real. Your solution is to either add the correct type of the runtime routines, like:
integer omp_get_num_threads
or, better, add implicit none
in the beginning to deactivate implicit typing and then include the header file:
implicit none
include 'omp_lib.h'
EDIT:
that the number of threads outside the parallel region is 1 is fine, however, in the parallel region it should indeed be 4. It could be possible that you're mixing fixed and free format, the former requires the omp directive (e.g. C$OMP
) at the beginning of a line (on column 1), like so:
program test
include 'omp_lib.h'
write(*,*) 'num_proc = ',omp_get_num_procs()
write(*,*) 'max_threads = ',omp_get_max_threads()
write(*,*) 'num_threads = ',omp_get_num_threads()
C$OMP PARALLEL DO
do i=1,4
write(*,*) 'num_threads = ',omp_get_num_threads()
end do
end
If you are using free-form, then you can use !$OMP
anywhere on a line. The tricky thing is that most compilers allow !
comment statements even in fixed format source code, but then openmp directives only work when the comment is at the beginning.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…