blob: a1ede73a6f36a2718071e1010d7f4be0d2999644 [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks that the omp_get_num_threads returns 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>
3<ompts:ompversion>2.0</ompts:ompversion>
4<ompts:directive>omp_get_num_threads</ompts:directive>
5<ompts:testcode>
6 INTEGER FUNCTION <ompts:testcode:functionname>omp_num_threads</ompts:testcode:functionname>()
7 IMPLICIT NONE
8 INTEGER i, max_threads
9 INTEGER omp_get_num_threads
10<ompts:orphan:vars>
11 INTEGER failed,threads,nthreads,tmp
12 COMMON /orphvars/ failed,threads,nthreads
13</ompts:orphan:vars>
14
15 failed = 0
16 max_threads = 0
17
18!$omp parallel
19!$omp master
20 max_threads = OMP_GET_NUM_THREADS()
21!$omp end master
22!$omp end parallel
23! print *, "max threads:",max_threads
24
25!Yi Wen added omp_Set_dynamics here to make sure num_threads clause work
26!Thanks to Dr. Yin Ma in Absoft. should be not be called before the test loop
Alp Tokerc2d5e612014-06-01 18:28:36 +000027!because it allows the dynamic adjustment of the number of threads at runtime
Jim Cownie18d84732014-05-10 17:02:09 +000028!instead of using the max_threads set.
29
30 !CALL OMP_SET_DYNAMIC(.TRUE.)
31 DO threads = 1, max_threads
32 nthreads = 0
33 <ompts:orphan>
34!$omp parallel num_threads(threads) reduction(+:failed)
35! print *, threads, omp_get_num_threads()
36 tmp = omp_get_num_threads()
37 IF ( threads .NE. tmp ) THEN
38 failed = failed + 1
39 WRITE (1,*) "Error: found ", tmp, " instead of ",
40 & threads, " threads"
41 END IF
42!$omp atomic
43 nthreads = nthreads + 1
44!$omp end parallel
45 </ompts:orphan>
46! print *, threads, nthreads
47 <ompts:check>IF ( nthreads .NE. threads ) THEN</ompts:check>
48 <ompts:crosscheck>IF ( nthreads .EQ. threads ) THEN</ompts:crosscheck>
49 failed = failed + 1
50 END IF
51 END DO
52
53 IF(failed .NE. 0) THEN
54 <testfunctionname></testfunctionname> = 0
55 ELSE
56 <testfunctionname></testfunctionname> = 1
57 END IF
58 END FUNCTION
59</ompts:testcode>
60</ompts:test>