It seems to me that having a critical section withic a parallel block in OpenMP makes no sense! I might just well write a simple serial do loop right?
In the following (trivial) example instead of
1.
!$omp critical
!$ thread_num = omp_get_thread_num()
print *, "Hello world from thread number ", thread_num
!$omp end critical
!$omp end parallel
2.
do i=1,num_threads
print *, "Hello world from thread number ", thread_num
end do
That being said, I understand the difference: 1. uses different threads while 2. doesn't.
Is there a non-trivial context where the former might actually provide a speed advantage over the latter?