連結已複製
5 threads is an unsuual number - do you have 5 cores or processors on your system? By default it uses the number of "logical processors". What model of processor is in your system and how many? Maybe your program has too much overhead for more (I assume) threads?
OpenMP may add a watchdog thread (depending on the version of OpenMP). Set break point inside of parallel region, then use debugger threads window. If one of the threads is inside a routine ...watchdog... then this is the case and you can ignore the 5-thread issue (as 4 are worker threads).
Jim Dempsey
When I use OMP_SET_NUM_THREADS(3) I get 75% CPU usage as expected. When I try something like
integer :: nt
nt = OMP_GET_MAX_THREADS()
CALL OMP_SET_NUM_THREADS(nt-1)
then CPU usage goes down to 25%. If I set it to a number larger than the number of cores I have (say 12) I still get only 25% CPU usage.
I'm a bit confused. Is this what you are seeing?
CALL OMP_SET_NUM_THREADS(4) ! results in 100% CPU usage
CALL OMP_SET_NUM_THREADS(3 ) ! results in 75% CPU usage
CALL OMP_SET_NUM_THREADS(12 ) ! results in 25% CPU usage
Just before the code enters the parallel region, can you put the write statement I suggested earlier. This is to make sure the the number of threads running is what you expect.
write(*,*) "Number of threads = ", OMP_GET_MAX_THREADS()
Roman
Roman, thanks for suggesting to print the number of threads again. It allowed me to figure out what was happening and solve the problem. I have the paralellization in a module compiled as a static library. The calls to set the maximum number of threads are made in a subroutine. So everytime I call the subroutine I was setting the number of threads to the maximum number of threads less 1. So in 4 calls to the subroutine I was going from 4 threads to 1 thread.I simply needed to set the number of threads once in the main program.
Thanks for the help.
Jon
