Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/DYN/dynspg_ts.F90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/DYN/dynspg_ts.F90	(revision 14899)
@@ -522,10 +522,15 @@
          !--        ssh    =  ssh   - delta_t' * [ frc + div( flux      ) ]      --!
          !-------------------------------------------------------------------------!
-         DO_2D( 0, 0, 0, 0 )
-            zhdiv = (   zhU(ji,jj) - zhU(ji-1,jj) + zhV(ji,jj) - zhV(ji,jj-1)   ) * r1_e1e2t(ji,jj)
-            ssha_e(ji,jj) = (  sshn_e(ji,jj) - rDt_e * ( zssh_frc(ji,jj) + zhdiv )  ) * ssmask(ji,jj)
-         END_2D
-         !
-         CALL lbc_lnk( 'dynspg_ts', ssha_e, 'T', 1._wp,  zhU, 'U', -1._wp,  zhV, 'V', -1._wp )
+
+         !
+         IF( ln_async )  THEN
+            CALL lbc_lnk( 'dynspg_ts', ssha_e, 'T', 1._wp,  zhU, 'U', -1._wp,  zhV, 'V', -1._wp, loop_fct=loop_fct1 )
+         ELSE
+            DO_2D( 0, 0, 0, 0 )
+                zhdiv = (   zhU(ji,jj) - zhU(ji-1,jj) + zhV(ji,jj) - zhV(ji,jj-1)   ) * r1_e1e2t(ji,jj)
+                ssha_e(ji,jj) = (  sshn_e(ji,jj) - rDt_e * ( zssh_frc(ji,jj) + zhdiv )  ) * ssmask(ji,jj)
+            END_2D
+            CALL lbc_lnk( 'dynspg_ts', ssha_e, 'T', 1._wp,  zhU, 'U', -1._wp,  zhV, 'V', -1._wp )
+         END IF
          !
          ! Duplicate sea level across open boundaries (this is only cosmetic if linssh=T)
@@ -836,7 +841,17 @@
       CALL iom_put( "baro_v" , pvv_b(:,:,Kmm) )  ! Barotropic  V Velocity
       !
+    CONTAINS
+      subroutine loop_fct1(i0, i1, j0, j1, k0, k1, buf)
+        integer, intent(in) :: i0, i1, j0, j1, k0, k1
+        REAL*8, dimension(:,:,:,:,:,:), optional, intent(out) :: buf
+        DO_2D( 0, 0, 0, 0 )
+            zhdiv = (   zhU(ji,jj) - zhU(ji-1,jj) + zhV(ji,jj) - zhV(ji,jj-1)   ) * r1_e1e2t(ji,jj)
+            ssha_e(ji,jj) = (  sshn_e(ji,jj) - rDt_e * ( zssh_frc(ji,jj) + zhdiv )  ) * ssmask(ji,jj)
+        END_2D
+      end subroutine loop_fct1
    END SUBROUTINE dyn_spg_ts
 
 
+                
    SUBROUTINE ts_wgt( ll_av, ll_fw, jpit, zwgt1, zwgt2)
       !!---------------------------------------------------------------------
Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_call_generic.h90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_call_generic.h90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_call_generic.h90	(revision 14899)
@@ -43,9 +43,4 @@
       LOGICAL, DIMENSION(4), OPTIONAL        , INTENT(in   ) ::   lsend, lrecv   ! indicate how communications are to be carried out
       LOGICAL              , OPTIONAL        , INTENT(in   ) ::   ld4only     ! if .T., do only 4-neighbour comm (ignore corners)
-      !!
-      INTEGER                          ::   kfld        ! number of elements that will be attributed
-      TYPE(PTR_4d_/**/PRECISION), DIMENSION(16) ::   ptab_ptr    ! pointer array
-      CHARACTER(len=1) , DIMENSION(16) ::   cdna_ptr    ! nature of ptab_ptr grid-points
-      REAL(PRECISION)  , DIMENSION(16) ::   psgn_ptr    ! sign used across the north fold boundary
       interface
         subroutine loop_fct(i0, i1, j0, j1, k0, k1, buf)
@@ -55,4 +50,10 @@
       end interface
       optional :: loop_fct
