<?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 Hello, in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933788#M88420</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Yes, Nbond is defined in my system.inc file. &amp;nbsp;I tired moving the REDUCTION(+:Nbond) into the !$OMP PARALLEL section, but it still produced the same results. &amp;nbsp;Here is a sample output of my program showing the difference.&lt;/P&gt;
&lt;P&gt;Run in serial with -O3:&lt;/P&gt;
&lt;P&gt;Time (us) &amp;nbsp;Nbonds &amp;nbsp; &amp;nbsp; N&lt;/P&gt;
&lt;P&gt;100.0000 &amp;nbsp;13328 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 200.0000 &amp;nbsp;13474 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 300.0000 &amp;nbsp;13568 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 400.0000 &amp;nbsp;13667 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 500.0000 &amp;nbsp;13707 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 600.0000 &amp;nbsp;13751 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 700.0000 &amp;nbsp;13800 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 800.0000 &amp;nbsp;13844 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 900.0000 &amp;nbsp;13852 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 1000.0000 13878 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;/P&gt;
&lt;P&gt;Run using 8 threads and -O1 -openmp&lt;/P&gt;
&lt;P&gt;Time (us) &amp;nbsp;Nbonds &amp;nbsp; &amp;nbsp;N&lt;/P&gt;
&lt;P&gt;100.0000 &amp;nbsp;13348 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 200.0000 &amp;nbsp;13532 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 300.0000 &amp;nbsp;13589 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 400.0000 &amp;nbsp;13701 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 500.0000 &amp;nbsp;13775 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 600.0000 &amp;nbsp;13784 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 700.0000 &amp;nbsp;13814 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 800.0000 &amp;nbsp;13883 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 900.0000 &amp;nbsp;13869 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 1000.0000 13906 &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;/P&gt;
&lt;P&gt;Run with 8 Threads and -O3 -openmp&lt;/P&gt;
&lt;P&gt;Time (us) &amp;nbsp;Nbonds &amp;nbsp; &amp;nbsp; N&lt;/P&gt;
&lt;P&gt;100.0000 &amp;nbsp;7499843 &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 200.0000 &amp;nbsp;9781784 &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 300.0000 &amp;nbsp;10867080 &amp;nbsp; 5041&lt;BR /&gt; 400.0000 &amp;nbsp;11468020 &amp;nbsp; 5041&lt;BR /&gt; 500.0000 &amp;nbsp;11824365 &amp;nbsp; 5041&lt;BR /&gt; 600.0000 &amp;nbsp;12042995 &amp;nbsp; 5041&lt;BR /&gt; 700.0000 &amp;nbsp;12178306 &amp;nbsp; 5041&lt;BR /&gt; 800.0000 &amp;nbsp;12265422 &amp;nbsp; 5041&lt;BR /&gt; 900.0000 &amp;nbsp;12319681 &amp;nbsp; 5041&lt;BR /&gt; 1000.0000 12354566 &amp;nbsp;5041&lt;/P&gt;
&lt;P&gt;The middle number of the output corresponds to the Nbond variable that I use in the reduction clause. &amp;nbsp;It is a stochastic variable, so the numbers between the runs should not be the exact same, but they should be close. &amp;nbsp;When I use the -O3 compiler flag, the output Nbond variable icreases by about 1000?&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jun 2013 00:05:12 GMT</pubDate>
    <dc:creator>Mike3</dc:creator>
    <dc:date>2013-06-27T00:05:12Z</dc:date>
    <item>
      <title>openmp Reduction differences with reduction flag</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933783#M88415</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I have a code where I have parallelized one of the intensive subroutines using openmp. &amp;nbsp;I have a reduction variable which, which I I use the optimization flags -O2 or -O3 (but now -O1), the value of the reduction variable that I am outputing is about 1000x to large. &amp;nbsp;This does not happen when I run the code in serial with or without the -O3 flag, nor does it happen when I compile the code using gfortran and the -O3 flag. &amp;nbsp;Is there something about the optimization flags that are incompatbile with OMP REDUCTION?&lt;/P&gt;
