Hi,
I try to add accelerator directives into a subroutine with nested loops. The limits of inner loops are variant in the outer loops. May I parallelize the outer loop only to overcome the restriction that inner loop limits must be constant? Attached please find the code. Any suggestion is appreciated.
SUBROUTINE GRID_BASED_NEIGHBOR_SEARCH
USE param1
USE discretelement
USE geometry
USE des_bc
IMPLICIT NONE
!-----------------------------------------------
! Local variables
!-----------------------------------------------
INTEGER I, II, IP1, IM1 ! X-coordinate loop indices
INTEGER J, JJ, JP1, JM1 ! Y-coordinate loop indices
INTEGER K, KK, KP1, KM1 ! Z-coordinate loop indices
INTEGER PNO ! Temp. particle number variable
INTEGER NPG ! Temp. cell particle count
INTEGER LL, NP, NEIGH_L ! Loop Counters
INTEGER NLIM !
DOUBLE PRECISION DISTVEC(DIMN), DIST, R_LM ! Contact variables
!$acc region do kernel copy(neighbours) copyin(pijk,des_pos_new) &
!$acc copyin(imin1,imax1,jmin1,jmax1,dimn,kmin1,kmax1) &
!$acc copyin(des_radius,factor_rlm)
DO LL = 1, MAX_PIS
II = PIJK(LL,1); IP1=min(II+1,imax1); IM1=max(II-1,imin1)
JJ = PIJK(LL,2); JP1=min(JJ+1,jmax1); JM1=max(JJ-1,jmin1)
KK = PIJK(LL,3); KP1=KK; KM1=KK
IF(DIMN.EQ.3)THEN
KP1 = min(KK+1,kmax1); KM1 = max(KK-1,kmin1)
ENDIF
DO KK = KM1, KP1
DO JJ = JM1, JP1
DO II = IM1, IP1
! Shift loop index to new variables for manipulation
I = II; J = JJ; K = KK
! If cell IJK contains particles, store the amount in NPG
IF(ASSOCIATED(PIC(I,J,K)%P))THEN
NPG = SIZE(PIC(I,J,K)%P)
ELSE
NPG = 0
ENDIF
! Loop over the particles in IJK cell to determine if they are
! neighbors to particle LL
DO NP = 1,NPG
PNO = PIC(I,J,K)%P(NP)
IF(PNO.GT.LL)THEN
R_LM = DES_RADIUS(LL) + DES_RADIUS(PNO)
R_LM = FACTOR_RLM*R_LM
DISTVEC(:) = DES_POS_NEW(PNO,:) - DES_POS_NEW(LL,:)
if(dimn.eq.2)then
dist=sqrt(distvec(1)**2+distvec(2)**2)
else
dist=sqrt(distvec(1)**2+distvec(2)**2+distvec(3)**2)
endif
IF(DIST .LE. R_LM) then
NEIGHBOURS(LL,1) = NEIGHBOURS(LL,1) + 1
NLIM = NEIGHBOURS(LL,1) + 1
NEIGHBOURS(LL,NLIM) = PNO
ENDIF !contact condition
ENDIF !PNO.GT.LL
ENDDO !NP
ENDDO ! II cell loop
ENDDO ! JJ cell loop
ENDDO ! KK cell loop
ENDDO ! Particles in system loop
!$acc end region
END SUBROUTINE GRID_BASED_NEIGHBOR_SEARCH
[/code]