blob: 0792361be380878c5baa6d62b05fd3a7cdbdea9f [file] [log] [blame]
Jim Cownie18d84732014-05-10 17:02:09 +00001<ompts:test>
2<ompts:testdescription>Test which checks the omp do firstprivate clause by counting up a variable in a parallelized loop. Each thread has a firstprivate variable (1) and an variable (2) declared by do firstprivate. First it stores the result of its last iteration in variable (2). Then it stores the value of the variable (2) in its firstprivate variable (1). At the end all firstprivate 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 firstprivate</ompts:directive>
5<ompts:dependences>omp parallel private, omp critical</ompts:dependences>
6<ompts:testcode>
7 INTEGER FUNCTION <ompts:testcode:functionname>do_firstprivate</ompts:testcode:functionname>()
8 IMPLICIT NONE
9 INTEGER sum, known_sum
10 INTEGER numthreads
11 INTEGER omp_get_num_threads
12<ompts:orphan:vars>
13 INTEGER sum0, sum1, i
14 COMMON /orphvars/ sum0, sum1, i
15</ompts:orphan:vars>
16
17 INCLUDE "omp_testsuite.f"
18
19 sum = 0
20 sum0 = 12345
21 sum1 = 0
22
23
24!$omp parallel firstprivate(sum1)
25!$omp single
26 numthreads = omp_get_num_threads()
27!$omp end single
28
29
30<ompts:orphan>
31!$omp do <ompts:check>firstprivate(sum0)</ompts:check><ompts:crosscheck>private (sum0)</ompts:crosscheck>
32 DO i=1,LOOPCOUNT
33 sum0 = sum0 + i
34 sum1 = sum0
35 END DO
36!$omp end do
37</ompts:orphan>
38
39
40!$omp critical
41 WRITE (1,*) sum0
42 sum = sum + sum1
43!$omp end critical
44!$omp end parallel
45
46
47 known_sum=12345*numthreads+ (LOOPCOUNT*(LOOPCOUNT+1))/2
48 IF ( known_sum .EQ. sum ) THEN
49 <testfunctionname></testfunctionname> = 1
50 ELSE
51 WRITE (1,*) "Found sum was", sum, "instead of", known_sum
52 <testfunctionname></testfunctionname> = 0
53 END IF
54 END FUNCTION
55</ompts:testcode>
56</ompts:test>