+      !!
+      INTEGER                          ::   kfld        ! number of elements that will be attributed
+      TYPE(PTR_4d_/**/PRECISION), DIMENSION(16) ::   ptab_ptr    ! pointer array
+      CHARACTER(len=1) , DIMENSION(16) ::   cdna_ptr    ! nature of ptab_ptr grid-points
+      REAL(PRECISION)  , DIMENSION(16) ::   psgn_ptr    ! sign used across the north fold boundary
+
       !!---------------------------------------------------------------------
       !
@@ -83,6 +84,6 @@
          IF( ln_tspers ) THEN
             CALL lbc_lnk_persistent( cdname, ptab_ptr, cdna_ptr, psgn_ptr, kfld, kfillmode, pfillval, khls, lsend, lrecv, ld4only )
-         elseif(present(loop_fct) .and. ln_async)
-            CALL lbc_lnk_pt2pt_async( cdname, loop_fct, ptab_ptr, cdna_ptr, psgn_ptr, kfld, kfillmode, pfillval, khls, lsend, lrecv, ld4only )
+         ELSE IF( PRESENT(loop_fct) .AND. ln_async ) THEN
+            CALL lbc_lnk_async( cdname, ptab_ptr, cdna_ptr, psgn_ptr, kfld, kfillmode, pfillval, khls, lsend, lrecv, ld4only, loop_fct )
          ELSE
             SELECT CASE (nn_comm)
@@ -97,6 +98,6 @@
             END SELECT
          END IF
-      elseif(present(loop_fct) .and. ln_async)
-         CALL lbc_lnk_pt2pt_async( cdname, loop_fct, ptab_ptr, cdna_ptr, psgn_ptr, kfld, kfillmode, pfillval, khls, lsend, lrecv, ld4only )
+      ELSE IF( PRESENT(loop_fct) .AND. ln_async ) THEN
+         CALL lbc_lnk_async( cdname, ptab_ptr, cdna_ptr, psgn_ptr, kfld, kfillmode, pfillval, khls, lsend, lrecv, ld4only, loop_fct )
       ELSE               ! No persistent call outside time-splitting
          SELECT CASE (nn_comm)
Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_newpt2pt_generic.h90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_newpt2pt_generic.h90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_newpt2pt_generic.h90	(revision 14899)
@@ -144,6 +144,4 @@
       !
       ! Allocate local temporary arrays to be sent/received.
-      iszS = COUNT( llsend )
-      iszR = COUNT( llrecv )
       iszall(:) = isizei(:) * isizej(:) * ipk * ipl * ipf
       ishtS(1) = 0
Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_oldpt2pt_generic.h90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_oldpt2pt_generic.h90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_oldpt2pt_generic.h90	(revision 14899)
@@ -252,8 +252,8 @@
       END DO   ;   END DO   ;   END DO   ;   END DO   ;   END DO
 #if ! defined key_mpi_off
-      IF( ln_timing ) CALL tic_tac(.TRUE.)
+      !IF( ln_timing ) CALL tic_tac(.TRUE.)
       ! non-blocking send of the west/east side using local buffer
       CALL MPI_ISEND( BUFFSND(ishtS(jn)+1), iszall(jn), MPI_TYPE, mpiSnei(ihls,jn), iStag(jn), icomm, nreq_p2p(jn), ierr )
-      IF( ln_timing ) CALL tic_tac(.FALSE.)
+      !IF( ln_timing ) CALL tic_tac(.FALSE.)
 #endif
    ENDIF
@@ -267,8 +267,8 @@
    CASE ( jpfillmpi   )                 ! fill with data received by MPI
 #if ! defined key_mpi_off
-      IF( ln_timing ) CALL tic_tac(.TRUE.)
+      !IF( ln_timing ) CALL tic_tac(.TRUE.)
       !                                 ! blocking receive of the west/east halo in local temporary arrays
       CALL MPI_RECV( BUFFRCV(ishtR(jn)+1), iszall(jn), MPI_TYPE, mpiRnei(ihls,jn), iRtag(jn), icomm, MPI_STATUS_IGNORE, ierr )
