<?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 Re: Reduction clause in OpenMP with ifort in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757302#M12789</link>
    <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
When you store to different array elements in each thread, as you have written it, there is no race, and no reduction. Reduction is for combining results from multiple threads, where, as you say, if multiple threads tried to add directly to a single variable, without reduction or critical section, there would be a race.&lt;BR /&gt;You could do in effect a reduction from rank 3 to rank 2. I don't see why you would use an OpenMP reduction operation for that, as you would want each thread to have its own results, no race with the other threads.&lt;BR /&gt;It looks like you are saying that what you show here doesn't represent your actual problem, which may be one which isn't reliable to parallelize.&lt;BR /&gt;</description>
    <pubDate>Wed, 22 Jul 2009 23:02:59 GMT</pubDate>
    <dc:creator>TimP</dc:creator>
    <dc:date>2009-07-22T23:02:59Z</dc:date>
    <item>
      <title>Reduction clause in OpenMP with ifort</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757299#M12786</link>
      <description>Dear forum,&lt;BR /&gt;&lt;BR /&gt;I am trying to use the 'reduction' clause with ifort version 11.1.038, but get segmentation fault error. I have been trying with the version ifort 10.1 in the past, out of luck too. &lt;BR /&gt;&lt;BR /&gt;I am attaching the code at then end, the code was compiled with &lt;BR /&gt;ifort -warn all -check all -openmp -o reduction.x reduction.f90&lt;BR /&gt;&lt;BR /&gt;Any help is much appreciated. Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;file reduction.f90:&lt;BR /&gt;===============&lt;BR /&gt;program test_reduction&lt;BR /&gt;&lt;BR /&gt;integer, parameter :: n=100&lt;BR /&gt;real :: r = 0.45&lt;BR /&gt;real, dimension(n,n,n) :: a, summ&lt;BR /&gt;integer :: i,j,k&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;summ = 0.&lt;BR /&gt;&lt;BR /&gt;!$OMP PARALLEL DO &amp;amp;&lt;BR /&gt;!$OMP default(shared) &amp;amp;&lt;BR /&gt;!$OMP reduction(+: summ) &amp;amp;&lt;BR /&gt;!$OMP private(i,j,k)&lt;BR /&gt;do i = 1,n&lt;BR /&gt; do j = 1,n&lt;BR /&gt; do k = 1,n&lt;BR /&gt; a(i,j,k) = (i+j)/k&lt;BR /&gt; summ(i,j,k) = summ(i,j,k) + a(i,j,k)*r&lt;BR /&gt; enddo&lt;BR /&gt; enddo&lt;BR /&gt;enddo&lt;BR /&gt;!$OMP END PARALLEL DO&lt;BR /&gt;&lt;BR /&gt;write(*,*) summ&lt;BR /&gt;&lt;BR /&gt;end program&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Jul 2009 20:54:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757299#M12786</guid>
      <dc:creator>gottoomanyaccounts</dc:creator>
      <dc:date>2009-07-22T20:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reduction clause in OpenMP with ifort</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757300#M12787</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
Your reduction variable must be a scalar. Alternatively, you could remove the reduction clause, and your code would have a meaning, but not a reduction.&lt;BR /&gt;Without OpenMP, you might expect ifort to optimize the loop nesting, at least at -O3, but the OpenMP would probably prevent optimization.&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Jul 2009 21:48:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757300#M12787</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2009-07-22T21:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reduction clause in OpenMP with ifort</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757301#M12788</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/367365"&gt;tim18&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; Your reduction variable must be a scalar. Alternatively, you could remove the reduction clause, and your code would have a meaning, but not a reduction.&lt;BR /&gt;Without OpenMP, you might expect ifort to optimize the loop nesting, at least at -O3, but the OpenMP would probably prevent optimization.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Thanks for the answer. Is 'the reduction variable must be a scalar' the OpenMP standard? My impression is I have seen examples using reduction array.. &lt;BR /&gt;&lt;BR /&gt;The above code is what I used to test the reduction clause, in reality, the different private loops are likely to sum to the same array position; in this case, simply removing the reduction clause will result in race condition, right? What is the recommended solution in this situation? Thanks a lot.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Jul 2009 22:14:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757301#M12788</guid>
      <dc:creator>gottoomanyaccounts</dc:creator>
      <dc:date>2009-07-22T22:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reduction clause in OpenMP with ifort</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757302#M12789</link>
      <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
