How to parallel it

Hi, I have a code as below:

        do k=1,n3  
          nb1=0 
          do eid1=1,nb_dem 
        if(Z(k)<=XYZ(3,eid1).and.XYZ(3,eid1)<=D(k))then
            nb1=nb1+1
                    list_z(nb1,k)=eid1
        else if(XYZ(3,eid1)<=Z(k).and.Z(k)<=XYZ(6,eid1))then
            nb1=nb1+1
                    list_z(nb1,k)=eid1
            mask1(eid1,k)=100
        end if
      end do        
      A1(k)=nb1
    end do

because there has "if " and “else if”, I want to know how to parallel it ,please kindly advise me

Hi Teslalady,

I would suggested something like:

!$acc parallel loop gang
        do k=1,n3  
           nb1=0 
!$acc loop vector reduction(+:nb1)
           do eid1=1,nb_dem 
         if(Z(k)<=XYZ(3,eid1).and.XYZ(3,eid1)<=D(k))then 
             nb1=nb1+1 
                     list_z(nb1,k)=eid1 
         else if(XYZ(3,eid1)<=Z(k).and.Z(k)<=XYZ(6,eid1))then 
             nb1=nb1+1 
                     list_z(nb1,k)=eid1 
             mask1(eid1,k)=100 
         end if 
       end do        
       A1(k)=nb1 
     end do

Note that the IF statements shouldn’t matter.

  • Mat