-      IF( ln_timing ) CALL tic_tac(.FALSE.)
+      !IF( ln_timing ) CALL tic_tac(.FALSE.)
 #endif
       DO jf = 1, ipf  ;  DO jl = 1, ipl  ;  DO jk = 1, ipk  ;  DO jj = 1,isizej(jn)  ;  DO ji = 1,isizei(jn)
Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_pt2pt_async.h90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_pt2pt_async.h90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbc_lnk_pt2pt_async.h90	(revision 14899)
@@ -1,12 +1,7 @@
-! vim: ft=fortran :
+
 #if ! defined BLOCK_ISEND && ! defined BLOCK_IRECV && ! defined BLOCK_FILL
-   SUBROUTINE lbc_lnk_pt2pt_async/**/PRECISION( cdname, loop_fct, ptab, cd_nat, psgn, kfld, kfillmode, pfillval, khls, lsend, lrecv, ld4only )
+   SUBROUTINE lbc_lnk_async_/**/PRECISION( cdname, ptab, cd_nat, psgn, kfld, kfillmode, pfillval, khls, lsend, lrecv, ld4only, loop_fct )
       CHARACTER(len=*)              , INTENT(in   ) ::   cdname      ! name of the calling subroutine
-      interface
-        subroutine loop_fct(i0, i1, j0, j1, k0, k1, buf)
-          integer, intent(in) :: i0, i1, j0, j1, k0, k1
-          REAL*8, dimension(:,:,:,:,:,:), optional, intent(out) :: buf
-        end subroutine loop_fct
-      end interface
+
       TYPE(PTR_4d_/**/PRECISION),  DIMENSION(:), INTENT(inout) ::   ptab        ! pointer of arrays on which apply the b.c.
       CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   cd_nat      ! nature of array grid-points
@@ -18,4 +13,11 @@
       LOGICAL, DIMENSION(4),OPTIONAL, INTENT(in   ) ::   lsend, lrecv  ! communication with other 4 proc
       LOGICAL,              OPTIONAL, INTENT(in   ) ::   ld4only     ! if .T., do only 4-neighbour comm (ignore corners)
+      interface
+         subroutine loop_fct(i0, i1, j0, j1, k0, k1, buf)
+           integer, intent(in) :: i0, i1, j0, j1, k0, k1
+           REAL*8, dimension(:,:,:,:,:,:), optional, intent(out) :: buf
+         end subroutine loop_fct
+      end interface
+      optional :: loop_fct
       !
       INTEGER  ::     ji,   jj,  jk,  jl,  jf, jn     ! dummy loop indices
@@ -56,8 +58,8 @@
       ! take care of optional parameters
       !
-      ihls = nn_hls   ! default definition
+      ihls = nn_hls       ! default definition
       IF( PRESENT( khls ) )   ihls = khls
       IF( ihls > n_hlsmax ) THEN
-         WRITE(ctmp1,*) TRIM(cdname), ' is calling lbc_lnk with khls > n_hlsmax : ', khls, '>', n_hlsmax
+         WRITE(ctmp1,*) TRIM(cdname), '  is calling lbc_lnk with khls > n_hlsmax : ', khls, '>', n_hlsmax
          CALL ctl_stop( 'STOP', ctmp1 )
       ENDIF
@@ -81,5 +83,5 @@
          llsend(1:4) = lsend(1:4)   ;   llrecv(1:4) = lrecv(1:4)
       ELSE IF( PRESENT(lsend) .OR.  PRESENT(lrecv) ) THEN
-         WRITE(ctmp1,*) TRIM(cdname), ' is calling lbc_lnk with only one of the two arguments lsend or lrecv'
+         WRITE(ctmp1,*) TRIM(cdname), '  is calling lbc_lnk with only one of the two arguments lsend or lrecv'
          CALL ctl_stop( 'STOP', ctmp1 )
       ELSE                                              ! default neighbours
@@ -92,5 +94,5 @@
       ! define ifill: which method should be used to fill each parts (sides+corners) of the halos
       ! default definition
-      DO jn = 1, 4
+      DO jn = 1, 8
          IF(             llrecv(jn) ) THEN   ;   ifill(jn) = jpfillmpi    ! with an mpi communication
          ELSEIF(    l_SelfPerio(jn) ) THEN   ;   ifill(jn) = jpfillperio  ! with self-periodicity
