1
0
mirror of https://github.com/OpenMP/Examples.git synced 2025-04-11 00:42:12 +01:00
OpenMP-Examples/sources/Example_taskloop_reduction.1.f90

39 lines
691 B
Fortran

! @@name: taskloop_reduction.1.f90
! @@type: F-free
! @@compilable: yes, omp_5.0
! @@linkable: yes
! @@expect: success
function array_sum(n, v) result(res)
implicit none
integer :: n, v(n), res
integer :: i
res = 0
!$omp taskloop reduction(+: res)
do i=1, n
res = res + v(i)
end do
!$omp end taskoop
end function array_sum
program main
implicit none
integer :: n, v(10), res
integer :: i
integer, external :: array_sum
n = 10
do i=1, n
v(i) = i
end do
!$omp parallel
!$omp single
res = array_sum(n, v)
print *, "The result is", res
!$omp end single
!$omp end parallel
end program main