I have a code where I have parallelized one of the intensive subroutines using openmp. 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. 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. Is there something about the optimization flags that are incompatbile with OMP REDUCTION?
Here is the portion of the code related to the reduction variable:
!$OMP PARALLEL DEFAULT(Shared) PRIVATE(Num,ID,jsr,Thread,CX,CY,CZ,i,j,k, !$OMP& II,JJ,KK,XX,YY,ZZ,RSQ,Btest,BX,BY,BZ,RR,BondR,FFx,FFy,FFz,TH) Thread = OMP_GET_THREAD_NUM() TH = Thread + 1 !$OMP Do SCHEDULE(Static) REDUCTION( + : Nbond) Do Num = 1,N jsr = seed(Thread) XX = DABS(RX(Num) - RX(ID)) YY = DABS(RY(Num) - RY(ID)) ZZ = DABS(RZ(Num) - RZ(ID)) RSQ = XX * XX + YY * YY + ZZ * ZZ IF (RSQ < RcutB2 .AND. BindOn) if (Bond(Num,ID) == 0) Then Btest = UNIF(jsr) if (Btest < Bon) Then Bond(Num,ID) = 1 Nbond = Nbond + 1 End if End if End if If (Bond(Num,ID) == 1) Then Btest = UNIF(jsr) if (Btest < Boff) Then Bond(Num,ID) = 0 Nbond = Nbond - 1 End Do !$OMP END Do !$OMP END PARALLEL
This is a code snippet with some of the other computations taken out. All the variables and whatnot are defines properly, as the code runs fine in serial and in parallel without O2 and O3 optimizations.