OpenMP TASKS all run on thread 0

The following code appears to run only on only one thread. In the calling program I have called OMP_SET_NESTED(.true.) and compiled using the -mp flag

recursive integer function lemma4 (c,la,lb,m) result (nswaps)
implicit none
integer c(0:), la, lb, m
integer ns1, ns2, lab, m2, lam2
integer lemma3
external lemma3
integer OMP_GET_THREAD_NUM
external OMP_GET_THREAD_NUM
nswaps = 0
if(la.eq.0.or.lb.eq.0) return
if(m.eq.1) return
m2 = m/2
lab = la+lb
lam2 = la
m2
!$OMP PARALLEL SHARED(c,m2,la,lb,lab,lam2) NUM_THREADS(16)
!$OMP SINGLE
!$OMP TASK SHARED(c,m2,la,lb,lab,lam2)
ns1 = lemma4(c,la,lb,m2)
!$OMP END TASK
!$OMP TASK SHARED(c,m2,la,lb,lab,lam2)
ns2 = lemma4(c(labm2),la,lb,m2)
!$OMP END TASK
!$OMP END SINGLE
!$OMP END PARALLEL
write(
,’(a,i4)’)"Thread number ",OMP_GET_THREAD_NUM()
nswaps = ns1 + ns2 + lemma3(c(lam2),lb*m2,lam2)
return
end

Hi David611,

I believe the problem is that with the “SINGLE” directive, the other threads will wait at the end of directive until the thread that is executing the region is done. Hence, you only have one thread available to perform the tasks.

Try adding the “nowait” clause to the “SINGLE” directive to have the other threads progress.

Note that I found this example which might help improving your performance: https://en.wikibooks.org/wiki/OpenMP/Tasks

Hope this helps,
Mat