When you store to different array elements in each thread, as you have written it, there is no race, and no reduction. Reduction is for combining results from multiple threads, where, as you say, if multiple threads tried to add directly to a single variable, without reduction or critical section, there would be a race.&lt;BR /&gt;You could do in effect a reduction from rank 3 to rank 2. I don't see why you would use an OpenMP reduction operation for that, as you would want each thread to have its own results, no race with the other threads.&lt;BR /&gt;It looks like you are saying that what you show here doesn't represent your actual problem, which may be one which isn't reliable to parallelize.&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Jul 2009 23:02:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757302#M12789</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2009-07-22T23:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reduction clause in OpenMP with ifort</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757303#M12790</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/367365"&gt;tim18&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; It looks like you are saying that what you show here doesn't represent your actual problem, which may be one which isn't reliable to parallelize.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;That's correct. My actual code looks like something like this&lt;BR /&gt;do m = 1, N&lt;BR /&gt;i = f(m) ! i is a function of m&lt;BR /&gt;j = g(m) ! j is another function of m&lt;BR /&gt;s(i,j) = s(i,j) + a(i,j)&lt;BR /&gt;enddo&lt;BR /&gt;&lt;BR /&gt;Different m values may result in the same (i,j), so what should I do in this case?&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Jul 2009 23:46:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757303#M12790</guid>
      <dc:creator>gottoomanyaccounts</dc:creator>
      <dc:date>2009-07-22T23:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reduction clause in OpenMP with ifort</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757304#M12791</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/417175"&gt;gottoomanyaccounts&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;That's correct. My actual code looks like something like this&lt;BR /&gt;do m = 1, N&lt;BR /&gt;i = f(m) ! i is a function of m&lt;BR /&gt;j = g(m) ! j is another function of m&lt;BR /&gt;s(i,j) = s(i,j) + a(i,j)&lt;BR /&gt;enddo&lt;BR /&gt;&lt;BR /&gt;Different m values may result in the same (i,j), so what should I do in this case?&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;Do your own reduction of array&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;[cpp]s = 0.0
!$omp parallel private(i,j,m,sLocal)
sLocal = 0.0
!$omp do
do m = 1, N
i = f(m)  ! i is a function of m
j = g(m) ! j is another function of m
s(i,j) = s(i,j) + a(i,j)
enddo
!$omp end do
!$omp critical
s = s + sLocal
!$omp end critical
!$omp end parallel

[/cpp]&lt;/PRE&gt;
Jim Dempsey&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2009 12:35:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757304#M12791</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-07-23T12:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reduction clause in OpenMP with ifort</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757305#M12792</link>
      <description>&lt;DIV style="margin: 0px; height: auto;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;Note, if s is large, replace the critical section with nested loops containing a barrier. With each thread working on a different section of the array.&lt;BR /&gt;&lt;BR /&gt;me = omp_get_thread_num()&lt;BR /&gt;do j=1,jMax&lt;BR /&gt;mej = me+j&lt;BR /&gt;if(mej .gt. jMax) mej = mej - jMax&lt;BR /&gt;do i=1,iMax&lt;BR /&gt;s(i,mej) = s(i,mej) + sLocal(i,mej)&lt;BR /&gt;end do&lt;BR /&gt;!$omp barrier&lt;BR /&gt;end do&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Thu, 23 Jul 2009 12:49:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Reduction-clause-in-OpenMP-with-ifort/m-p/757305#M12792</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2009-07-23T12:49:10Z</dc:date>
    </item>
  </channel>
</rss>

