From 1fe8a7eb3c45773cfc8276eb95da9436eaee047b Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Tue, 11 Apr 2023 11:31:48 +0200
Subject: [PATCH] Philippe 11/04/2023:  OpenACC: merge COPY_CRSPD_TRANS_DEVICE
 into COPY_CRSPD_TRANS

---
 src/LIB/SURCOUCHE/src/mode_exchange_ll.f90   | 149 +------------------
 src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90 |  48 +-----
 2 files changed, 8 insertions(+), 189 deletions(-)

diff --git a/src/LIB/SURCOUCHE/src/mode_exchange_ll.f90 b/src/LIB/SURCOUCHE/src/mode_exchange_ll.f90
index e50387f7d..3a832a232 100644
--- a/src/LIB/SURCOUCHE/src/mode_exchange_ll.f90
+++ b/src/LIB/SURCOUCHE/src/mode_exchange_ll.f90
@@ -816,15 +816,9 @@ INTEGER                                               :: NB_REQ
 !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
 !               ------------------------------------------------------------
 !
-#ifndef MNH_OPENACC
   CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TSEND_TRANS_BX, &
                         TCRRT_COMDATA%TRECV_TRANS_BX, &
                         PFIELDIN, PFIELDOUT, KINFO)
-#else
-  CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TSEND_TRANS_BX, &
-                        TCRRT_COMDATA%TRECV_TRANS_BX, &
-                        PFIELDIN, PFIELDOUT, KINFO)
-#endif
 !
 
 !$acc end data
@@ -926,15 +920,9 @@ CALL MPPDB_CHECK( PFIELDIN, 'REMAP_X_2WAY_ll beg:PFIELDIN' )
 !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
 !               ------------------------------------------------------------
 !
-#ifndef MNH_OPENACC
   CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TRECV_TRANS_BX, &
                         TCRRT_COMDATA%TSEND_TRANS_BX, &
                         PFIELDIN, PFIELDOUT, KINFO)
-#else
-  CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TRECV_TRANS_BX, &
-                        TCRRT_COMDATA%TSEND_TRANS_BX, &
-                        PFIELDIN, PFIELDOUT, KINFO)
-#endif
 !
 !*       3.    UPDATE HALO :
 !              -----------
@@ -1038,15 +1026,9 @@ END IF
 !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
 !               ------------------------------------------------------------
 !
-#ifndef MNH_OPENACC
   CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TSEND_TRANS_XY, &
                         TCRRT_COMDATA%TRECV_TRANS_XY, &
                         PFIELDIN, PFIELDOUT, KINFO)
-#else
-  CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TSEND_TRANS_XY, &
-                        TCRRT_COMDATA%TRECV_TRANS_XY, &
-                        PFIELDIN, PFIELDOUT, KINFO)
-#endif
 
 !$acc end data
 
@@ -1143,16 +1125,9 @@ END IF
 !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
 !               ------------------------------------------------------------
 !
-#ifndef MNH_OPENACC
   CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TRECV_TRANS_XY, &
                         TCRRT_COMDATA%TSEND_TRANS_XY, &
                         PFIELDIN, PFIELDOUT, KINFO)
-#else
-  CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TRECV_TRANS_XY, &
-                        TCRRT_COMDATA%TSEND_TRANS_XY, &
-                        PFIELDIN, PFIELDOUT, KINFO)
-#endif
-
 !$acc end data
 
 IF (MPPDB_INITIALIZED) THEN
@@ -1459,123 +1434,6 @@ END IF
 !
 !*       1.    GO OVER THE TPSEND_CRSPD LIST OF ZONES
 !              --------------------------------------