&lt;P&gt;Here is the portion of the code related to the reduction variable:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;!$OMP PARALLEL DEFAULT(Shared) PRIVATE(Num,ID,jsr,Thread,CX,CY,CZ,i,j,k,&lt;BR /&gt;!$OMP&amp;amp; II,JJ,KK,XX,YY,ZZ,RSQ,Btest,BX,BY,BZ,RR,BondR,FFx,FFy,FFz,TH)&lt;/P&gt;
&lt;P&gt;Thread = OMP_GET_THREAD_NUM()&lt;BR /&gt; TH = Thread + 1&lt;/P&gt;
&lt;P&gt;!$OMP Do SCHEDULE(Static) REDUCTION( + : Nbond)&lt;BR /&gt; Do Num = 1,N&lt;BR /&gt; jsr = seed(Thread)&lt;/P&gt;
&lt;P&gt;XX = DABS(RX(Num) - RX(ID))&lt;BR /&gt; YY = DABS(RY(Num) - RY(ID))&lt;BR /&gt; ZZ = DABS(RZ(Num) - RZ(ID))&lt;BR /&gt; RSQ = XX * XX + YY * YY + ZZ * ZZ&lt;/P&gt;
&lt;P&gt;IF (RSQ &amp;lt; RcutB2 .AND. BindOn)&amp;nbsp;&lt;BR /&gt; if (Bond(Num,ID) == 0) Then&lt;BR /&gt; Btest = UNIF(jsr)&lt;BR /&gt; if (Btest &amp;lt; Bon) Then&lt;BR /&gt; Bond(Num,ID) = 1&lt;BR /&gt; Nbond = Nbond + 1&lt;BR /&gt; End if&lt;BR /&gt; End if&lt;BR /&gt; End if&lt;/P&gt;
&lt;P&gt;If (Bond(Num,ID) == 1) Then&lt;BR /&gt; Btest = UNIF(jsr)&lt;BR /&gt; if (Btest &amp;lt; Boff) Then&lt;BR /&gt; Bond(Num,ID) = 0&lt;BR /&gt; Nbond = Nbond - 1&lt;/P&gt;
&lt;P&gt;End Do&lt;BR /&gt;!$OMP END Do&lt;/P&gt;
&lt;P&gt;!$OMP END PARALLEL&lt;/P&gt;
&lt;P&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This is a code snippet with some of the other computations taken out. &amp;nbsp;All the variables and whatnot are defines properly, as the code runs fine in serial and in parallel without O2 and O3 optimizations.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2013 23:03:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933783#M88415</guid>
      <dc:creator>Mike3</dc:creator>
      <dc:date>2013-06-25T23:03:59Z</dc:date>
    </item>
    <item>
      <title>ID is declared as private,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933784#M88416</link>
      <description>&lt;P&gt;ID is declared as private, but is not initilaized before used (defined).&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2013 00:16:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933784#M88416</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-06-26T00:16:59Z</dc:date>
    </item>
    <item>
      <title>All the variables have been</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933785#M88417</link>
      <description>&lt;P&gt;All the variables have been defined as evidenced by the program working with the -openmp and -O1 flags but now with the -openmp -O2 or -openmp -O3. &amp;nbsp;I think that's my part for only posting what I considered the relavent parts of the subroutine. &amp;nbsp;Here is the complete subroutine in which ID is defined.&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;SUBROUTINE FORCE (N, Gridon, Cell, seed, jsr, kn, fn, wn,&lt;BR /&gt; &amp;amp; Thread_Num)&lt;BR /&gt; Implicit None&lt;/P&gt;
