From 04194cbc574c6334f403500b2f3945e667b5b2a2 Mon Sep 17 00:00:00 2001
From: Juan ESCOBAR <juan.escobar@aero.obs-mip.fr>
Date: Tue, 24 Oct 2023 16:05:46 +0200
Subject: [PATCH] Juan 24/10/2023:MNH/*.f90 , for cce/16.0.0 , add new
 present_cr directive to avoid FALSE RECURRENCE on GPU

---
 src/MNH/gradient_m.f90              |  2 +-
 src/MNH/ice4_fast_rh.f90            |  2 +-
 src/MNH/ice4_nucleation_wrapper.f90 |  2 +-
 src/MNH/ice4_tendencies.f90         |  2 +-
 src/MNH/rain_ice_fast_rh.f90        |  6 +++---
 src/MNH/turb_hor_splt.f90           | 14 +++++++-------
 src/MNH/turb_hor_tke.f90            |  4 ++--
 7 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/MNH/gradient_m.f90 b/src/MNH/gradient_m.f90
index 2731cbd34..6c30e2f52 100644
--- a/src/MNH/gradient_m.f90
+++ b/src/MNH/gradient_m.f90
@@ -657,7 +657,7 @@ call Print_msg( NVERB_WARNING, 'GEN', 'GZ_M_M_DEVICE', 'OpenACC: not yet tested'
 !              --------------------
 !
 CALL DZM_DEVICE( PA(:,:,:), ZTMP1(:,:,:) )
-!$acc kernels
+!$acc kernels present_cr(ZTMP2)
 ZTMP2(:,:,:) = ZTMP1(:,:,:) / PDZZ(:,:,:)
 !$acc end kernels
 CALL MZF_DEVICE( ZTMP2(:,:,:), PGZ_M_M(:,:,:) )
diff --git a/src/MNH/ice4_fast_rh.f90 b/src/MNH/ice4_fast_rh.f90
index 04c1d71ee..2ca808211 100644
--- a/src/MNH/ice4_fast_rh.f90
+++ b/src/MNH/ice4_fast_rh.f90
@@ -569,7 +569,7 @@ ELSE
   PRH_TEND(:, IRRWETH)=0.
 !$acc end kernels
   IF(IGWET>0)THEN
-!$acc kernels present_cr(ZVEC1,ZVEC2)
+!$acc kernels present_cr(ZVEC1,ZVEC2,ZVEC3)
     !
     !*       7.2.12  select the (PLBDAH,PLBDAR) couplet
     !
diff --git a/src/MNH/ice4_nucleation_wrapper.f90 b/src/MNH/ice4_nucleation_wrapper.f90
index 74df1318a..37543ce88 100644
--- a/src/MNH/ice4_nucleation_wrapper.f90
+++ b/src/MNH/ice4_nucleation_wrapper.f90
@@ -146,7 +146,7 @@ CALL MNH_MEM_GET( gnegt, kit, kjt, kkt )
 !  optimization by looking for locations where
 !  the temperature is negative only !!!
 !
-!$acc kernels
+!$acc kernels present_cr(GNEGT)
 GNEGT(:,:,:)=PT(:,:,:)<XTT .AND. LDMASK
 INEGT = COUNT(GNEGT(:,:,:))
 !$acc end kernels
diff --git a/src/MNH/ice4_tendencies.f90 b/src/MNH/ice4_tendencies.f90
index 8ee10ef63..1578bc99a 100644
--- a/src/MNH/ice4_tendencies.f90
+++ b/src/MNH/ice4_tendencies.f90
@@ -637,7 +637,7 @@ IF(ISIZE>0) THEN
                         PHLI_HCF, PHLI_LCF, PHLI_HRI, PHLI_LRI, ZRF)
   IF(HSUBG_RC_RR_ACCR=='PRFR' .OR. HSUBG_RR_EVAP=='PRFR') THEN
     !Diagnostic of precipitation fraction
-!$acc kernels
+!$acc kernels present_cr(ZRRT3D,ZRST3D,ZRGT3D,ZRHT3D)
     PRAINFR(:,:,:) = 0.
     ZRRT3D (:,:,:) = 0.
     ZRST3D (:,:,:) = 0.
diff --git a/src/MNH/rain_ice_fast_rh.f90 b/src/MNH/rain_ice_fast_rh.f90
index a2d969e71..fc5445fae 100644
--- a/src/MNH/rain_ice_fast_rh.f90
+++ b/src/MNH/rain_ice_fast_rh.f90
@@ -178,7 +178,7 @@ CALL MNH_MEM_GET( ZZW1,  SIZE(PRHODREF), 7 )
 !$acc data present( I1H, I1W, GWORK, ZZW, ZZW1 )
 #endif
 
-!$acc kernels
+!$acc kernels present_cr(GWORK)
   GWORK(:) = PRHT(:)>XRTMIN(7)
 !$acc end kernels
 #ifndef MNH_OPENACC
@@ -229,7 +229,7 @@ CALL MNH_MEM_GET( ZZW1,  SIZE(PRHODREF), 7 )
 !
 !*       7.2.1  accretion of aggregates on the hailstones
 !
-!$acc kernels
+!$acc kernels present_cr(GWORK)
     GWORK(1:IHAIL) = PRST(I1H(1:IHAIL))>XRTMIN(5) .AND. PRSS(I1H(1:IHAIL))>0.0
 !$acc end kernels
 #ifndef MNH_OPENACC
@@ -327,7 +327,7 @@ CALL MNH_MEM_GET( ZZW1,  SIZE(PRHODREF), 7 )
 !
 !*       7.2.6  accretion of graupeln on the hailstones
 !
-!$acc kernels
+!$acc kernels present_cr(GWORK)
     GWORK(1:IHAIL) = PRGT(I1H(1:IHAIL))>XRTMIN(6) .AND. PRGS(I1H(1:IHAIL))>0.0
 !$acc end kernels
 #ifndef MNH_OPENACC
diff --git a/src/MNH/turb_hor_splt.f90 b/src/MNH/turb_hor_splt.f90
index b30e280c6..8f0774896 100644
--- a/src/MNH/turb_hor_splt.f90
+++ b/src/MNH/turb_hor_splt.f90
@@ -556,7 +556,7 @@ IF (KSPLIT>1 .AND. CPROGRAM=='MESONH') THEN
 !             ---------------
 !
 !
-  !$acc kernels
+  !$acc kernels present_cr(ZSVM,ZRM)
   ZUM=PUM
   ZVM=PVM
   ZWM=PWM
@@ -613,7 +613,7 @@ IF (KSPLIT>1 .AND. CPROGRAM=='MESONH') THEN
 #else
     CALL MXM_DEVICE(PRHODJ,ZTMP1_DEVICE)
     CALL MYM_DEVICE(PRHODJ,ZTMP2_DEVICE)
-!$acc kernels
+!$acc kernels present_cr(ZSVM,ZRM)
     ZUM=PUM+(ZRUS/KSPLIT-PRUS)/ZTMP1_DEVICE*PTSTEP
     ZVM=PVM+(ZRVS/KSPLIT-PRVS)/ZTMP2_DEVICE*PTSTEP
 #endif
@@ -659,7 +659,7 @@ IF (KSPLIT>1 .AND. CPROGRAM=='MESONH') THEN
 #endif
     !
     IF ( HLBCX(1) /= "CYCL" .AND. LWEST_ll()) THEN
-!$acc kernels
+!$acc kernels present_cr(ZSVM,ZRM)
        ZUM(IIB  ,:,:)=PUM(IIB  ,:,:)
        ZVM(IIB-1,:,:)=PVM(IIB-1,:,:)
        ZWM(IIB-1,:,:)=PWM(IIB-1,:,:)
@@ -671,7 +671,7 @@ IF (KSPLIT>1 .AND. CPROGRAM=='MESONH') THEN
      ENDIF
      !
      IF ( HLBCX(2) /= "CYCL" .AND. LEAST_ll()) THEN
-!$acc kernels
+!$acc kernels present_cr(ZSVM,ZRM)
        ZUM(IIE+1,:,:)=PUM(IIE+1,:,:)
        ZVM(IIE+1,:,:)=PVM(IIE+1,:,:)
        ZWM(IIE+1,:,:)=PWM(IIE+1,:,:)
@@ -683,7 +683,7 @@ IF (KSPLIT>1 .AND. CPROGRAM=='MESONH') THEN
      ENDIF
      !
      IF ( HLBCY(1) /= "CYCL" .AND. LSOUTH_ll()) THEN
-!$acc kernels
+!$acc kernels present_cr(ZSVM,ZRM)
        ZUM(:,IJB-1,:)=PUM(:,IJB-1,:)
        ZVM(:,IJB  ,:)=PVM(:,IJB  ,:)
        ZWM(:,IJB-1,:)=PWM(:,IJB-1,:)
@@ -695,7 +695,7 @@ IF (KSPLIT>1 .AND. CPROGRAM=='MESONH') THEN
      ENDIF
      !
      IF ( HLBCY(2) /= "CYCL" .AND. LNORTH_ll()) THEN
-!$acc kernels
+!$acc kernels present_cr(ZSVM,ZRM)
        ZUM(:,IJE+1,:)=PUM(:,IJE+1,:)
        ZVM(:,IJE+1,:)=PVM(:,IJE+1,:)
        ZWM(:,IJE+1,:)=PWM(:,IJE+1,:)
@@ -706,7 +706,7 @@ IF (KSPLIT>1 .AND. CPROGRAM=='MESONH') THEN
 !$acc end kernels
      ENDIF
      !
-!$acc kernels
+!$acc kernels present_cr(ZSVM,ZRM)
      ZUM(:,:,IKB-1)=ZUM(:,:,IKB)
      ZVM(:,:,IKB-1)=ZVM(:,:,IKB)
      ZWM(:,:,IKB-1)=ZWM(:,:,IKB)
diff --git a/src/MNH/turb_hor_tke.f90 b/src/MNH/turb_hor_tke.f90
index 0aa4d3d69..a8fb4d6c4 100644
--- a/src/MNH/turb_hor_tke.f90
+++ b/src/MNH/turb_hor_tke.f90
@@ -319,7 +319,7 @@ IF (.NOT. LFLAT) THEN
   !$acc end kernels 
 ELSE
   CALL MXM_DEVICE(PRHODJ,ZTMP1_DEVICE)
-  !$acc kernels
+  !$acc kernels present_cr(ZTMP2_DEVICE,ZTMP1_DEVICE)
   ZTMP2_DEVICE = ZTMP1_DEVICE * ZFLX * PINV_PDXX
   !$acc end kernels 
   CALL DXF_DEVICE(ZTMP2_DEVICE,ZTMP1_DEVICE)
@@ -458,7 +458,7 @@ IF (.NOT. L2D) THEN
     !$acc end kernels 
   ELSE
     CALL MYM_DEVICE(PRHODJ,ZTMP1_DEVICE)
-    !$acc kernels
+    !$acc kernels present_cr(ZTMP2_DEVICE,ZTMP1_DEVICE)
     ZTMP2_DEVICE = ZTMP1_DEVICE * ZFLX * PINV_PDYY
     !$acc end kernels 
     CALL DYF_DEVICE(ZTMP2_DEVICE,ZTMP1_DEVICE)
-- 
GitLab