blob: a8faa27f85531556504dc1721e44e959f5382770 [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks if WORKSHARE is present.</ompts:testdescription>
3<ompts:ompversion>2.0</ompts:ompversion>
4<ompts:directive>omp workshare</ompts:directive>
5<ompts:dependences>omp critical</ompts:dependences>
6<ompts:testcode>
7!********************************************************************
8! Function: omp_workshare
9!
10! by Chunhua Liao, University of Houston
11! Oct. 2005 - First version
12!
13! The idea for the test is that if WORKSHARE is not present,
14! the array assignment in PARALLEL region will be executed by each
15! thread and then wrongfully repeated several times.
16!
17! TODO:Do we need test for WHERE and FORALL?
18! A simple test for WHERE and FORALL is added by Zhenying Liu
19!********************************************************************
20 INTEGER FUNCTION <ompts:testcode:functionname>omp_workshare</ompts:testcode:functionname>()
21 IMPLICIT NONE
22 INTEGER result,i
23 INTEGER scalar02,scalar12,scalar22,scalar32,count
24 REAL, DIMENSION(1000)::FF
25<ompts:orphan:vars>
26 INTEGER scalar0,scalar1,scalar2,scalar3
27 INTEGER, DIMENSION(1000)::AA,BB,CC
28 REAL, DIMENSION(1000)::DD
29 COMMON /orphvars/ scalar0,scalar1,scalar2,scalar3,
30 & AA,BB,CC,DD
31</ompts:orphan:vars>
32
33 result=0
34 scalar0=0
35 scalar02=0
36 scalar1=0
37 scalar12=0
38 scalar2=0
39 scalar22=0
40 scalar3=0
41 scalar32=0
42
43 count = 0
44
45 AA=0
46 BB=0
47
48 do i=1,1000
49 CC(i) = i
50 FF(i) = 1.0/i
51 end do
52
53!$OMP PARALLEL
54<ompts:orphan>
55<ompts:check>!$OMP WORKSHARE</ompts:check>
56
57! test if work is divided or not for array assignment
58 AA=AA+1
59
60! test if scalar assignment is treated as a single unit of work
61 scalar0=scalar0+1
62
63! test if atomic is treated as a single unit of work
64!$OMP ATOMIC
65 scalar1=scalar1+1
66! test if critical is treated as a single unit of work
67!$OMP CRITICAL
68 scalar2=scalar2+1
69!$OMP END CRITICAL
70
71! test if PARALLEL is treated as a single unit of work
72!$OMP PARALLEL
73 scalar3=scalar3+1
74!$OMP END PARALLEL
75
76 WHERE ( CC .ne. 0 ) DD = 1.0/CC
77
78 FORALL (I=1:1000) CC(i) = -i
79
80<ompts:check>!$OMP END WORKSHARE</ompts:check>
81</ompts:orphan>
82!$OMP END PARALLEL
83
84!sequential equivalent statements for comparison
85 BB=BB+1
86 scalar02=scalar02+1
87 scalar12=scalar12+1
88 scalar22=scalar22+1
89 scalar32=scalar32+1
90
91! write (1,*) "ck:sum of AA is",SUM(AA)," sum of BB is ",sum(BB)
92 if (SUM(AA)/=SUM(BB)) then
93 write(1,*) "Array assignment has some problem"
94 result=result +1
95 endif
96 if (scalar0/=scalar02) then
97 write(1,*) "Scalar assignment has some problem"
98 result = result +1
99 endif
100 if (scalar1/=scalar12) then
101 write(1,*) "Atomic inside WORKSHARE has some problem"
102 result = result +1
103 endif
104 if (scalar2/=scalar22) then
105 write(1,*) "CRITICAL inside WORKSHARE has some problem"
106 result = result +1
107 endif
108 if (scalar3/=scalar32) then
109 write(1,*) "PARALLEL inside WORKSHARE has some problem"
110 result = result +1
111 endif
112 do i=1,1000
113 if ( abs( DD(i)- FF(i)) .gt. 1.0E-4 ) then
114 count = count + 1
115 end if
116 end do
117 if ( count .ne. 0 ) then
118 result = result + 1
119 write(1,*) "WHERE has some problem"
120 end if
121
122 count = 0
123 do i=1,1000
124 if ( CC(i) .ne. -i ) then
125 count = count + 1
126 end if
127 end do
128 if ( count .ne. 0 ) then
129 result = result + 1
130 write(1,*) "FORALL has some problem"
131 end if
132
133
134!if anything is wrong, set return value to 0
135 if (result==0) then
136 <testfunctionname></testfunctionname> = 1
137 else
138 <testfunctionname></testfunctionname> = 0
139 end if
140 end
141</ompts:testcode>
142</ompts:test>