&lt;P&gt;Include 'omp_lib.h'&lt;BR /&gt; Include 'maxarray.inc'&lt;BR /&gt; Include 'system.inc'&lt;/P&gt;
&lt;P&gt;C *******************************************************************&lt;/P&gt;
&lt;P&gt;INTEGER I, J, K, NUM, II, JJ, KK&lt;BR /&gt; INTEGER ID, CX,CY,CZ, jsr, Thread, Thread_Num, TH&lt;BR /&gt; INTEGER kn(128)&lt;BR /&gt; INTEGER seed(0:Thread_Max-1)&lt;BR /&gt; LOGICAL Gridon, Can_Bind&lt;BR /&gt; REAL*8 RXI, RYI, RZI, FXIJ, FYIJ, FZIJ, FIJ&lt;BR /&gt; REAL*8 FXI, FYI, FZI, RIJ, FFx, FFy, FFz&lt;BR /&gt; REAL*8 XX, YY, ZZ, BX, BY, BZ&lt;BR /&gt; REAL*8 RSQ, RR, BondR, Btest&lt;BR /&gt; REAL*8 FX_Priv(N,Thread_Num)&lt;BR /&gt; REAL*8 FY_Priv(N,Thread_Num)&lt;BR /&gt; REAL*8 FZ_Priv(N,Thread_Num)&lt;BR /&gt; REAL fn(128), wn(128)&lt;BR /&gt; REAL*8 Attract, A, B, C, wtime&lt;/P&gt;
&lt;P&gt;C *******************************************************************&lt;/P&gt;
&lt;P&gt;If (Gridon) Then&lt;/P&gt;
&lt;P&gt;FX(1:N) = 0.0&lt;BR /&gt; FY(1:N) = 0.0&lt;BR /&gt; FZ(1:N) = 0.0&lt;BR /&gt; FX_Priv(1:N,1:Thread_Num) = 0.0&lt;BR /&gt; FY_Priv(1:N,1:Thread_Num) = 0.0&lt;BR /&gt; FZ_Priv(1:N,1:Thread_Num) = 0.0&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;!$OMP PARALLEL DEFAULT(Shared) PRIVATE(Num,ID,jsr,Thread,CX,CY,CZ,i,j,k,&lt;BR /&gt;!$OMP&amp;amp; II,JJ,KK,XX,YY,ZZ,RSQ,Btest,BX,BY,BZ,RR,BondR,FFx,FFy,FFz,TH)&lt;/P&gt;
&lt;P&gt;Thread = OMP_GET_THREAD_NUM()&lt;BR /&gt;! Thread = 0&lt;BR /&gt; TH = Thread + 1&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;!$OMP Do SCHEDULE(Static) REDUCTION( + : Nbond)&lt;BR /&gt; Do Num = 1,N&lt;BR /&gt; jsr = seed(Thread)&lt;BR /&gt; CX = INT(RX(Num)/RXcut)+1&lt;BR /&gt; CY = INT(RY(Num)/RYcut)+1&lt;BR /&gt; CZ = INT(RZ(Num)/RZcut)+1&lt;BR /&gt; Do I=CX-1,CX+1&lt;BR /&gt; Do J=CY-1,CY+1&lt;BR /&gt; Do K=CZ-1,CZ+1&lt;BR /&gt; II = i&lt;BR /&gt; JJ = j&lt;BR /&gt; KK = k&lt;BR /&gt;C FOR X &lt;BR /&gt; If (II.LT.1) II=II+NCellx&lt;BR /&gt; If (II.GT.NCellx) II=II-NCellx&lt;BR /&gt;C FOR Y&lt;BR /&gt; If (JJ.LT.1) JJ=JJ+NCelly&lt;BR /&gt; If (JJ.GT.NCelly) JJ=JJ-NCelly&lt;BR /&gt;C FOR Z&lt;BR /&gt; If (KK.LT.1) KK=KK+NCellz&lt;BR /&gt; If (KK.GT.NCellz) KK=KK-NCellz&lt;/P&gt;
&lt;P&gt;ID = Cell(II,JJ,KK)&lt;BR /&gt; Do While (ID.NE.0)&lt;BR /&gt; If (ID &amp;lt;= Num) Then&lt;BR /&gt; ID = Linker(ID) !Don't count same/twice&lt;BR /&gt; Cycle&lt;BR /&gt; End If&lt;BR /&gt; XX = DABS(RX(Num) - RX(ID))&lt;BR /&gt; YY = DABS(RY(Num) - RY(ID))&lt;BR /&gt; ZZ = DABS(RZ(Num) - RZ(ID))&lt;BR /&gt; if (XX.GT.HLx) XX = Lx - XX !P&lt;BR /&gt; if (YY.GT.HLy) YY = Ly - YY !B&lt;BR /&gt; if (ZZ.GT.HLz) ZZ = Lz - ZZ !C&lt;BR /&gt; RSQ = XX * XX + YY * YY + ZZ * ZZ&lt;/P&gt;
&lt;P&gt;IF (RSQ &amp;lt; RcutB2 .AND. BindOn) Then&lt;BR /&gt; if (Bond(Num,ID) == 0) Then&lt;BR /&gt; Btest = UNIF(jsr)&lt;BR /&gt; if (Btest &amp;lt; Bon) Then&lt;BR /&gt; Bond(Num,ID) = 1&lt;BR /&gt; Nbond = Nbond + 1&lt;/P&gt;
&lt;P&gt;End if&lt;BR /&gt; End if&lt;BR /&gt; End if&lt;/P&gt;
&lt;P&gt;If (Bond(Num,ID) == 1) Then&lt;BR /&gt; Btest = UNIF(jsr)&lt;BR /&gt; if (Btest &amp;lt; Boff) Then&lt;BR /&gt; Bond(Num,ID) = 0&lt;BR /&gt; Nbond = Nbond - 1&lt;/P&gt;
&lt;P&gt;End if&lt;BR /&gt; End if&lt;/P&gt;
&lt;P&gt;If ((Bond(Num,ID) == 1) .OR. (RSQ &amp;lt; BondEQ)) Then&lt;BR /&gt; BX = RX(Num) - RX(ID)&lt;BR /&gt; BY = RY(Num) - RY(ID)&lt;BR /&gt; BZ = RZ(Num) - RZ(ID)&lt;BR /&gt; &lt;BR /&gt; if (BX.GE.HLx) Then&lt;BR /&gt; BX = BX - Lx&lt;BR /&gt; Elseif (BX.LT.-HLx) Then&lt;BR /&gt; BX = BX + Lx&lt;BR /&gt; End If&lt;BR /&gt; if (BY.GE.HLy) Then&lt;BR /&gt; BY = BY - Ly&lt;BR /&gt; Elseif (BY.LT.-HLy) Then&lt;BR /&gt; BY = BY + Ly&lt;BR /&gt; End If&lt;BR /&gt; if (BZ.GE.HLz) Then&lt;BR /&gt; BZ = BZ - Lz&lt;BR /&gt; Elseif (BZ.LT.-HLz) Then&lt;BR /&gt; BZ = BZ + Lz&lt;BR /&gt; End If&lt;/P&gt;
&lt;P&gt;RR = DSQRT(RSQ)&lt;BR /&gt; BondR = RR - BondEQ&lt;BR /&gt; FFx = -Spring*BondR*(BX/RR)&lt;BR /&gt; FFy = -Spring*BondR*(BY/RR)&lt;BR /&gt; if (Zon) FFz = -Spring*BondR*(BZ/RR)&lt;/P&gt;
&lt;P&gt;FX_Priv(Num,TH) = FX_Priv(Num,TH) + FFx&lt;BR /&gt; FY_Priv(Num,TH) = FY_Priv(Num,TH) + FFy&lt;BR /&gt; FX_Priv(ID,TH) = FX_Priv(ID,TH) - FFx&lt;BR /&gt; FY_Priv(ID,TH) = FY_Priv(ID,TH) - FFy&lt;BR /&gt; If (Zon) Then&lt;BR /&gt; FZ_Priv(Num,TH) = FZ_Priv(Num,TH)+FFz&lt;BR /&gt; FZ_Priv(ID,TH) = FZ_Priv(ID,TH) - FFz&lt;BR /&gt; End If&lt;/P&gt;
&lt;P&gt;End If&lt;BR /&gt; ID = Linker(ID)&lt;BR /&gt; seed(Thread) = jsr&lt;BR /&gt; End Do&lt;BR /&gt; End Do&lt;BR /&gt; End Do&lt;BR /&gt; End Do&lt;/P&gt;
&lt;P&gt;FX_Priv(Num,TH) = FX_Priv(Num,TH)+Scale*GAUSS2(jsr,kn,fn,wn)&lt;BR /&gt; FY_Priv(Num,TH) = FY_Priv(Num,TH)+Scale*GAUSS2(jsr,kn,fn,wn)&lt;BR /&gt; IF(Zon) Then&lt;BR /&gt; FZ_Priv(Num,TH)=FZ_Priv(Num,TH)+Scale*GAUSS2(jsr,kn,fn,wn)&lt;BR /&gt; End If&lt;/P&gt;
&lt;P&gt;End Do&lt;BR /&gt;!$OMP END Do&lt;/P&gt;
&lt;P&gt;Do j=1,Thread_Num&lt;BR /&gt;!$OMP DO&lt;BR /&gt; Do i=1,N&lt;BR /&gt; FX(i) = FX(i) + FX_Priv(i,j)&lt;BR /&gt; FY(i) = FY(i) + FY_Priv(i,j)&lt;BR /&gt; if (Zon) FZ(i) = FZ(i) + FZ_Priv(i,j)&lt;BR /&gt; End Do&lt;BR /&gt;!$OMP END DO&lt;BR /&gt; End Do&lt;BR /&gt;!$OMP END PARALLEL&lt;/P&gt;
&lt;P&gt;End If&lt;/P&gt;
&lt;P&gt;RETURN&lt;BR /&gt; END&lt;/P&gt;
&lt;P&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Here, UNIF() and GAUSS2() are calls to a random number generators, and some of variables are defined in common statements that are included in the 'include system.inc' statement.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2013 02:00:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933785#M88417</guid>
      <dc:creator>Mike3</dc:creator>
      <dc:date>2013-06-26T02:00:00Z</dc:date>
    </item>
    <item>
      <title>Quote:Mike wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933786#M88418</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Mike wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;All the variables have been defined as evidenced by the program working with the -openmp and -O1 flags&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Sorry, but that's not evidence of anything.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2013 08:24:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933786#M88418</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-06-26T08:24:39Z</dc:date>
    </item>
    <item>
      <title>I do not see Nbond declared.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933787#M88419</link>
      <description>&lt;P&gt;I do not see Nbond declared. Is it in one of your .inc files?&lt;/P&gt;
