mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-07 23:22:11 +01:00
49 lines
1.2 KiB
Fortran
49 lines
1.2 KiB
Fortran
! @@name: metadirective.3f90
|
|
! @@type: F-free
|
|
! @@compilable: yes, omp_5.0
|
|
! @@linkable: yes
|
|
! @@expect: success
|
|
|
|
module params
|
|
integer, parameter :: N=1000
|
|
DOUBLE PRECISION, PARAMETER::M_PI=4.0d0*DATAN(1.0d0) !3.1415926535897932_8
|
|
end module
|
|
|
|
|
|
subroutine exp_pi_diff(d, my_pi)
|
|
use params
|
|
implicit none
|
|
integer :: i
|
|
double precision :: d(N), my_pi
|
|
!$omp declare target
|
|
|
|
!$omp metadirective &
|
|
!$omp& when( construct={target}: distribute parallel do ) &
|
|
!$omp& default( parallel do simd)
|
|
|
|
do i = 1,size(d)
|
|
d(i) = exp( (M_PI-my_pi)*i )
|
|
end do
|
|
|
|
end subroutine
|
|
|
|
program main
|
|
! Calculates sequence of exponentials: (M_PI-my_pi) * index
|
|
! M_PI is from usual way, and my_pi is user provided.
|
|
! Fortran Standard does not provide PI
|
|
|
|
use params
|
|
implicit none
|
|
double precision :: d(N)
|
|
double precision :: my_pi=3.14159265358979d0
|
|
|
|
!$omp target teams map(from: d)
|
|
call exp_pi_diff(d,my_pi)
|
|
! value should be near 1
|
|
print*, "d(N) = ",d(N) ! 1.00000000000311
|
|
|
|
call exp_pi_diff(d,my_pi) ! value should be near 1
|
|
print*, "d(N) = ",d(N) ! 1.00000000000311
|
|
|
|
end program
|