@@ -104,5 +106,4 @@
          ENDIF
       END DO
-         !
       ! north fold treatment
       ll_IdoNFold = l_IdoNFold .AND. ifill(jpno) /= jpfillnothing
@@ -111,5 +112,5 @@
          ifill( (/jpno/) ) = jpfillnothing   ! we do north fold -> do nothing for northern halo
       ENDIF
-
+      
       ! We first define the localization and size of the parts of the array that will be sent (s), received (r)
       ! or used for periodocity (p). The localization is defined as "the bottom left corner - 1" in i and j directions.
@@ -129,13 +130,13 @@
       !
       iwewe(:) = (/ jpwe,jpea,jpwe,jpea /)   ;   issnn(:) = (/ jpso,jpso,jpno,jpno /)
-      !cd     sides:     west  east south north      ;   corners: so-we, so-ea, no-we, no-ea
-      isizei(1:4) = (/ ihls, ihls,  ipi,  ipi /)   ;   isizei(5:8) = ihls              ! i- count
-      isizej(1:4) = (/  ipj,  ipj, ihls, ihls /)   ;   isizej(5:8) = ihls              ! j- count
-      ishtSi(1:4) = (/ ip1i, im1i, ip0i, ip0i /)   ;   ishtSi(5:8) = ishtSi( iwewe )   ! i- shift send data
-      ishtSj(1:4) = (/ ip0j, ip0j, ip1j, im1j /)   ;   ishtSj(5:8) = ishtSj( issnn )   ! j- shift send data
-      ishtRi(1:4) = (/ ip0i, im0i, ip0i, ip0i /)   ;   ishtRi(5:8) = ishtRi( iwewe )   ! i- shift received data location
-      ishtRj(1:4) = (/ ip0j, ip0j, ip0j, im0j /)   ;   ishtRj(5:8) = ishtRj( issnn )   ! j- shift received data location
-      ishtPi(1:4) = (/ im1i, ip1i, ip0i, ip0i /)   ;   ishtPi(5:8) = ishtPi( iwewe )   ! i- shift data used for periodicity
-      ishtPj(1:4) = (/ ip0j, ip0j, im1j, ip1j /)   ;   ishtPj(5:8) = ishtPj( issnn )   ! j- shift data used for periodicity
+      !     sides:     west  east south north      ;   corners: so-we, so-ea, no-we, no-ea
+      isizei(1:4) = (/ ihls, ihls, Ni_0, Ni_0 /)   ;   isizei(5:8) = ihls              ! i- count
+      isizej(1:4) = (/ Nj_0, Nj_0, ihls, ihls /)   ;   isizej(5:8) = ihls              ! j- count
+      ishtSi(1:4) = (/ ip1i, im1i, ip1i, ip1i /)   ;   ishtSi(5:8) = ishtSi( iwewe )   ! i- shift send data
+      ishtSj(1:4) = (/ ip1j, ip1j, ip1j, im1j /)   ;   ishtSj(5:8) = ishtSj( issnn )   ! j- shift send data
+      ishtRi(1:4) = (/ ip0i, im0i, ip1i, ip1i /)   ;   ishtRi(5:8) = ishtRi( iwewe )   ! i- shift received data location
+      ishtRj(1:4) = (/ ip1j, ip1j, ip0j, im0j /)   ;   ishtRj(5:8) = ishtRj( issnn )   ! j- shift received data location
+      ishtPi(1:4) = (/ im1i, ip1i, ip1i, ip1i /)   ;   ishtPi(5:8) = ishtPi( iwewe )   ! i- shift data used for periodicity
+      ishtPj(1:4) = (/ ip1j, ip1j, im1j, ip1j /)   ;   ishtPj(5:8) = ishtPj( issnn )   ! j- shift data used for periodicity
       !
       ! -------------------------------- !
@@ -148,4 +149,5 @@
       iRtag(jpsw) = iStag(jpne)   ;   iRtag(jpse) = iStag(jpnw)   ;   iRtag(jpnw) = iStag(jpse)   ;   iRtag(jpne) = iStag(jpsw)
       !
+      ! Allocate local temporary arrays to be sent/received.
       iszall(:) = isizei(:) * isizej(:) * ipk * ipl * ipf
       ishtS(1) = 0