&lt;P&gt;In any event, the REDUCTION( + : Nbond), I believe would belong on the !$OMP PARALLEL, not on the enclosed !$OMP DO&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2013 20:14:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933787#M88419</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-06-26T20:14:28Z</dc:date>
    </item>
    <item>
      <title>Hello,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933788#M88420</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Yes, Nbond is defined in my system.inc file. &amp;nbsp;I tired moving the REDUCTION(+:Nbond) into the !$OMP PARALLEL section, but it still produced the same results. &amp;nbsp;Here is a sample output of my program showing the difference.&lt;/P&gt;
&lt;P&gt;Run in serial with -O3:&lt;/P&gt;
&lt;P&gt;Time (us) &amp;nbsp;Nbonds &amp;nbsp; &amp;nbsp; N&lt;/P&gt;
&lt;P&gt;100.0000 &amp;nbsp;13328 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 200.0000 &amp;nbsp;13474 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 300.0000 &amp;nbsp;13568 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 400.0000 &amp;nbsp;13667 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 500.0000 &amp;nbsp;13707 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 600.0000 &amp;nbsp;13751 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 700.0000 &amp;nbsp;13800 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 800.0000 &amp;nbsp;13844 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 900.0000 &amp;nbsp;13852 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;BR /&gt; 1000.0000 13878 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;/P&gt;
&lt;P&gt;Run using 8 threads and -O1 -openmp&lt;/P&gt;
&lt;P&gt;Time (us) &amp;nbsp;Nbonds &amp;nbsp; &amp;nbsp;N&lt;/P&gt;
&lt;P&gt;100.0000 &amp;nbsp;13348 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 200.0000 &amp;nbsp;13532 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 300.0000 &amp;nbsp;13589 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 400.0000 &amp;nbsp;13701 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 500.0000 &amp;nbsp;13775 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 600.0000 &amp;nbsp;13784 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 700.0000 &amp;nbsp;13814 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 800.0000 &amp;nbsp;13883 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 900.0000 &amp;nbsp;13869 &amp;nbsp; &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 1000.0000 13906 &amp;nbsp; &amp;nbsp; &amp;nbsp;5041&lt;/P&gt;
&lt;P&gt;Run with 8 Threads and -O3 -openmp&lt;/P&gt;
&lt;P&gt;Time (us) &amp;nbsp;Nbonds &amp;nbsp; &amp;nbsp; N&lt;/P&gt;
&lt;P&gt;100.0000 &amp;nbsp;7499843 &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 200.0000 &amp;nbsp;9781784 &amp;nbsp; &amp;nbsp; 5041&lt;BR /&gt; 300.0000 &amp;nbsp;10867080 &amp;nbsp; 5041&lt;BR /&gt; 400.0000 &amp;nbsp;11468020 &amp;nbsp; 5041&lt;BR /&gt; 500.0000 &amp;nbsp;11824365 &amp;nbsp; 5041&lt;BR /&gt; 600.0000 &amp;nbsp;12042995 &amp;nbsp; 5041&lt;BR /&gt; 700.0000 &amp;nbsp;12178306 &amp;nbsp; 5041&lt;BR /&gt; 800.0000 &amp;nbsp;12265422 &amp;nbsp; 5041&lt;BR /&gt; 900.0000 &amp;nbsp;12319681 &amp;nbsp; 5041&lt;BR /&gt; 1000.0000 12354566 &amp;nbsp;5041&lt;/P&gt;
&lt;P&gt;The middle number of the output corresponds to the Nbond variable that I use in the reduction clause. &amp;nbsp;It is a stochastic variable, so the numbers between the runs should not be the exact same, but they should be close. &amp;nbsp;When I use the -O3 compiler flag, the output Nbond variable icreases by about 1000?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 00:05:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933788#M88420</guid>
      <dc:creator>Mike3</dc:creator>
      <dc:date>2013-06-27T00:05:12Z</dc:date>
    </item>
    <item>
      <title>Save a copy of your code to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933789#M88421</link>
      <description>&lt;P&gt;Save a copy of your code to reference later. Make these edits and give it a try:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;integer :: NbondLocal&lt;BR /&gt;...&lt;BR /&gt;!$OMP PARALLEL DEFAULT(Shared) PRIVATE(Num,ID,jsr,Thread,CX,CY,CZ,i,j,k,&amp;nbsp; &lt;BR /&gt;!$OMP&amp;amp; II,JJ,KK,XX,YY,ZZ,RSQ,Btest,BX,BY,BZ,RR,BondR,FFx,FFy,FFz,TH, NbondLocal) ! the local copy &lt;BR /&gt;!$OMP&amp;amp; REDUCTION( + : Nbond) ! the .inc copy&lt;BR /&gt;nBondLocal = 0&lt;BR /&gt;...&lt;BR /&gt;!$OMP DO SCHEDUAL(Static) ! *** no reduction here&lt;BR /&gt;...&lt;BR /&gt;NbondLocal = NbondLocal + 1 ! **** replace all nBond with NbondLocal inside the !$OMP DO&lt;BR /&gt;!$OMP END DO&lt;BR /&gt;Nbond = Nbond + NbondLocal ! accumulate into the reduction variable here&lt;BR /&gt;...&lt;BR /&gt;!$OMP END PARALLEL ! performs the reduction from inner Nbond to outer Nbond here&lt;BR /&gt;&amp;nbsp;[/fortran]&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 05:52:22 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933789#M88421</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-06-27T05:52:22Z</dc:date>
    </item>
    <item>
      <title>Thank you for the response.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933790#M88422</link>
      <description>&lt;P&gt;Thank you for the response. &amp;nbsp;I tried switching to using Nbondlocal within the inner loop. &amp;nbsp;I am still experiencing the same problems, but this does seem to be a better way of doing things. &amp;nbsp;I think I have tracked things down to the calls to the random number generator (Btest = UNIF(jsr) in the code). &amp;nbsp;It seems that when I use the -O1 compiler flag the value of jsr is being changed (as it is changed within the UNIF function) but when I use the -O3 compiler flag, the value of jsr is the same throughout. &amp;nbsp;Therefore, I am generally not getting into the section of the code where Nbondlocal (or Nbond) is decreased. &amp;nbsp;Is there a difference in how ifort handles function calls when the -O1 optimization flag is used versus the -O3 optimization flag?&lt;/P&gt;
