OpenMP-Examples/sources/Example_reduction.6.f

27 lines
417 B
Fortran

! @@name: reduction.6f
! @@type: F-fixed
! @@compilable: yes
! @@linkable: yes
! @@expect: rt-error
INTEGER A, I
!$OMP PARALLEL SHARED(A) PRIVATE(I)
!$OMP MASTER
A = 0
!$OMP END MASTER
! To avoid race conditions, add a barrier here.
!$OMP DO REDUCTION(+:A)
DO I= 0, 9
A = A + I
END DO
!$OMP SINGLE
PRINT *, "Sum is ", A
!$OMP END SINGLE
!$OMP END PARALLEL
END