blob: c920498fa475a9147aba49626ccdd2d55a0f96f3 [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks the omp threadprivate directive by filling an array with random numbers in an parallelised region. Each thread generates one number of the array and saves this in a temporary threadprivate variable. In a second parallelised region the test controls, that the temporary variable contains still the former value by comparing it with the one in the array.</ompts:testdescription>
3<ompts:ompversion>2.0</ompts:ompversion>
4<ompts:directive>omp threadprivate</ompts:directive>
5<ompts:dependences>omp critical,omp_set_dynamic,omp_get_num_threads,omp master</ompts:dependences>
6<ompts:testcode>
7!Yi Wen modified this function from his own understanding of the semantics
8!of C version at 05042004
9!The undeestanding is that sum0 and myvalue can be local static variables
10!of the chk_omp_threadprivate function. There is no need to use common
11!block
12 INTEGER FUNCTION <ompts:testcode:functionname>omp_threadprivate</ompts:testcode:functionname>()
13 IMPLICIT NONE
14 INTEGER sum, known_sum, i , iter, rank,size, failed
15 INTEGER omp_get_num_threads, omp_get_thread_num
16 REAL my_random
17 REAL, ALLOCATABLE:: data(:)
18 INTEGER random_size
19 INTRINSIC random_number
20 INTRINSIC random_seed
21 EXTERNAL omp_set_dynamic
22
23!Yi Wen modified at 05042004 : add "save"
24 INTEGER, SAVE:: sum0
25 REAL, SAVE::myvalue
26!Yi Wen commented two common blocks
27! common/csum0/ sum0
28! common/cmyvalue/ myvalue
29!!!!!!!!!!$omp threadprivate(/csum0/,/cmyvalue/)
30 <ompts:check>
31!$omp threadprivate(sum0,myvalue)
32 </ompts:check>
33 INCLUDE "omp_testsuite.f"
34
35 sum = 0
36 failed = 0
37 sum0=0
38 myvalue=0
39 random_size=45
40 CALL omp_set_dynamic(.FALSE.)
41!$omp parallel
42 sum0 = 0
43!$omp do
44 DO i=1, LOOPCOUNT
45 sum0 = sum0 + i
46 END DO
47!$omp end do
48!$omp critical
49 sum = sum + sum0
50!$omp end critical
51!$omp end parallel
52 known_sum = (LOOPCOUNT*(LOOPCOUNT+1))/2
53 IF ( known_sum .NE. sum ) THEN
54 PRINT *, ' known_sum =', known_sum, ', sum =',sum
55 END IF
56
57 CALL omp_set_dynamic(.FALSE.)
58
59!$omp parallel
60!$omp master
61 size = omp_get_num_threads()
62 ALLOCATE ( data(size) )
63!$omp end master
64!$omp end parallel
65 CALL RANDOM_SEED(SIZE=random_size)
66 DO iter = 0, 99
67 CALL RANDOM_NUMBER(HARVEST=my_random)
68!$omp parallel private(rank)
69 rank = omp_get_thread_num()+1
70 myvalue = my_random + rank
71 data(rank) = myvalue
72!$omp end parallel
73!$omp parallel private(rank)
74 rank = omp_get_thread_num()+1
75 IF ( myvalue .NE. data(rank) ) THEN
76 failed = failed + 1
77 PRINT *, ' myvalue =',myvalue,' data(rank)=', data(rank)
78 END IF
79!$omp end parallel
80 END DO
81 DEALLOCATE( data)
82 IF ( (known_sum .EQ. sum) .AND. (failed .NE. 1) ) THEN
83 <testfunctionname></testfunctionname> = 1
84 else
85 <testfunctionname></testfunctionname> = 0
86 end if
87 END
88</ompts:testcode>
89</ompts:test>