&lt;P&gt;The random number generator function looks like this:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;Function UNIF(jsr)&lt;BR /&gt; Implicit None&lt;/P&gt;
&lt;P&gt;C ** Fuction to Generate Uniformly Distributed ********************* &lt;BR /&gt;C ** Random Numbers on [0,1] ****************************************&lt;/P&gt;
&lt;P&gt;INTEGER jsr, jsr_input&lt;BR /&gt; REAL UNIF&lt;/P&gt;
&lt;P&gt;jsr_input = jsr&lt;/P&gt;
&lt;P&gt;jsr = ieor (jsr, ishft(jsr, 13))&lt;BR /&gt; jsr = ieor (jsr, ishft(jsr, -17))&lt;BR /&gt; jsr = ieor (jsr, ishft(jsr, 5))&lt;/P&gt;
&lt;P&gt;UNIF = 0.5E+00 + 0.2328306E-9 * REAL( jsr_input + jsr )&lt;/P&gt;
&lt;P&gt;Return&lt;BR /&gt; End&lt;/P&gt;
&lt;P&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;When I output the value of jsr within the function, it does change from the beginning to the end of the function. &amp;nbsp;However, when I output the value of jsr before and after the call to the function, the result is jsr is different with the -O1 flag set and jsr is the same when the -O3 flag is set. &amp;nbsp;I tried declaring jsr within the function with intent(inout), but that did not solve the problem. &amp;nbsp;I am not sure if this is the exact cause for the value of Nbond to be so greatly increased, but it couldn't help. &amp;nbsp;Also, this problem (neither the Nbond or the random number generator problem) occur when compiling with gfortran and the -O3 flag.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 17:43:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933790#M88422</guid>
      <dc:creator>Mike3</dc:creator>
      <dc:date>2013-06-27T17:43:32Z</dc:date>
    </item>
    <item>
      <title>You should have disclosed</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933791#M88423</link>
      <description>&lt;P&gt;You should have disclosed that UNIF were a random number generator.&lt;/P&gt;