@@ -157,5 +159,5 @@
          ishtR(jn) = ishtR(jn-1) + iszall(jn-1) * COUNT( (/llrecv(jn-1)/) )
       END DO
-
+      
       ! Allocate buffer arrays to be sent/received if needed
       iszS = SUM(iszall, mask = llsend)                             ! send buffer size
@@ -179,5 +181,5 @@
       ! ------------------------------------------------------------- !
       !
-      DO jn = 1, 4 ! TODO maybe to 8 for corners
+      DO jn = 1, 8 ! TODO maybe to 8 for corners
 #define BLOCK_IRECV
 #  include "lbc_lnk_pt2pt_async.h90"
@@ -198,5 +200,5 @@
       ! ------------------------------------------------------------- !
       !
-      DO jn = 1, 4
+      DO jn = 1, 8
 #define BLOCK_ISEND
 #  include "lbc_lnk_pt2pt_async.h90"
@@ -209,5 +211,5 @@
       ! ----------------------------------- !
       !
-      DO jn = 1, 2
+      DO jn = 1, 8
 #define BLOCK_FILL
 #  include "lbc_lnk_pt2pt_async.h90"
@@ -233,9 +235,9 @@
       ! ------------------------------------- !
       !
-      DO jn = 3, 4
-#define BLOCK_FILL
-#  include "lbc_lnk_pt2pt_async.h90"
-#undef BLOCK_FILL
-      END DO
+!       DO jn = 3, 4
+! #define BLOCK_FILL
+! #  include "lbc_lnk_pt2pt_async.h90"
+! #undef BLOCK_FILL
+!       END DO
 !!      !
 !!      ! ----------------------------------------------- !
@@ -266,5 +268,5 @@
       ENDIF
       !
-   END SUBROUTINE lbc_lnk_pt2pt_/**/PRECISION
+   END SUBROUTINE lbc_lnk_async_/**/PRECISION
 #endif
 
@@ -309,5 +311,5 @@
       IF( ln_timing ) CALL tic_tac(.TRUE.)
       !                                 ! waiting receive of the west/east halo in local temporary arrays
-      call MPI_WAIT(iref(jn), MPI_STATUS_IGNORE, ier)
+      call MPI_WAIT(ireq(jn), MPI_STATUS_IGNORE, ierr)
       IF( ln_timing ) CALL tic_tac(.FALSE.)
 #endif
Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbclnk.F90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbclnk.F90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lbclnk.F90	(revision 14899)
@@ -54,4 +54,8 @@
       MODULE PROCEDURE   lbc_lnk_persistent_sp, lbc_lnk_persistent_dp
    END INTERFACE lbc_lnk_persistent
+
+   INTERFACE lbc_lnk_async
+      MODULE PROCEDURE   lbc_lnk_async_sp, lbc_lnk_async_dp
+   END INTERFACE lbc_lnk_async
    !
    INTERFACE lbc_lnk_icb
Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lib_mpp.F90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lib_mpp.F90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/lib_mpp.F90	(revision 14899)
@@ -222,4 +222,5 @@
    LOGICAL                            , PUBLIC :: lints = .FALSE.   ! indicate if currently in time-splitting (for persistent calls)
    LOGICAL                            , PUBLIC :: ln_tspers         ! indicate if persistent call enabled in time-splitting
+   LOGICAL                            , PUBLIC :: ln_async          ! indicate if asynchronous communications enabled
    
    !! * Substitutions
Index: NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/mppini.F90
===================================================================
--- NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/mppini.F90	(revision 14896)
+++ NEMO/branches/2021/dev_r14447_HPC-07_Irrmann_try_new_pt2pt/src/OCE/LBC/mppini.F90	(revision 14899)
@@ -145,5 +145,5 @@
            &             cn_ice, nn_ice_dta,                                     &
            &             ln_vol, nn_volctl, nn_rimwidth
-      NAMELIST/nammpp/ jpni, jpnj, nn_hls, ln_nnogather, ln_listonly, nn_comm, ln_tspers
+      NAMELIST/nammpp/ jpni, jpnj, nn_hls, ln_nnogather, ln_listonly, nn_comm, ln_tspers, ln_async
       !!----------------------------------------------------------------------
       !
