- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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")
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at OMP_WAIT_POLICY, and KMP_BLOCKTIME in the IVF documentation under: OpenMP directives | Using OpenMP*
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
[fortran]
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)
!$OMP PARALLEL
call kmp_set_blocktime(0)
!$OMP MASTER
call kmp_set_blocktime(0)
do i = 1, 4
!$OMP TASK FIRSTPRIVATE(i)
print *, 'Hello World', omp_get_thread_num()
!$OMP END TASK
end do
!$OMP TASKWAIT
pause !Note CPU useage is high while we wait for user to press enter
!$OMP END MASTER
!$OMP BARRIER
!$OMP END PARALLEL
end program
[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page