My example .f90 code can have 4 threads with openMP compiling option (-mp) on. But my project code can have only 1 thread with the same compiling options as the example code.
Anyone have an idea?
Thanks
My example .f90 code can have 4 threads with openMP compiling option (-mp) on. But my project code can have only 1 thread with the same compiling options as the example code.
Anyone have an idea?
Thanks
Did you specify the number of the threads? The default is 1 otherwise. Though you can change the default to use the same as the number of cores by compiling with “-mp=allcores”.
This is the example code:
…
call omp_set_num_threads(4)
!$OMP parallel private (n)
!$OMP DO
do n=1,4
print *, “Thread “,OMP_GET_THREAD_NUM(),” local sum: 111”
enddo
!$OMP ENDDO
!$OMP END paralleL
…
It shows 4 threads.
The same code is pasted into my project program and returns 1 thread.
I have tried to make all compiling options the same, but it always does the same.
This is visual fortran.
Did you remember to add “use omp_lib” or “include omp_lib.h”?
program tomp
use omp_lib
integer :: n
call omp_set_num_threads(4)
!$OMP parallel private (n)
!$OMP DO
do n=1,4
print *, "Thread ",OMP_GET_THREAD_NUM()," local sum: 111"
enddo
!$OMP ENDDO
!$OMP END paralleL
end program tomp
The example code works without this :
use omp_lib.
If I add it, both codes wouldn’t compile showing an error message:
Error 1 omp_get_thread_num is use associated and cannot be redeclared …
Error 1 omp_get_thread_num is use associated and cannot be redeclared …
This means omp_get_thread_num was declare twice. Do you manually declare it someplace? Did you accidently add both “use omp_lib” and “include omp_lib.h”? (only one should be used).