&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;P&gt;[fortran]&lt;BR /&gt;!$OMP Do SCHEDULE(Static) REDUCTION( + : Nbond)&lt;BR /&gt;Do Num = 1,N&lt;BR /&gt;&amp;nbsp; jsr = seed(0)&lt;BR /&gt;&amp;nbsp; DO I=1,N&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Best = UNIF(jsr)&lt;BR /&gt;&amp;nbsp; END DO&lt;BR /&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;This way, each iteration of the Do Num loop has a unique random seed, that is the same, regardless of which thead or how many threads (including 1 thread)&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 21:14:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933791#M88423</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-06-27T21:14:53Z</dc:date>
    </item>
    <item>
      <title>You want reproducability, use</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933792#M88424</link>
      <description>&lt;P&gt;You want reproducability, use a reproducable method.&lt;/P&gt;
&lt;P&gt;For performance, you could build (once) an array of N seed values, then re-init using a lookup: jsr=jsr_seed(Num)&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 21:18:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933792#M88424</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-06-27T21:18:10Z</dc:date>
    </item>
    <item>
      <title>Thanks for your input, but I</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933793#M88425</link>
      <description>&lt;P&gt;Thanks for your input, but I am a little confused. &amp;nbsp;In the code listed above, the array seed is previously initialized with random integers corresponding to the maximum number of threads and then passed to the subroutine.&lt;/P&gt;