-!
-  IF (.NOT.ASSOCIATED(TPSEND)) THEN
-    RETURN
-  ENDIF
-!
-  TZSEND => TPSEND
-  DO JSEND = 1, TPSEND%NCARD
-!
-!*       1.1   Test whether a zone is sent to the same proc
-!
-    IF (TZSEND%TELT%NUMBER == IP) THEN
-!
-!*       1.2   If so, go over the TPRECV list of zones
-!*             and test whether the zone to be received corresponds to
-!*             the zone to be sent
-!
-      TZRECV => TPRECV
-      DO WHILE (ASSOCIATED(TZRECV))
-        IF (TZRECV%TELT%NUMBER == IP &
-           .AND. TZRECV%TELT%MSSGTAG == TZSEND%TELT%MSSGTAG) THEN
-! 
-!*       1.2.1 If so, copy the zone
-!
-          CALL COPY_ZONE_TRANS(TZSEND%TELT, TZRECV%TELT, PFIELDIN, PFIELDOUT, &
-                               KINFO)
-!
-        ENDIF
-!
-        TZRECV => TZRECV%TNEXT
-!
-      ENDDO
-!
-    ENDIF
-!
-    TZSEND => TZSEND%TNEXT
-!
-  ENDDO
-!
-!-------------------------------------------------------------------------------
-!
-      END SUBROUTINE COPY_CRSPD_TRANS
-!
-#ifdef MNH_OPENACC
-!     #######################################################################
-      SUBROUTINE COPY_CRSPD_TRANS_DEVICE(TPSEND, TPRECV, PFIELDIN, PFIELDOUT, KINFO)
-!     #######################################################################
-!
-!!****  *COPY_CRSPD_TRANS* -
-!
-!!    Purpose
-!!    -------
-!       copy the zones a process sends to itself, instead of sending them
-!!    via MPI.
-!!
-!!**  Method
-!!    ------
-!     we go over all the zones of the TPSEND variable and find
-!     out those whose NUMBER equals IP.
-!     In this case the recipient of a ZONE is the same as the sender.
-!     To find out where the zone has to be copied we go over the
-!     TPRECV variable.
-!
-!!    External
-!!    --------
-!     Module MODE_EXCHANGE_ll
-!       COPY_ZONE_TRANS
-!
-!!    Implicit Arguments
-!!    ------------------
-!     Module MODD_ARGSLIST_ll
-!       type LIST_ll
-!
-!     Module MODD_STRUCTURE_ll
-!        type CRSPD_ll
-!
-!     Module MODD_VAR_ll
-!       IP - Number of local processor=subdomain
-!
-!!    Reference
-!!    ---------
-!
-!!    Author
-!!    ------
-!     N. Gicquel                * CERFACS - CNRM *
-!!
-!!    Modifications
-!!    -------------
-!!     1 october 1998
-!
-!-------------------------------------------------------------------------------
-!
-!*       0.    DECLARATIONS
-!              ------------
-!
-  USE MODD_ARGSLIST_ll, ONLY : LIST_ll
-  USE MODD_STRUCTURE_ll, ONLY : CRSPD_ll
-  USE MODD_VAR_ll, ONLY : IP
-!
-  IMPLICIT NONE
-!
-!*       0.1   declarations of arguments
-!
-  TYPE(CRSPD_ll), POINTER :: TPSEND     ! CRSPD to be sent
-  TYPE(CRSPD_ll), POINTER :: TPRECV     ! CRSPD to be received
-  REAL, DIMENSION(:,:,:), INTENT(INOUT)  :: PFIELDIN
-  REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PFIELDOUT
-  INTEGER                 :: KINFO       ! return status
-!
-!*       0.2   declarations of local variables
-!
-  TYPE(CRSPD_ll), POINTER :: TZSEND, TZRECV
-  INTEGER :: JSEND
-!
-!-------------------------------------------------------------------------------
-!
-!*       1.    GO OVER THE TPSEND_CRSPD LIST OF ZONES
-!              --------------------------------------
 !
   IF (.NOT.ASSOCIATED(TPSEND)) THEN
     RETURN
@@ -1597,7 +1455,7 @@ END IF
       DO WHILE (ASSOCIATED(TZRECV))
         IF (TZRECV%TELT%NUMBER == IP &
            .AND. TZRECV%TELT%MSSGTAG == TZSEND%TELT%MSSGTAG) THEN
