Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28935 Discussions

Incorrect results from using private arrays in !$OMP TARGET PRIVATE()

cu238
Novice
899 Views

Recently I am trying to make my numerical model running on Intel ARC A750 GPU by using IFX compiler. I found codes like below would generate incorrect results and makes the model wrong or instable:

REAL SW(11)

N_CTRD=38753

!----------------------------------------------------------------------------

!$OMP TARGET DEFAULTMAP(present: allocatable) PRIVATE(SW)
!$OMP TEAMS DISTRIBUTE PARALLEL DO
DO I = 1,N_CTRD

    ...

ENDDO

!$OMP END TARGET

!----------------------------------------------------------------------------

Replacing this privare array SW with 2-d array A could correct the results:

REAL A(38573,11)

N_CTRD=38753

!----------------------------------------------------------------------------

!$OMP TARGET DEFAULTMAP(present: allocatable) !!!PRIVATE(SW)
!$OMP TEAMS DISTRIBUTE PARALLEL DO
DO I = 1,N_CTRD

IF(FSM(I).EQ.1.) THEN
! SW(1) = F(I,1)
A(I,1) = F(I,1)
IF (W(I,2).LT.0.) THEN
! SW(2) = F(I,1)
A(I,2) = F(I,1)
ELSE
IF (ABS(F(I,2)-F(I,1)).LE.EPSON) THEN
RD = 0.
ELSE
RD = (F(I,3)-F(I,2))/(F(I,2)-F(I,1))
RKAD = KAZ(I,3)/KAZ(I,2)
ENDIF
A1 = 1./4.*KAZ(I,2)+1./2.-1./(12.*KAZ(I,2))
B1 = -1./4*KAZ(I,2)+1./2.+1./(12.*KAZ(I,2))
BETAD = A1+B1*RD
! SW(2) = F(I,2)
A(I,2) = F(I,2)
* +0.5*AMAX1(0.,AMIN1(2.,2*RD*RKAD,BETAD))
* *((F(I,1)-F(I,2))*KAZ(I,2))
ENDIF
DO K = 3, KBM1
IF (W(I,K).GE.0.) THEN
IF (K.NE.KBM1) THEN
IF (ABS(F(I,K)-F(I,K-1)).LE.EPSON) THEN
RD = 0.
ELSE
RD = (F(I,K+1)-F(I,K))/(F(I,K)-F(I,K-1))
RKAD = KAZ(I,K+1)/KAZ(I,K)
ENDIF
A1 = 1./4.*KAZ(I,K)+1./2.-1./(12.*KAZ(I,K))
B1 = -1./4*KAZ(I,K)+1./2.+1./(12.*KAZ(I,K))
BETAD = A1+B1*RD
! SW(K) = F(I,K)
A(I,K) = F(I,K)
* +0.5*AMAX1(0.,AMIN1(2.,2*RD*RKAD,BETAD))
* *((F(I,K-1)-F(I,K))*KAZ(I,K))
ELSE
! SW(K) = F(I,K)
A(I,K) = F(I,K)
ENDIF
ELSE
IF (ABS(F(I,K)-F(I,K-1)).LE.EPSON) THEN
RU = 0.
ELSE
RU = (F(I,K-1)-F(I,K-2))/(F(I,K)-F(I,K-1))
RKAU = KAZ(I,K-1)/KAZ(I,K)
ENDIF
A1 = 1./4.*KAZ(I,2)+1./2.-1./(12.*KAZ(I,2))
B1 = -1./4*KAZ(I,2)+1./2.+1./(12.*KAZ(I,2))
BETAU = A1+B1*RU
! SW(K) = F(I,K-1)
A(I,K) = F(I,K-1)
* -0.5*AMAX1(0.,AMIN1(2.,2*RU*RKAU,BETAU))
* *((F(I,K-1)-F(I,K))*KAZ(I,K))
ENDIF
ENDDO
! SW(KB) = F(I,KBM1)
A(I,KB) = F(I,KBM1)
DO K = 1,KBM1
! FF(I,K) = DZR(K)*(SW(K)*W(I,K)-SW(K+1)*W(I,K+1))*DJ(I)
FF(I,K) = DZR(K)*(A(I,K)*W(I,K)-A(I,K+1)*W(I,K+1))*DJ(I)
ENDDO
ENDIF

ENDDO
!$OMP END TARGET

!----------------------------------------------------------------------------

There are still some private clause used in my model with smaller "N_CTRD" like 94 instead of 38753. I don't know whether they would generate incorrect results too. The model's results seem correct by now.

 

Thanks!

Labels (2)
0 Kudos
1 Solution
TobiasK
Moderator
766 Views

@cu238 can you please use the 'code' formatting when inserting a code block. It's quite hard to read the code.

For you problem, can you please move the private to the distribute parallel do construct?

!$OMP TARGET DEFAULTMAP(present: allocatable) 
!$OMP TEAMS DISTRIBUTE PARALLEL DO PRIVATE(SW)

instead of

!$OMP TARGET DEFAULTMAP(present: allocatable) PRIVATE(SW)
!$OMP TEAMS DISTRIBUTE PARALLEL DO 

 

View solution in original post

0 Kudos
4 Replies
cu238
Novice
890 Views

REAL A(38753,11)

It is defined in a module, which is used by a SUBROUTINE including this code frament. 

0 Kudos
cu238
Novice
887 Views

KB=11, KBM1=10

0 Kudos
TobiasK
Moderator
767 Views

@cu238 can you please use the 'code' formatting when inserting a code block. It's quite hard to read the code.

For you problem, can you please move the private to the distribute parallel do construct?

!$OMP TARGET DEFAULTMAP(present: allocatable) 
!$OMP TEAMS DISTRIBUTE PARALLEL DO PRIVATE(SW)

instead of

!$OMP TARGET DEFAULTMAP(present: allocatable) PRIVATE(SW)
!$OMP TEAMS DISTRIBUTE PARALLEL DO 

 

0 Kudos
cu238
Novice
699 Views

Sorry for the inconvenience. I'll try the 'code' formatting next time.

The result is correct now after moving the PRIVATE(SW) down. It's great! Thanks a lot!

 

0 Kudos
Reply