&lt;P&gt;[fortran]&lt;/P&gt;
&lt;P&gt;Thread = OMP_GET_THREAD_NUM()&lt;/P&gt;
&lt;P&gt;!$OMP&amp;nbsp;Do&amp;nbsp;SCHEDULE(Static) REDUCTION( + : Nbond)&lt;/P&gt;
&lt;P&gt;Do&amp;nbsp;Num = 1, N&lt;/P&gt;
&lt;P&gt;jsr = seed(Thread)&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;(Bond(Num,ID) == 0)&amp;nbsp;Then&lt;/P&gt;
&lt;P&gt;Btest&amp;nbsp;= UNIF(jsr)&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;End If&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;End Do&lt;/P&gt;
&lt;P&gt;[/fortran]&lt;/P&gt;
&lt;P&gt;Is this not giving me a unique random seed for each thread? &amp;nbsp;What seems to be the difference is that with the -O1 flag, when I call UNIF(jsr) with a particular value of jsr, the value of jsr is changed during the call to UNIF(jsr). &amp;nbsp;However, when I use the -O3 flag, the value of jsr is the same before and after the call to UNIF(jsr) for a given thread (the values of jsr are different among the different threads, but the value of jst for the same thread does not change between successive calls to UNIF(jsr))&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 21:33:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933793#M88425</guid>
      <dc:creator>Mike3</dc:creator>
      <dc:date>2013-06-27T21:33:58Z</dc:date>
    </item>
    <item>
      <title>The code I provided gives a</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933794#M88426</link>
      <description>&lt;P&gt;The code I provided gives a unique random seed for: Num=1, Num=2, Num=3, ...&lt;BR /&gt;and the same random seed for the given Num&lt;BR /&gt;no matter which order the Num's are encountered&lt;/P&gt;
&lt;P&gt;With 2 threads, the !$OMP DO might have in order of time&lt;/P&gt;
&lt;P&gt;Thread(0), Num=1&lt;BR /&gt;Thread(1), Num=N/2&lt;BR /&gt;Thread(0), Num=2&lt;BR /&gt;Thread(0), Num=3 (thread 0 beat thread 1 this time)&lt;BR /&gt;Thread(1), Num=N/2+1&lt;BR /&gt;...&lt;/P&gt;
&lt;P&gt;Additionaly, depending on how the code flows, a differing number of UNIF's may be called by each thread.&lt;/P&gt;
&lt;P&gt;The code I provided, gives random sequences, that are consistent with respect of Num, regardless of the order in which the Num is processed.&lt;/P&gt;
&lt;P&gt;In -O3, the value of jsr may reside in a register, watching the memory location reserved for jsr will not show you what is in the register (register gets copied only when a save is required). Also, the debugger gets at times gets goofed up with respect to finding variables across a shared/private boundary.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2013 23:56:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/openmp-Reduction-differences-with-reduction-flag/m-p/933794#M88426</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2013-06-27T23:56:33Z</dc:date>
    </item>
  </channel>
</rss>