-!
+! 
 !*       1.2.1 If so, copy the zone
 !
           CALL COPY_ZONE_TRANS(TZSEND%TELT, TZRECV%TELT, PFIELDIN, PFIELDOUT, &
@@ -1614,15 +1472,12 @@ END IF
     TZSEND => TZSEND%TNEXT
 !
   ENDDO
-
 !$acc end data
-
 !
 !-------------------------------------------------------------------------------
 !
-      END SUBROUTINE COPY_CRSPD_TRANS_DEVICE
+      END SUBROUTINE COPY_CRSPD_TRANS
 !
-#endif
 !     ######################################################################
       SUBROUTINE COPY_ZONE_TRANS(TPSEND, TPRECV, PFIELDIN, PFIELDOUT, KINFO)
 !     ######################################################################
diff --git a/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90 b/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90
index 3033a3290..496cd5d30 100644
--- a/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90
+++ b/src/LIB/SURCOUCHE/src/mode_splittingz_ll.f90
@@ -1068,7 +1068,7 @@ CONTAINS
 #ifndef MNH_OPENACC
     USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD, COPY_CRSPD_TRANS
 #else
-    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS_DEVICE
+    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS
 #endif
     USE MODD_VAR_ll     , ONLY : TCRRT_COMDATA
     USE MODD_CONFZ      , ONLY : NZ_SPLITTING ! for debug IZ=1=flat_inv;  IZ=2=flat_invz ;  IZ=1+2=the two
@@ -1115,15 +1115,9 @@ CONTAINS
     !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
     !               ------------------------------------------------------------
     !
-#ifndef MNH_OPENACC
     CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TSEND_SXP1_YP2_Z_SX_YP2_ZP1, &
          TCRRT_COMDATA%TRECV_SXP1_YP2_Z_SX_YP2_ZP1, &
          PFIELDIN, PFIELDOUT, KINFO)
-#else
-    CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TSEND_SXP1_YP2_Z_SX_YP2_ZP1, &
-         TCRRT_COMDATA%TRECV_SXP1_YP2_Z_SX_YP2_ZP1, &
-         PFIELDIN, PFIELDOUT, KINFO)
-#endif
     ELSE
     !
     !-------------------------------------------------------------------------------
@@ -1238,7 +1232,7 @@ CONTAINS
 #ifndef MNH_OPENACC
     USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD, COPY_CRSPD_TRANS
 #else
-    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS_DEVICE
+    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS
 #endif
     USE MODD_VAR_ll     , ONLY : TCRRT_COMDATA
     USE MODD_CONFZ      , ONLY : NZ_SPLITTING ! for debug IZ=1=flat_inv;  IZ=2=flat_invz ;  IZ=1+2=the two
@@ -1275,15 +1269,9 @@ CONTAINS
     !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
     !               ------------------------------------------------------------
     !
-#ifndef MNH_OPENACC
     CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TRECV_SXP1_YP2_Z_SX_YP2_ZP1, &
          TCRRT_COMDATA%TSEND_SXP1_YP2_Z_SX_YP2_ZP1, &
          PFIELDIN, PFIELDOUT, KINFO)
-#else
-    CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TRECV_SXP1_YP2_Z_SX_YP2_ZP1, &
-         TCRRT_COMDATA%TSEND_SXP1_YP2_Z_SX_YP2_ZP1, &
-         PFIELDIN, PFIELDOUT, KINFO)
-#endif
     ELSE
 #ifndef MNH_OPENACC
     CALL ALL_SEND_RECV(TCRRT_COMDATA%TRECV_BOX_SXP1_YP2_Z_SX_YP2_ZP1, &
@@ -1329,7 +1317,7 @@ CONTAINS
 #ifndef MNH_OPENACC
     USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD, COPY_CRSPD_TRANS
 #else
-    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS_DEVICE
+    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS
 #endif
     USE MODD_VAR_ll     , ONLY : TCRRT_COMDATA
     USE MODD_CONFZ      , ONLY : NZ_SPLITTING ! for debug IZ=1=flat_inv;  IZ=2=flat_invz ;  IZ=1+2=the two
@@ -1364,15 +1352,9 @@ CONTAINS
     !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
     !               ------------------------------------------------------------
     !
-#ifndef MNH_OPENACC
     CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TSEND_SX_YP2_ZP1_SXP2_Y_ZP1, &
          TCRRT_COMDATA%TRECV_SX_YP2_ZP1_SXP2_Y_ZP1, &
          PFIELDIN, PFIELDOUT, KINFO)
-#else
-    CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TSEND_SX_YP2_ZP1_SXP2_Y_ZP1, &
-         TCRRT_COMDATA%TRECV_SX_YP2_ZP1_SXP2_Y_ZP1, &
-         PFIELDIN, PFIELDOUT, KINFO)
-#endif
     ELSE
     !
     !-------------------------------------------------------------------------------
@@ -1420,7 +1402,7 @@ CONTAINS
 #ifndef MNH_OPENACC
     USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD, COPY_CRSPD_TRANS
 #else
