<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problems with declare target on a fortran program in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Problems-with-declare-target-on-a-fortran-program/m-p/1176950#M79529</link>
    <description>&lt;P&gt;Can you help me to&amp;nbsp; correct this program?&lt;BR /&gt;
	Thank you , Fedele&lt;/P&gt;

&lt;P&gt;Thank you,&lt;/P&gt;

&lt;P&gt;Fedele&lt;/P&gt;

&lt;P&gt;Program main&lt;BR /&gt;
	!=============================================&lt;BR /&gt;
	! Integration of a function using Simpson rule&lt;BR /&gt;
	!=============================================&lt;BR /&gt;
	implicit none&lt;BR /&gt;
	double precision f, a, b, integral&lt;BR /&gt;
	integer*8 n, i&lt;BR /&gt;
	double precision, parameter:: pi = 3.1415926&lt;BR /&gt;
	external f&lt;BR /&gt;
	!$omp declare target(f)&lt;BR /&gt;
	a = 0.0&lt;BR /&gt;
	b = pi&lt;/P&gt;

&lt;P&gt;n = 2&lt;/P&gt;

&lt;P&gt;do i=1,32&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; call simpson(f,a,b,integral,n)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; write (*,101) n, integral&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; n = n*2&lt;BR /&gt;
	end do&lt;/P&gt;

&lt;P&gt;100&amp;nbsp;&amp;nbsp; format('&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nint&amp;nbsp;&amp;nbsp; Simpson')&lt;BR /&gt;
	101&amp;nbsp;&amp;nbsp; format(i9,1pe15.6)&lt;BR /&gt;
	print *, "fine calcolo"&lt;BR /&gt;
	end&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp; Function f(x)&lt;BR /&gt;
	!----------------------------------------&lt;BR /&gt;
	! Function for integration&lt;BR /&gt;
	!----------------------------------------&lt;BR /&gt;
	implicit none&lt;BR /&gt;
	double precision f, x&lt;BR /&gt;
	!$omp declare target&lt;BR /&gt;
	&amp;nbsp;f = sin(x)&lt;BR /&gt;
	! f = x*cos(10.0*x**2)/(x**2 + 1.0)&lt;BR /&gt;
	return&lt;BR /&gt;
	end&lt;/P&gt;

&lt;P&gt;&amp;nbsp;Subroutine simpson(f,a,b,integral,n)&lt;BR /&gt;
	!==========================================================&lt;BR /&gt;
	! Integration of f(x) on [a,b]&lt;BR /&gt;
	! Method: Simpson rule for n intervals &amp;nbsp;&lt;BR /&gt;
	! written by: Alex Godunov (October 2009)&lt;BR /&gt;
	!----------------------------------------------------------&lt;BR /&gt;
	! IN:&lt;BR /&gt;
	! f&amp;nbsp;&amp;nbsp; - Function to integrate (supplied by a user)&lt;BR /&gt;
	! a&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; - Lower limit of integration&lt;BR /&gt;
	! b&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; - Upper limit of integration&lt;BR /&gt;
	! n&amp;nbsp;&amp;nbsp; - number of intervals&lt;BR /&gt;
	! OUT:&lt;BR /&gt;
	! integral - Result of integration&lt;BR /&gt;
	!==========================================================&lt;BR /&gt;
	implicit none&lt;BR /&gt;
	double precision f, a, b, integral,s&lt;BR /&gt;
	double precision h, x&lt;BR /&gt;
	integer*8 n, i&lt;/P&gt;

&lt;P&gt;! if n is odd we add +1 to make it even&lt;/P&gt;

&lt;P&gt;if((n/2)*2.ne.n) n=n+1&lt;/P&gt;

&lt;P&gt;! loop over n (number of intervals)&lt;BR /&gt;
	s = 0.0&lt;BR /&gt;
	h = (b-a)/dfloat(n)&lt;BR /&gt;
	!$omp target&lt;BR /&gt;
	!$omp parallel do private(x), reduction(+:s)&lt;BR /&gt;
	do i=2, n-2, 2&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; x&amp;nbsp;&amp;nbsp; = a+dfloat(i)*h&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; s = s + 2.0*f(x) + 4.0*f(x+h)&lt;BR /&gt;
	end do&lt;BR /&gt;
	!$omp end parallel do&lt;BR /&gt;
	!$omp end target&lt;BR /&gt;
	integral = (s + f(a) + f(b) + 4.0*f(a+h))*h/3.0&lt;BR /&gt;
	return&lt;BR /&gt;
	end subroutine simpson&lt;/P&gt;</description>
    <pubDate>Mon, 04 Sep 2017 11:42:48 GMT</pubDate>
    <dc:creator>Fedele_S_</dc:creator>
    <dc:date>2017-09-04T11:42:48Z</dc:date>
    <item>
      <title>Problems with declare target on a fortran program</title>
      <link>https://community.intel.com/t5/Software-Archive/Problems-with-declare-target-on-a-fortran-program/m-p/1176950#M79529</link>
      <description>&lt;P&gt;Can you help me to&amp;nbsp; correct this program?&lt;BR /&gt;
	Thank you , Fedele&lt;/P&gt;

