blob: 2e587cf52daf0aa776e3da77df377e0b27a1841e [file] [log] [blame]
 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. 2.0 omp do private omp parallel private, omp flush, omp critical SUBROUTINE do_some_work() IMPLICIT NONE INTEGER i INTRINSIC sqrt DOUBLE PRECISION sum INCLUDE "omp_testsuite.f" sum=0.0 DO i=0, LOOPCOUNT-1 sum = sum + sqrt(REAL(i)) ENDDO END INTEGER FUNCTION do_private() IMPLICIT NONE INTEGER sum, known_sum INTEGER sum0, sum1, i COMMON /orphvars/ sum0, sum1, i INCLUDE "omp_testsuite.f" sum = 0 sum0 = 0 sum1 = 0 !\$omp parallel private(sum1) sum0 = 0 sum1 = 0 !\$omp do private(sum0) schedule(static,1) DO i=1, LOOPCOUNT sum0 = sum1 !\$omp flush sum0 = sum0 + i CALL do_some_work() !\$omp flush ! print *, sum0 sum1 = sum0 END DO !\$omp end do !\$omp critical sum = sum + sum1 !\$omp end critical !\$omp end parallel known_sum = (LOOPCOUNT*(LOOPCOUNT+1))/2 ! print *, "sum:", sum, "known_sum", known_sum IF ( known_sum .EQ. sum) THEN = 1 ELSE = 0 END IF END FUNCTION