-    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS_DEVICE
+    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS
 #endif
     USE MODD_VAR_ll     , ONLY : TCRRT_COMDATA
     USE MODD_CONFZ      , ONLY : NZ_SPLITTING ! for debug IZ=1=flat_inv;  IZ=2=flat_invz ;  IZ=1+2=the two
@@ -1454,15 +1436,9 @@ CONTAINS
     !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
     !               ------------------------------------------------------------
     !
-#ifndef MNH_OPENACC
     CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TRECV_SX_YP2_ZP1_SXP2_Y_ZP1, &
          TCRRT_COMDATA%TSEND_SX_YP2_ZP1_SXP2_Y_ZP1, &
          PFIELDIN, PFIELDOUT, KINFO)
-#else
-    CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TRECV_SX_YP2_ZP1_SXP2_Y_ZP1, &
-         TCRRT_COMDATA%TSEND_SX_YP2_ZP1_SXP2_Y_ZP1, &
-         PFIELDIN, PFIELDOUT, KINFO)
-#endif
     ELSE
     !
     !-------------------------------------------------------------------------------
@@ -1508,7 +1484,7 @@ CONTAINS
 #ifndef MNH_OPENACC
     USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD, COPY_CRSPD_TRANS
 #else
-    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS_DEVICE
+    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS
 #endif
     USE MODD_VAR_ll     , ONLY : TCRRT_COMDATA
     USE MODD_CONFZ      , ONLY : NZ_SPLITTING ! for debug IZ=1=flat_inv;  IZ=2=flat_invz ;  IZ=1+2=the two
@@ -1545,15 +1521,9 @@ CONTAINS
     !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
     !               ------------------------------------------------------------
     !
-#ifndef MNH_OPENACC
     CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TSEND_SXP2_Y_ZP1_SXP2_YP1_Z, &
          TCRRT_COMDATA%TRECV_SXP2_Y_ZP1_SXP2_YP1_Z, &
          PFIELDIN, PFIELDOUT, KINFO)
-#else
-    CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TSEND_SXP2_Y_ZP1_SXP2_YP1_Z, &
-         TCRRT_COMDATA%TRECV_SXP2_Y_ZP1_SXP2_YP1_Z, &
-         PFIELDIN, PFIELDOUT, KINFO)
-#endif
     ELSE
 #ifndef MNH_OPENACC
     CALL ALL_SEND_RECV(TCRRT_COMDATA%TSEND_BOX_SXP2_Y_ZP1_SXP2_YP1_Z, &
@@ -1665,7 +1635,7 @@ CONTAINS
 #ifndef MNH_OPENACC
     USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD, COPY_CRSPD_TRANS
 #else
-    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS_DEVICE
+    USE MODE_EXCHANGE_ll, ONLY : SEND_RECV_FIELD_DEVICE, COPY_CRSPD_TRANS
 #endif
     USE MODD_VAR_ll     , ONLY : TCRRT_COMDATA
     USE MODD_CONFZ      , ONLY : NZ_SPLITTING ! for debug IZ=1=flat_inv;  IZ=2=flat_invz ;  IZ=1+2=the two
@@ -1702,15 +1672,9 @@ CONTAINS
     !*       2.     UPDATE THE ZONES THE PROCESSOR SENDS OR RECEIVED FROM ITSELF
     !               ------------------------------------------------------------
     !
-#ifndef MNH_OPENACC
     CALL COPY_CRSPD_TRANS(TCRRT_COMDATA%TRECV_SXP2_Y_ZP1_SXP2_YP1_Z, &
          TCRRT_COMDATA%TSEND_SXP2_Y_ZP1_SXP2_YP1_Z, &
          PFIELDIN, PFIELDOUT, KINFO)
-#else
-    CALL COPY_CRSPD_TRANS_DEVICE(TCRRT_COMDATA%TRECV_SXP2_Y_ZP1_SXP2_YP1_Z, &
-         TCRRT_COMDATA%TSEND_SXP2_Y_ZP1_SXP2_YP1_Z, &
-         PFIELDIN, PFIELDOUT, KINFO)
-#endif
     ELSE
 #ifndef MNH_OPENACC
     CALL ALL_SEND_RECV(TCRRT_COMDATA%TRECV_BOX_SXP2_Y_ZP1_SXP2_YP1_Z, &
-- 
GitLab