&lt;P&gt;Thank you,&lt;/P&gt;

&lt;P&gt;Fedele&lt;/P&gt;

&lt;P&gt;Program main&lt;BR /&gt;
	!=============================================&lt;BR /&gt;
	! Integration of a function using Simpson rule&lt;BR /&gt;
	!=============================================&lt;BR /&gt;
	implicit none&lt;BR /&gt;
	double precision f, a, b, integral&lt;BR /&gt;
	integer*8 n, i&lt;BR /&gt;
	double precision, parameter:: pi = 3.1415926&lt;BR /&gt;
	external f&lt;BR /&gt;
	!$omp declare target(f)&lt;BR /&gt;
	a = 0.0&lt;BR /&gt;
	b = pi&lt;/P&gt;

&lt;P&gt;n = 2&lt;/P&gt;

&lt;P&gt;do i=1,32&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; call simpson(f,a,b,integral,n)&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; write (*,101) n, integral&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; n = n*2&lt;BR /&gt;
	end do&lt;/P&gt;

&lt;P&gt;100&amp;nbsp;&amp;nbsp; format('&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nint&amp;nbsp;&amp;nbsp; Simpson')&lt;BR /&gt;
	101&amp;nbsp;&amp;nbsp; format(i9,1pe15.6)&lt;BR /&gt;
	print *, "fine calcolo"&lt;BR /&gt;
	end&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp; Function f(x)&lt;BR /&gt;
	!----------------------------------------&lt;BR /&gt;
	! Function for integration&lt;BR /&gt;
	!----------------------------------------&lt;BR /&gt;
	implicit none&lt;BR /&gt;
	double precision f, x&lt;BR /&gt;
	!$omp declare target&lt;BR /&gt;
	&amp;nbsp;f = sin(x)&lt;BR /&gt;
	! f = x*cos(10.0*x**2)/(x**2 + 1.0)&lt;BR /&gt;
	return&lt;BR /&gt;
	end&lt;/P&gt;

&lt;P&gt;&amp;nbsp;Subroutine simpson(f,a,b,integral,n)&lt;BR /&gt;
	!==========================================================&lt;BR /&gt;
	! Integration of f(x) on [a,b]&lt;BR /&gt;
	! Method: Simpson rule for n intervals &amp;nbsp;&lt;BR /&gt;
	! written by: Alex Godunov (October 2009)&lt;BR /&gt;
	!----------------------------------------------------------&lt;BR /&gt;
	! IN:&lt;BR /&gt;
	! f&amp;nbsp;&amp;nbsp; - Function to integrate (supplied by a user)&lt;BR /&gt;
	! a&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; - Lower limit of integration&lt;BR /&gt;
	! b&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; - Upper limit of integration&lt;BR /&gt;
	! n&amp;nbsp;&amp;nbsp; - number of intervals&lt;BR /&gt;
	! OUT:&lt;BR /&gt;
	! integral - Result of integration&lt;BR /&gt;
	!==========================================================&lt;BR /&gt;
	implicit none&lt;BR /&gt;
	double precision f, a, b, integral,s&lt;BR /&gt;
	double precision h, x&lt;BR /&gt;
	integer*8 n, i&lt;/P&gt;

&lt;P&gt;! if n is odd we add +1 to make it even&lt;/P&gt;

&lt;P&gt;if((n/2)*2.ne.n) n=n+1&lt;/P&gt;

&lt;P&gt;! loop over n (number of intervals)&lt;BR /&gt;
	s = 0.0&lt;BR /&gt;
	h = (b-a)/dfloat(n)&lt;BR /&gt;
	!$omp target&lt;BR /&gt;
	!$omp parallel do private(x), reduction(+:s)&lt;BR /&gt;
	do i=2, n-2, 2&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; x&amp;nbsp;&amp;nbsp; = a+dfloat(i)*h&lt;BR /&gt;
	&amp;nbsp;&amp;nbsp; s = s + 2.0*f(x) + 4.0*f(x+h)&lt;BR /&gt;
	end do&lt;BR /&gt;
	!$omp end parallel do&lt;BR /&gt;
	!$omp end target&lt;BR /&gt;
	integral = (s + f(a) + f(b) + 4.0*f(a+h))*h/3.0&lt;BR /&gt;
	return&lt;BR /&gt;
	end subroutine simpson&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2017 11:42:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Problems-with-declare-target-on-a-fortran-program/m-p/1176950#M79529</guid>
      <dc:creator>Fedele_S_</dc:creator>
      <dc:date>2017-09-04T11:42:48Z</dc:date>
    </item>
  </channel>
</rss>

