Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Fedele_S_
Beginner
47 Views

Problems with declare target on a fortran program

Can you help me to  correct this program?
Thank you , Fedele

Thank you,

Fedele

Program main
!=============================================
! Integration of a function using Simpson rule
!=============================================
implicit none
double precision f, a, b, integral
integer*8 n, i
double precision, parameter:: pi = 3.1415926
external f
!$omp declare target(f)
a = 0.0
b = pi

n = 2

do i=1,32
   call simpson(f,a,b,integral,n)
   write (*,101) n, integral
   n = n*2
end do

100   format('     nint   Simpson')
101   format(i9,1pe15.6)
print *, "fine calcolo"
end


  Function f(x)
!----------------------------------------
! Function for integration
!----------------------------------------
implicit none
double precision f, x
!$omp declare target
 f = sin(x)
! f = x*cos(10.0*x**2)/(x**2 + 1.0)
return
end

 Subroutine simpson(f,a,b,integral,n)
!==========================================================
! Integration of f(x) on [a,b]
! Method: Simpson rule for n intervals  
! written by: Alex Godunov (October 2009)
!----------------------------------------------------------
! IN:
! f   - Function to integrate (supplied by a user)
! a      - Lower limit of integration
! b      - Upper limit of integration
! n   - number of intervals
! OUT:
! integral - Result of integration
!==========================================================
implicit none
double precision f, a, b, integral,s
double precision h, x
integer*8 n, i

! if n is odd we add +1 to make it even

if((n/2)*2.ne.n) n=n+1

! loop over n (number of intervals)
s = 0.0
h = (b-a)/dfloat(n)
!$omp target
!$omp parallel do private(x), reduction(+:s)
do i=2, n-2, 2
   x   = a+dfloat(i)*h
   s = s + 2.0*f(x) + 4.0*f(x+h)
end do
!$omp end parallel do
!$omp end target
integral = (s + f(a) + f(b) + 4.0*f(a+h))*h/3.0
return
end subroutine simpson

0 Kudos
0 Replies
Reply