Setting the number of threads once at the beginning of the program definitely doesn’t work. If, in the initialisation section of the program, I put the code:
nthreads = omp_get_num_procs()
call omp_set_num_threads(nthreads)
open (12, file='threadcount.txt', status='REPLACE')
!$omp parallel
nthreads = omp_get_num_threads()
!$omp end parallel
write (12,*) 'In omp_init, nthreads = ', nthreads
close(12)
…then it is clear from the resulting file that the correct number of threads has been set. If, before the first parallelised loop, I then put the code:
open (12, file='threadcount.txt', status='REPLACE')
write (12,*) 'In Make_Incident_Image...'
close(12)
!$omp parallel
nthreads = omp_get_num_threads()
!$omp end parallel
open (12, file='threadcount.txt', status='REPLACE')
write (12,*) 'In Make_Incident_Image, nthreads = ', nthreads
close(12)
…then the application crashes, and the file contents indicate that it was at the “omp_get_num_threads” that it crashed.
Furthermore, if I then try to insert:
nthreads = omp_get_num_procs()
call omp_set_num_threads(nthreads)
…into the routine before the open(12…), then it becomes clear that that the file is never even opened. In other words, any OpenMP command at all, following the first initialisation, causes a crash.
Could this behvaiour be connected with the fact that the Fortran code here is all in a DLL called from a C++ GUI, and each execution of a Fortran routine is in a discrete call from C++? [/code]