Test which checks the omp master directive by counting up a variable in a omp master section. It also checks that the master thread has the thread number 0 as specified in the OpenMP standard version 3.0.
3.0
omp master
omp critical
INTEGER FUNCTION omp_master_3()
IMPLICIT NONE
INTEGER omp_get_thread_num
INTEGER nthreads, executing_thread
INTEGER tid_result ! counts up the number of wrong thread no.
! for the master thread
COMMON /orphvars/ nthreads, executing_thread, tid_result
tid_result = 0
nthreads=0
executing_thread=-1
!$omp parallel
!$omp master
if (omp_get_thread_num() .ne. 0) then
!$omp critical
tid_result = tid_result + 1
!$omp end critical
end if
!$omp critical
nthreads = nthreads + 1
!$omp end critical
executing_thread=omp_get_thread_num()
!$omp end master
!$omp end parallel
IF ( (nthreads .EQ. 1) .AND. (executing_thread .EQ. 0) .AND.
& (tid_result .EQ. 0) ) THEN
= 1
ELSE
= 0
END IF
END