OpenMP waiting threads consumming CPU

OpenMP waiting threads consumming CPU

I have a Fortran code which exclusively uses OpenMP tasking. I start the parallal region right at the beginning and stop when the program stops. The code is run by the master thread and it spawns tasks. But after a set of tasks is complete and the master task is waiting for input from a pipe, the idle tasks are spinning the CPU (green bar on task manager). The computer seams to be still fully responsive to other programs but it is undesirable to have it look so busy when it is not. I have not set any OpenMP controlling environment variables but I make some calls before starting the parallel region:

maxThreads = OMP_Get_Num_Procs()

call omp_Set_Num_Threads(maxThreads)

call MKL_Set_Num_Threads(maxThreads)

call kmp_set_defaults("KMP_WARNINGS=0")

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Look at OMP_WAIT_POLICY, and KMP_BLOCKTIME in the IVF documentation under: OpenMP directives | Using OpenMP*

Jim Dempsey

Thanks Jim. I tried OMP_WAIT_POLICY=PASSIVE, and KMP_BLOCKTIME=0 but no change in behaviour, the threads are still consumming CPU while waiting. I will try to make a test code.

Here is test case. I added far more calls to kmp_set_blocktime than I needed just make sure it took effect and also set the environment variable as well. The idle threads remain actively polling the CPU while having no work.

program Console3
   use omp_lib
   implicit none
   integer i
   call kmp_set_defaults("KMP_BLOCKTIME=0")
   call kmp_set_defaults("OMP_WAIT_POLICY=PASSIVE")
   call kmp_set_blocktime(0)
   call kmp_set_blocktime(0)
   call kmp_set_blocktime(0)
   do i = 1, 4
      print *, 'Hello World', omp_get_thread_num()
      !$OMP END TASK
   end do
   pause !Note CPU useage is high while we wait for user to press enter
end program

Ah. BARRIER is not subject to block time timeout, its spin time is infinite (though apparently it includes a sched_yield or equivilent). If you want thread suspension, then you will have to exit the parallel region. OpenMP tasking is not equivilent to pthread wait on condition variable, nor Windows WaitForSinglEvent, rather it is more like co-routine polling. This may be suitable for a feature request, provided you can supply a compelling argument. The barrier is intended for short interval, low overhead, synchronization.

Jim Dempsey

Leave a Comment

Please sign in to add a comment. Not a member? Join today