2014-05-11 01:02:09 +08:00
<ompt s : test >
<ompt s : testdescription > Test which checks that the omp_get_num_threads re turns the correct number of threads. Therefor it counts up a variable in a parallelized section and compars this value with the result of the omp_get_num_threads function.</ompts:testdescription>
<ompt s : ompversion > 2.0 < / ompts : ompversion >
<ompt s : directive > omp_get_num_threads < / ompts : directive >
<ompt s : testcode >
INTEGER FUNCTION < ompts : testcode : functionname > omp_num_threads < / omp ts:testcode:functionname>()
IMPLICIT NONE
INTEGER i , max_threads
INTEGER omp_get_num_threads
<ompt s : orphan : vars >
INTEGER failed , threads , nthreads , tmp
COMMON / orphvars / failed , threads , nthreads
</omp t s : orphan : vars >
failed = 0
max_threads = 0
!$omp parallel
!$omp master
max_threads = OMP_GET_NUM_THREADS ( )
!$omp end master
!$omp end parallel
! print *, "max threads:",max_threads
!Yi Wen added omp_Set_dynamics here to make sure num_threads clause work
!Thanks to Dr. Yin Ma in Absoft. should be not be called before the test loop
2014-06-02 02:28:36 +08:00
!because it allows the dynamic adjustment of the number of threads at runtime
2014-05-11 01:02:09 +08:00
!instead of using the max_threads set.
!CALL OMP_SET_DYNAMIC(.TRUE.)
DO threads = 1 , max_threads
nthreads = 0
< ompts : orphan >
!$omp parallel num_threads(threads) reduction(+:failed)
! print *, threads, omp_get_num_threads()
tmp = omp_get_num_threads ( )
IF ( threads . NE . tmp ) THEN
failed = failed + 1
WRITE ( 1 , * ) "Error: found " , tmp , " instead of " ,
& threads , " threads"
END IF
!$omp atomic
nthreads = nthreads + 1
!$omp end parallel
< / ompts : orphan >
! print *, threads, nthreads
< ompts : check > IF ( nthreads . NE . threads ) THEN < / ompts : check >
< ompts : crosscheck > IF ( nthreads . EQ . threads ) THEN < / ompts : cro sscheck>
failed = failed + 1
END IF
END DO
IF ( failed . NE . 0 ) THEN
< testfunctionname > < / testfunctionname > = 0
ELSE
< testfunctionname > < / testfunctionname > = 1
END IF
END FUNCTION
</omp t s : testcode >
</omp t s : test >