Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

OpenMP waiting threads consumming CPU

Andrew_Smith
Valued Contributor I
1,841 Views

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")

0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
1,841 Views

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

Jim Dempsey

0 Kudos
Andrew_Smith
Valued Contributor I
1,841 Views

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.

0 Kudos
Andrew_Smith
Valued Contributor I
1,841 Views

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]

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,841 Views

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

0 Kudos
Reply