blob: 2e587cf52daf0aa776e3da77df377e0b27a1841e [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks the omp do private clause by counting up a variable in a parallelized loop. Each thread has a private variable (1) and an variable (2) declared by for private. First it stores the result of its last iteration in variable (2). Then this thread waits some time before it stores the value of the variable (2) in its private variable (1). At the beginning of the next iteration the value of (1) is assigned to (2). At the end all private variables (1) are added to a total sum in a critical section and compared with the correct result.</ompts:testdescription>
3<ompts:version>2.0</ompts:version>
4<ompts:directive>omp do private</ompts:directive>
5<ompts:dependences>omp parallel private, omp flush, omp critical</ompts:dependences>
6<ompts:testcode>
7 SUBROUTINE do_some_work()
8 IMPLICIT NONE
9 INTEGER i
10 INTRINSIC sqrt
11 DOUBLE PRECISION sum
12
13 INCLUDE "omp_testsuite.f"
14 sum=0.0
15 DO i=0, LOOPCOUNT-1
16 sum = sum + sqrt(REAL(i))
17 ENDDO
18
19 END
20
21 INTEGER FUNCTION <ompts:testcode:functionname>do_private</ompts:testcode:functionname>()
22 IMPLICIT NONE
23 INTEGER sum, known_sum
24<ompts:orphan:vars>
25 INTEGER sum0, sum1, i
26 COMMON /orphvars/ sum0, sum1, i
27</ompts:orphan:vars>
28
29 INCLUDE "omp_testsuite.f"
30
31 sum = 0
32 sum0 = 0
33 sum1 = 0
34
35!$omp parallel private(sum1)
36 sum0 = 0
37 sum1 = 0
38
39<ompts:orphan>
40!$omp do <ompts:check>private(sum0)</ompts:check> schedule(static,1)
41 DO i=1, LOOPCOUNT
42 sum0 = sum1
43!$omp flush
44 sum0 = sum0 + i
45 CALL do_some_work()
46!$omp flush
47! print *, sum0
48 sum1 = sum0
49 END DO
50!$omp end do
51</ompts:orphan>
52
53!$omp critical
54 sum = sum + sum1
55!$omp end critical
56!$omp end parallel
57
58 known_sum = (LOOPCOUNT*(LOOPCOUNT+1))/2
59! print *, "sum:", sum, "known_sum", known_sum
60 IF ( known_sum .EQ. sum) THEN
61 <testfunctionname></testfunctionname> = 1
62 ELSE
63 <testfunctionname></testfunctionname> = 0
64 END IF
65 END FUNCTION
66</ompts:testcode>
67</ompts:test>