Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdy_oce.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdy_oce.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdy_oce.F90	(revision 11071)
@@ -139,6 +139,10 @@
    TYPE(OBC_DATA) , DIMENSION(jp_bdy), TARGET      ::   dta_bdy           !: bdy external data (local process)
 !$AGRIF_END_DO_NOT_TREAT
-   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lsend_bdy !: mark needed communication for given boundary, grid and direction
-   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lrecv_bdy !: mark needed communication for given boundary, grid and direction
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lsend_bdy      !: mark needed communication for given boundary, grid and neighbour
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lrecv_bdy      !:  when searching in any direction
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lsend_bdyint   !: mark needed communication for given boundary, grid and neighbour
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lrecv_bdyint   !:  when searching towards the interior of the computational domain
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lsend_bdyext   !: mark needed communication for given boundary, grid and neighbour
+   LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) ::   lrecv_bdyext   !:  when searching towards the exterior of the computational domain
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdydyn2d.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdydyn2d.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdydyn2d.F90	(revision 11071)
@@ -51,5 +51,5 @@
       !!
       INTEGER                                  ::   ib_bdy     ! Loop counter
-      LOGICAL, DIMENSION(4) :: lsend2, lrecv2, lsend3, lrecv3  ! indicate how communications are to be carried out
+      LOGICAL, DIMENSION(4) :: llsend2, llrecv2, llsend3, llrecv3  ! indicate how communications are to be carried out
       
       DO ib_bdy=1, nb_bdy
@@ -72,32 +72,31 @@
       ENDDO
       !
-      lsend2(:) = .false.
-      lrecv2(:) = .false.
-      lsend3(:) = .false.
-      lrecv3(:) = .false.
+      llsend2(:) = .false.
+      llrecv2(:) = .false.
+      llsend3(:) = .false.
+      llrecv3(:) = .false.
       DO ib_bdy=1, nb_bdy
          SELECT CASE( cn_dyn2d(ib_bdy) )
          CASE('flather')
-            lsend2(:) = lsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! to   every bdy neighbour, U points
-            lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! from every bdy neighbour, U points
-            lsend3(:) = lsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! to   every bdy neighbour, V points
-            lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! from every bdy neighbour, V points
-         CASE('orlanski')
-            lsend2(:) = lsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! to   every bdy neighbour, U points
-            lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! from every bdy neighbour, U points
-            lsend3(:) = lsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! to   every bdy neighbour, V points
-            lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! from every bdy neighbour, V points
-         CASE('orlanski_npo')
-            lsend2(:) = lsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! to   every bdy neighbour, U points
-            lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! from every bdy neighbour, U points
-            lsend3(:) = lsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! to   every bdy neighbour, V points
-            lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! from every bdy neighbour, V points
+            llsend2(1:2) = llsend2(1:2) .OR. lsend_bdyint(ib_bdy,2,1:2)   ! west/east, U points
+            llsend2(1)   = llsend2(1)   .OR. lsend_bdyext(ib_bdy,2,1)     ! neighbour might search point towards bdy on its east
+            llrecv2(1:2) = llrecv2(1:2) .OR. lrecv_bdyint(ib_bdy,2,1:2)   ! west/east, U points
+            llrecv2(2)   = llrecv2(2)   .OR. lrecv_bdyext(ib_bdy,2,2)     ! might search point towards bdy on the east
+            llsend3(3:4) = llsend3(3:4) .OR. lsend_bdyint(ib_bdy,3,3:4)   ! north/south, V points
+            llsend3(3)   = llsend3(3)   .OR. lsend_bdyext(ib_bdy,3,3)     ! neighbour might search point towards bdy on its north
+            llrecv3(3:4) = llrecv3(3:4) .OR. lrecv_bdyint(ib_bdy,3,3:4)   ! north/south, V points
+            llrecv3(4)   = llrecv3(4)   .OR. lrecv_bdyext(ib_bdy,3,4)     ! might search point towards bdy on the north
+         CASE('orlanski', 'orlanski_npo')
+            llsend2(:) = llsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! possibly every direction, U points
+            llrecv2(:) = llrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! possibly every direction, U points
+            llsend3(:) = llsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! possibly every direction, V points
+            llrecv3(:) = llrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! possibly every direction, V points
          END SELECT
       END DO
-      IF( ANY(lsend2) .OR. ANY(lrecv2) ) THEN   ! if need to send/recv in at least one direction
-         CALL lbc_bdy_lnk( 'bdydyn2d', lsend2, lrecv2, pua2d, 'U', -1. )
+      IF( ANY(llsend2) .OR. ANY(llrecv2) ) THEN   ! if need to send/recv in at least one direction
+         CALL lbc_bdy_lnk( 'bdydyn2d', llsend2, llrecv2, pua2d, 'U', -1. )
       END IF
-      IF( ANY(lsend3) .OR. ANY(lrecv3) ) THEN   ! if need to send/recv in at least one direction
-         CALL lbc_bdy_lnk( 'bdydyn2d', lsend3, lrecv3, pva2d, 'V', -1. )
+      IF( ANY(llsend3) .OR. ANY(llrecv3) ) THEN   ! if need to send/recv in at least one direction
+         CALL lbc_bdy_lnk( 'bdydyn2d', llsend3, llrecv3, pva2d, 'V', -1. )
       END IF
       !
@@ -197,5 +196,4 @@
          ENDIF
       END DO
-
       !
       igrd = 2      ! Flather bc on u-velocity; 
@@ -284,15 +282,15 @@
       !!
       INTEGER  ::   ib_bdy          ! bdy index
-      LOGICAL, DIMENSION(4) :: lsend1, lrecv1  ! indicate how communications are to be carried out
-      !!----------------------------------------------------------------------
-      lsend1(:) = .false.
-      lrecv1(:) = .false.
+      LOGICAL, DIMENSION(4) :: llsend1, llrecv1  ! indicate how communications are to be carried out
+      !!----------------------------------------------------------------------
+      llsend1(:) = .false.
+      llrecv1(:) = .false.
       DO ib_bdy = 1, nb_bdy
          CALL bdy_nmn( idx_bdy(ib_bdy), 1, zssh )   ! zssh is masked
-         lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-         lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
-      END DO
-      IF( ANY(lsend1) .OR. ANY(lrecv1) ) THEN   ! if need to send/recv in at least one direction
-         CALL lbc_bdy_lnk( 'bdydyn2d', lsend1, lrecv1, zssh(:,:,1), 'T',  1. )
+         llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:)   ! possibly every direction, T points
+         llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:)   ! possibly every direction, T points
+      END DO
+      IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+         CALL lbc_bdy_lnk( 'bdydyn2d', llsend1, llrecv1, zssh(:,:,1), 'T',  1. )
       END IF
       !
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdydyn3d.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdydyn3d.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdydyn3d.F90	(revision 11071)
@@ -43,5 +43,5 @@
       !
       INTEGER ::   ib_bdy   ! loop index
-      LOGICAL, DIMENSION(4) :: lsend2, lrecv2, lsend3, lrecv3  ! indicate how communications are to be carried out
+      LOGICAL, DIMENSION(4) :: llsend2, llrecv2, llsend3, llrecv3  ! indicate how communications are to be carried out
 
       !!----------------------------------------------------------------------
@@ -61,38 +61,33 @@
       END DO
       !
-      lsend2(:) = .false.
-      lrecv2(:) = .false.
-      lsend3(:) = .false.
-      lrecv3(:) = .false.
+      llsend2(:) = .false.
+      llrecv2(:) = .false.
+      llsend3(:) = .false.
+      llrecv3(:) = .false.
       DO ib_bdy=1, nb_bdy
          SELECT CASE( cn_dyn3d(ib_bdy) )
-         CASE('orlanski')
-            lsend2(:) = lsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! to   every bdy neighbour, U points
-            lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! from every bdy neighbour, U points
-            lsend3(:) = lsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! to   every bdy neighbour, V points
-            lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! from every bdy neighbour, V points
-         CASE('orlanski_npo')
-            lsend2(:) = lsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! to   every bdy neighbour, U points
-            lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! from every bdy neighbour, U points
-            lsend3(:) = lsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! to   every bdy neighbour, V points
-            lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! from every bdy neighbour, V points
+         CASE('orlanski', 'orlanski_npo')
+            llsend2(:) = llsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! possibly every direction, U points
+            llrecv2(:) = llrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! possibly every direction, U points
+            llsend3(:) = llsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! possibly every direction, V points
+            llrecv3(:) = llrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! possibly every direction, V points
          CASE('zerograd')
-            lsend2(:) = lsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! to   every bdy neighbour, U points
-            lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! from every bdy neighbour, U points
-            lsend3(:) = lsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! to   every bdy neighbour, V points
-            lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! from every bdy neighbour, V points
+            llsend2(3:4) = llsend2(3:4) .OR. lsend_bdyint(ib_bdy,2,3:4)   ! north/south, U points
+            llrecv2(3:4) = llrecv2(3:4) .OR. lrecv_bdyint(ib_bdy,2,3:4)   ! north/south, U points
+            llsend3(1:2) = llsend3(1:2) .OR. lsend_bdyint(ib_bdy,3,1:2)   ! west/east, V points
+            llrecv3(1:2) = llrecv3(1:2) .OR. lrecv_bdyint(ib_bdy,3,1:2)   ! west/east, V points
          CASE('neumann')
-            lsend2(:) = lsend2(:) .OR. lsend_bdy(ib_bdy,2,:)   ! to   every bdy neighbour, U points
-            lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(ib_bdy,2,:)   ! from every bdy neighbour, U points
-            lsend3(:) = lsend3(:) .OR. lsend_bdy(ib_bdy,3,:)   ! to   every bdy neighbour, V points
-            lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(ib_bdy,3,:)   ! from every bdy neighbour, V points
+            llsend2(:) = llsend2(:) .OR. lsend_bdyint(ib_bdy,2,:)   ! possibly every direction, U points
+            llrecv2(:) = llrecv2(:) .OR. lrecv_bdyint(ib_bdy,2,:)   ! possibly every direction, U points
+            llsend3(:) = llsend3(:) .OR. lsend_bdyint(ib_bdy,3,:)   ! possibly every direction, V points
+            llrecv3(:) = llrecv3(:) .OR. lrecv_bdyint(ib_bdy,3,:)   ! possibly every direction, V points
          END SELECT
       END DO
       !
-      IF( ANY(lsend2) .OR. ANY(lrecv2) ) THEN   ! if need to send/recv in at least one direction
-         CALL lbc_bdy_lnk( 'bdydyn2d', lsend2, lrecv2, ua, 'U', -1. )
+      IF( ANY(llsend2) .OR. ANY(llrecv2) ) THEN   ! if need to send/recv in at least one direction
+         CALL lbc_bdy_lnk( 'bdydyn2d', llsend2, llrecv2, ua, 'U', -1. )
       END IF
-      IF( ANY(lsend3) .OR. ANY(lrecv3) ) THEN   ! if need to send/recv in at least one direction
-         CALL lbc_bdy_lnk( 'bdydyn2d', lsend3, lrecv3, va, 'V', -1. )
+      IF( ANY(llsend3) .OR. ANY(llrecv3) ) THEN   ! if need to send/recv in at least one direction
+         CALL lbc_bdy_lnk( 'bdydyn2d', llsend3, llrecv3, va, 'V', -1. )
       END IF
       !
@@ -363,7 +358,5 @@
       TYPE(OBC_INDEX),              INTENT(in) ::   idx  ! OBC indices
       INTEGER,                      INTENT(in) ::   ib_bdy  ! BDY set index
-
-      INTEGER  ::   jb, igrd                               ! dummy loop indices
-      LOGICAL, DIMENSION(4) :: lsend2, lrecv2, lsend3, lrecv3  ! indicate how communications are to be carried out
+      INTEGER  ::   igrd                                    ! dummy indice
       !!----------------------------------------------------------------------
       !
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdyice.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdyice.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdyice.F90	(revision 11071)
@@ -56,5 +56,5 @@
       !
       INTEGER ::   jbdy                               ! BDY set index
-      LOGICAL, DIMENSION(4)       :: lsend1, lrecv1   ! indicate how communications are to be carried out
+      LOGICAL, DIMENSION(4)       :: llsend1, llrecv1   ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       ! controls
@@ -76,21 +76,21 @@
       !
       ! Update bdy points
-      lsend1(:) = .false.
-      lrecv1(:) = .false.
+      llsend1(:) = .false.
+      llrecv1(:) = .false.
       DO jbdy = 1, nb_bdy
          IF( cn_ice(jbdy) == 'frs' ) THEN
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(jbdy,1,:)   ! to   every neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(jbdy,1,:)   ! from every neighbour, T points
+            llsend1(:) = llsend1(:) .OR. lsend_bdyint(jbdy,1,:)   ! possibly every direction, T points
+            llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(jbdy,1,:)   ! possibly every direction, T points
          END IF
       END DO
-      IF( ANY(lsend1) .OR. ANY(lrecv1) ) THEN   ! if need to send/recv in at least one direction
+      IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
          ! exchange 3d arrays
-         CALL lbc_bdy_lnk_multi( 'bdyice', lsend1, lrecv1, a_i , 'T', 1., h_i , 'T', 1., h_s , 'T', 1. &
-              &                                          , oa_i, 'T', 1., a_ip, 'T', 1., v_ip, 'T', 1. &
-              &                                          , s_i , 'T', 1., t_su, 'T', 1., v_i , 'T', 1. &
-              &                                          , v_s , 'T', 1., sv_i, 'T', 1.                )
+         CALL lbc_bdy_lnk_multi( 'bdyice', llsend1, llrecv1, a_i , 'T', 1., h_i , 'T', 1., h_s , 'T', 1. &
+              &                                            , oa_i, 'T', 1., a_ip, 'T', 1., v_ip, 'T', 1. &
+              &                                            , s_i , 'T', 1., t_su, 'T', 1., v_i , 'T', 1. &
+              &                                            , v_s , 'T', 1., sv_i, 'T', 1.                )
          ! exchange 4d arrays
-         CALL lbc_bdy_lnk_multi( 'bdyice', lsend1, lrecv1, t_s , 'T', 1., e_s , 'T', 1. )   ! third dimension = 1
-         CALL lbc_bdy_lnk_multi( 'bdyice', lsend1, lrecv1, t_i , 'T', 1., e_i , 'T', 1. )   ! third dimension = 2
+         CALL lbc_bdy_lnk_multi( 'bdyice', llsend1, llrecv1, t_s , 'T', 1., e_s , 'T', 1. )   ! third dimension = 1
+         CALL lbc_bdy_lnk_multi( 'bdyice', llsend1, llrecv1, t_i , 'T', 1., e_i , 'T', 1. )   ! third dimension = jpk
       END IF
       !
@@ -172,13 +172,13 @@
             !
             IF( flagu ==  1. )   THEN
-               IF( ji+1 > jpi  )   CYCLE
+               IF( ji+1 > jpi )   CYCLE
                IF( u_ice(ji  ,jj  ) < 0. )   jpbound = 1 ; ib = ji+1
             END IF
             IF( flagu == -1. )   THEN
-               IF( ji-1 < 1    )   CYCLE
+               IF( ji-1 < 1   )   CYCLE
                IF( u_ice(ji-1,jj  ) < 0. )   jpbound = 1 ; ib = ji-1
             END IF
             IF( flagv ==  1. )   THEN
-               IF( ji+1 > jpj )   CYCLE
+               IF( jj+1 > jpj )   CYCLE
                IF( v_ice(ji  ,jj  ) < 0. )   jpbound = 1 ; jb = jj+1
             END IF
@@ -299,5 +299,5 @@
       INTEGER  ::   jbdy             ! BDY set index
       REAL(wp) ::   zmsk1, zmsk2, zflag
-      LOGICAL, DIMENSION(4) :: lsend2, lrecv2, lsend3, lrecv3  ! indicate how communications are to be carried out
+      LOGICAL, DIMENSION(4) :: llsend2, llrecv2, llsend3, llrecv3  ! indicate how communications are to be carried out
       !!------------------------------------------------------------------------------
       IF( ln_timing )   CALL timing_start('bdy_ice_dyn')
@@ -384,24 +384,28 @@
       SELECT CASE ( cd_type )        
       CASE ( 'U' ) 
-         lsend2(:) = .false.   ;   lrecv2(:) = .false.
+         llsend2(:) = .false.   ;   llrecv2(:) = .false.
          DO jbdy = 1, nb_bdy
             IF( cn_ice(jbdy) == 'frs' .AND. nn_ice_dta(jbdy) /= 0 ) THEN
-               lsend2(:) = lsend2(:) .OR. lsend_bdy(jbdy,2,:)   ! to   every bdy neighbour, U points
-               lrecv2(:) = lrecv2(:) .OR. lrecv_bdy(jbdy,2,:)   ! from every bdy neighbour, U points
+               llsend2(:) = llsend2(:) .OR. lsend_bdyint(jbdy,2,:)   ! possibly every direction, U points
+               llsend2(1) = llsend2(1) .OR. lsend_bdyext(jbdy,2,1)   ! neighbour might search point towards bdy on its east
+               llrecv2(:) = llrecv2(:) .OR. lrecv_bdyint(jbdy,2,:)   ! possibly every direction, U points
+               llrecv2(2) = llrecv2(2) .OR. lrecv_bdyext(jbdy,2,2)   ! might search point towards bdy on the east
             END IF
          END DO
-         IF( ANY(lsend2) .OR. ANY(lrecv2) ) THEN   ! if need to send/recv in at least one direction
-            CALL lbc_bdy_lnk( 'bdyice', lsend2, lrecv2, u_ice, 'U', -1. )
+         IF( ANY(llsend2) .OR. ANY(llrecv2) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_bdy_lnk( 'bdyice', llsend2, llrecv2, u_ice, 'U', -1. )
          END IF
       CASE ( 'V' )
-         lsend3(:) = .false.   ;   lrecv3(:) = .false.
+         llsend3(:) = .false.   ;   llrecv3(:) = .false.
          DO jbdy = 1, nb_bdy
             IF( cn_ice(jbdy) == 'frs' .AND. nn_ice_dta(jbdy) /= 0 ) THEN
-               lsend3(:) = lsend3(:) .OR. lsend_bdy(jbdy,3,:)   ! to   every bdy neighbour, V points
-               lrecv3(:) = lrecv3(:) .OR. lrecv_bdy(jbdy,3,:)   ! from every bdy neighbour, V points
+               llsend3(:) = llsend3(:) .OR. lsend_bdyint(jbdy,3,:)   ! possibly every direction, V points
+               llsend3(3) = llsend3(3) .OR. lsend_bdyext(jbdy,3,3)   ! neighbour might search point towards bdy on its north
+               llrecv3(:) = llrecv3(:) .OR. lrecv_bdyint(jbdy,3,:)   ! possibly every direction, V points
+               llrecv3(4) = llrecv3(4) .OR. lrecv_bdyext(jbdy,3,4)   ! might search point towards bdy on the north
             END IF
          END DO
-         IF( ANY(lsend3) .OR. ANY(lrecv3) ) THEN   ! if need to send/recv in at least one direction
-            CALL lbc_bdy_lnk( 'bdyice', lsend3, lrecv3, v_ice, 'V', -1. )
+         IF( ANY(llsend3) .OR. ANY(llrecv3) ) THEN   ! if need to send/recv in at least one direction
+            CALL lbc_bdy_lnk( 'bdyice', llsend3, llrecv3, v_ice, 'V', -1. )
          END IF
       END SELECT
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdyini.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdyini.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdyini.F90	(revision 11071)
@@ -132,4 +132,6 @@
       INTEGER  ::   ib_bdy1, ib_bdy2, ib1, ib2             !   -       -
       INTEGER  ::   i_offset, j_offset, inbdy, itreat      !   -       -
+      INTEGER  ::   ii1, ii2, ii3, ij1, ij2, ij3, iibe, ijbe   !   -       -
+      INTEGER  ::   flagu, flagv                               ! short cuts
       INTEGER , POINTER  ::  nbi, nbj, nbr                 ! short cuts
       REAL(wp), POINTER, DIMENSION(:,:)       ::   pmask    ! pointer to 2D mask fields
@@ -145,5 +147,4 @@
       REAL(wp), TARGET, DIMENSION(jpi,jpj) ::   zfmask  ! temporary fmask array excluding coastal boundary condition (shlat)
       REAL(wp)        , DIMENSION(jpi,jpj) ::   ztmp
-      REAL(wp), POINTER                    :: flagu,     flagv     ! short cuts
       LOGICAL  ::   llnobdy, llsobdy, lleabdy, llwebdy     ! local logicals
       !!
@@ -867,27 +868,9 @@
       ! Initialize array indicating communications in bdy
       ! -------------------------------------------------
-
-      ! Allocate array indicating if a send    instruction is needed in bdy treatment
-      ALLOCATE( nbondi_bdy(nb_bdy) )
-      ALLOCATE( nbondj_bdy(nb_bdy) )
-      nbondi_bdy(:)=2
-      nbondj_bdy(:)=2
-      ! Allocate array indicating if a receive instruction is needed in bdy treatment
-      ALLOCATE( nbondi_bdy_b(nb_bdy))
-      ALLOCATE( nbondj_bdy_b(nb_bdy))
-      nbondi_bdy_b(:)=2
-      nbondj_bdy_b(:)=2
+      ALLOCATE( lsend_bdy(nb_bdy,jpbgrd,4), lrecv_bdy(nb_bdy,jpbgrd,4) )
+      lsend_bdy(:,:,:) = .false.
+      lrecv_bdy(:,:,:) = .false. 
 
       DO ib_bdy = 1, nb_bdy
-         ! default : no send
-         llsend_ea = .false.   
-         llsend_we = .false.
-         llsend_so = .false.
-         llsend_no = .false.
-         ! default : no receive
-         llrecv_ea = .false.
-         llrecv_we = .false.
-         llrecv_so = .false.
-         llrecv_no = .false.
          DO igrd = 1, jpbgrd
             DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)   ! only the rim triggers communications, see bdy routines
@@ -896,45 +879,25 @@
                !
                ! check if point has to be sent     to   a neighbour
+               ! W neighbour and on the inner left  side
+               IF( ii == 2     .and. (nbondi == 0 .or. nbondi ==  1) )   lsend_bdy(ib_bdy,igrd,1) = .true.
                ! E neighbour and on the inner right side
-               IF( ii == nlci-1 .and. (nbondi == 0 .or. nbondi == -1) )   llsend_ea = .true.
-               ! W neighbour and on the inner left  side
-               IF( ii == 2      .and. (nbondi == 0 .or. nbondi ==  1) )   llsend_we = .true.
+               IF( ii == jpi-1 .and. (nbondi == 0 .or. nbondi == -1) )   lsend_bdy(ib_bdy,igrd,2) = .true.
+               ! S neighbour and on the inner down side
+               IF( ij == 2     .and. (nbondj == 0 .or. nbondj ==  1) )   lsend_bdy(ib_bdy,igrd,3) = .true.
                ! N neighbour and on the inner up   side
-               IF( ij == nlcj-1 .and. (nbondj == 0 .or. nbondj == -1) )   llsend_no = .true.
-               ! S neighbour and on the inner down side
-               IF( ij == 2      .and. (nbondj == 0 .or. nbondj ==  1) )   llsend_so = .true.
+               IF( ij == jpj-1 .and. (nbondj == 0 .or. nbondj == -1) )   lsend_bdy(ib_bdy,igrd,4) = .true.
                !
                ! check if point has to be received from a neighbour
+               ! W neighbour and on the outter left  side
+               IF( ii == 1   .and. (nbondi == 0 .or. nbondi ==  1) )    lrecv_bdy(ib_bdy,igrd,1) = .true.
                ! E neighbour and on the outter right side
-               IF( ii == nlci .and. (nbondi == 0 .or. nbondi == -1) )   llrecv_ea = .true.
-               ! W neighbour and on the outter left  side
-               IF( ii == 1    .and. (nbondi == 0 .or. nbondi ==  1) )   llrecv_we = .true.
+               IF( ii == jpi .and. (nbondi == 0 .or. nbondi == -1) )    lrecv_bdy(ib_bdy,igrd,2) = .true.
+               ! S neighbour and on the outter down side
+               IF( ij == 1   .and. (nbondj == 0 .or. nbondj ==  1) )    lrecv_bdy(ib_bdy,igrd,3) = .true.
                ! N neighbour and on the outter up   side
-               IF( ij == nlcj .and. (nbondj == 0 .or. nbondj == -1) )   llrecv_no = .true.
-               ! S neighbour and on the outter down side
-               IF( ij == 1    .and. (nbondj == 0 .or. nbondj ==  1) )   llrecv_so = .true.
+               IF( ij == jpj .and. (nbondj == 0 .or. nbondj == -1) )    lrecv_bdy(ib_bdy,igrd,4) = .true.
                !
             END DO
          END DO  ! igrd
-
-         ! definition of the i- and j- direction local boundaries arrays used for sending the boundaries
-         IF(           llsend_ea .and.       llsend_we ) THEN   ;   nbondi_bdy(ib_bdy) =  0
-         ELSEIF(       llsend_ea .and. .not. llsend_we ) THEN   ;   nbondi_bdy(ib_bdy) = -1
-         ELSEIF( .not. llsend_ea .and.       llsend_we ) THEN   ;   nbondi_bdy(ib_bdy) =  1
-         ENDIF
-         IF(           llsend_no .and.       llsend_so ) THEN   ;   nbondj_bdy(ib_bdy) =  0
-         ELSEIF(       llsend_no .and. .not. llsend_so ) THEN   ;   nbondj_bdy(ib_bdy) = -1
-         ELSEIF( .not. llsend_no .and.       llsend_so ) THEN   ;   nbondj_bdy(ib_bdy) =  1
-         ENDIF
-
-         ! definition of the i- and j- direction local boundaries arrays used for receiving the boundaries
-         IF(           llrecv_ea .and.       llrecv_we ) THEN   ;   nbondi_bdy_b(ib_bdy) =  0
-         ELSEIF(       llrecv_ea .and. .not. llrecv_we ) THEN   ;   nbondi_bdy_b(ib_bdy) = -1
-         ELSEIF( .not. llrecv_ea .and.       llrecv_we ) THEN   ;   nbondi_bdy_b(ib_bdy) =  1
-         ENDIF
-         IF(           llrecv_no .and.       llrecv_so ) THEN   ;   nbondj_bdy_b(ib_bdy) =  0
-         ELSEIF(       llrecv_no .and. .not. llrecv_so ) THEN   ;   nbondj_bdy_b(ib_bdy) = -1
-         ELSEIF( .not. llrecv_no .and.       llrecv_so ) THEN   ;   nbondj_bdy_b(ib_bdy) =  1
-         ENDIF
 
          ! Compute rim weights for FRS scheme
@@ -1134,11 +1097,11 @@
                   !  1 |   o      !  2  o   |    !  3 | x        !  4     x |    
                   !    |_x_ _     !    _ _x_|    !    |   o      !      o   |
-                  IF( pmask(ii+1,ij+1) == 1. )   ztmp(ii,ij) = 1
-                  IF( pmask(ii-1,ij+1) == 1. )   ztmp(ii,ij) = 2
-                  IF( pmask(ii+1,ij-1) == 1. )   ztmp(ii,ij) = 3
-                  IF( pmask(ii-1,ij-1) == 1. )   ztmp(ii,ij) = 4
+                  IF( pmask(ii+1,ij+1) == 1. )   ztmp(ii,ij) = 1.
+                  IF( pmask(ii-1,ij+1) == 1. )   ztmp(ii,ij) = 2.
+                  IF( pmask(ii+1,ij-1) == 1. )   ztmp(ii,ij) = 3.
+                  IF( pmask(ii-1,ij-1) == 1. )   ztmp(ii,ij) = 4.
                END IF
                IF( inbdy == 1 )   THEN   ! middle of linear bdy
-                  ztmp(ii,ij) = 0   ! regular treatment with flags
+                  ztmp(ii,ij) = 0.   ! regular treatment with flags
                END IF
                IF( inbdy == 2 )   THEN   ! exterior of a corner
@@ -1146,8 +1109,8 @@
                   !  5 ____x o    !  6   o x___   ! 7      x o      !  8   o x      
                   !         |     !       |       !        o        !        o 
-                  IF( llnobdy .AND. lleabdy )   ztmp(ii,ij) = 5
-                  IF( llnobdy .AND. llwebdy )   ztmp(ii,ij) = 6
-                  IF( llsobdy .AND. lleabdy )   ztmp(ii,ij) = 7
-                  IF( llsobdy .AND. llwebdy )   ztmp(ii,ij) = 8
+                  IF( llnobdy .AND. lleabdy )   ztmp(ii,ij) = 5.
+                  IF( llnobdy .AND. llwebdy )   ztmp(ii,ij) = 6.
+                  IF( llsobdy .AND. lleabdy )   ztmp(ii,ij) = 7.
+                  IF( llsobdy .AND. llwebdy )   ztmp(ii,ij) = 8.
                END IF
                IF( inbdy == 3 )   THEN   ! 3 neighbours __   __
@@ -1155,8 +1118,8 @@
                   !  9  _| x o    ! 10   o x |_   ! 11   o x o    ! 12  o x o       
                   !    |   o      !        o   |  !        o      !    __|¨|__    
-                  IF( llnobdy .AND. lleabdy .AND. llsobdy )   ztmp(ii,ij) = 9
-                  IF( llnobdy .AND. llwebdy .AND. llsobdy )   ztmp(ii,ij) = 10
-                  IF( llwebdy .AND. llsobdy .AND. lleabdy )   ztmp(ii,ij) = 11
-                  IF( llwebdy .AND. llnobdy .AND. lleabdy )   ztmp(ii,ij) = 12
+                  IF( llnobdy .AND. lleabdy .AND. llsobdy )   ztmp(ii,ij) = 9.
+                  IF( llnobdy .AND. llwebdy .AND. llsobdy )   ztmp(ii,ij) = 10.
+                  IF( llwebdy .AND. llsobdy .AND. lleabdy )   ztmp(ii,ij) = 11.
+                  IF( llwebdy .AND. llnobdy .AND. lleabdy )   ztmp(ii,ij) = 12.
                END IF
                IF( inbdy == 4 )   THEN
@@ -1171,5 +1134,5 @@
                ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
                ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
-               idx_bdy(ib_bdy)%ntreat(ib,igrd) = ztmp(ii,ij)
+               idx_bdy(ib_bdy)%ntreat(ib,igrd) = NINT(ztmp(ii,ij))
             END DO
          END DO
@@ -1177,45 +1140,99 @@
 
 
-      ALLOCATE( lsend_bdy(nb_bdy,jpbgrd,4), lrecv_bdy(nb_bdy,jpbgrd,4) )
-      lsend_bdy(:,:,:) = .false.
-      lrecv_bdy(:,:,:) = .false. 
+      ALLOCATE( lsend_bdyint(nb_bdy,jpbgrd,4), lrecv_bdyint(nb_bdy,jpbgrd,4) )
+      lsend_bdyint(:,:,:) = .false.
+      lrecv_bdyint(:,:,:) = .false. 
+      ALLOCATE( lsend_bdyext(nb_bdy,jpbgrd,4), lrecv_bdyext(nb_bdy,jpbgrd,4) )
+      lsend_bdyext(:,:,:) = .false.
+      lrecv_bdyext(:,:,:) = .false.
       !
       ! Check which boundaries might need communication
       DO igrd = 1, jpbgrd
          DO ib_bdy = 1, nb_bdy
-            IF     ( nbondi_bdy  (ib_bdy) ==  0 )   THEN 
-               lsend_bdy(ib_bdy,igrd,1) = .true.
-               lsend_bdy(ib_bdy,igrd,2) = .true.
-            ELSE IF( nbondi_bdy  (ib_bdy) ==  1 )   THEN
-               lsend_bdy(ib_bdy,igrd,1) = .true.
-            ELSE IF( nbondi_bdy  (ib_bdy) == -1 )   THEN
-               lsend_bdy(ib_bdy,igrd,2) = .true.
-            END IF
-            IF     ( nbondi_bdy_b(ib_bdy) ==  0 )   THEN 
-               lrecv_bdy(ib_bdy,igrd,1) = .true.
-               lrecv_bdy(ib_bdy,igrd,2) = .true.
-            ELSE IF( nbondi_bdy_b(ib_bdy) ==  1 )   THEN
-               lrecv_bdy(ib_bdy,igrd,1) = .true.
-            ELSE IF( nbondi_bdy_b(ib_bdy) == -1 )   THEN
-               lrecv_bdy(ib_bdy,igrd,2) = .true.
-            END IF
-            IF(      nbondj_bdy  (ib_bdy) ==  0 )   THEN 
-               lsend_bdy(ib_bdy,igrd,3) = .true.
-               lsend_bdy(ib_bdy,igrd,4) = .true.
-            ELSE IF( nbondj_bdy  (ib_bdy) ==  1 )   THEN
-               lsend_bdy(ib_bdy,igrd,3) = .true.
-            ELSE IF( nbondj_bdy  (ib_bdy) == -1 )   THEN
-               lsend_bdy(ib_bdy,igrd,4) = .true.
-            END IF
-            IF(      nbondj_bdy_b(ib_bdy) ==  0 )   THEN 
-               lrecv_bdy(ib_bdy,igrd,3) = .true.
-               lrecv_bdy(ib_bdy,igrd,4) = .true.
-            ELSE IF( nbondj_bdy_b(ib_bdy) ==  1 )   THEN
-               lrecv_bdy(ib_bdy,igrd,3) = .true.
-            ELSE IF( nbondj_bdy_b(ib_bdy) == -1 )   THEN
-               lrecv_bdy(ib_bdy,igrd,4) = .true.
-            END IF
+            DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
+               ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+               ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+               flagu = NINT(idx_bdy(ib_bdy)%flagu(ib,igrd))
+               flagv = NINT(idx_bdy(ib_bdy)%flagv(ib,igrd))
+               iibe = ii - flagu   ! neighbouring point towards the exterior of the computational domain
+               ijbe = ij - flagv   ! neighbouring point towards the exterior of the computational domain
+               SELECT CASE( idx_bdy(ib_bdy)%ntreat(ib,igrd) )   ! points that will be used by bdy routines, -1 will be discarded
+               CASE( 0 )    ;   ii1 = ii + flagu   ;   ii2 = -1   ;   ii3 = -1
+                                ij1 = ij + flagv   ;   ij2 = -1   ;   ij3 = -1
+               CASE( 1  )   ;   ii1 = ii+1   ;   ij1 = ij+1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+               CASE( 2  )   ;   ii1 = ii-1   ;   ij1 = ij+1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+               CASE( 3  )   ;   ii1 = ii+1   ;   ij1 = ij-1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+               CASE( 4  )   ;   ii1 = ii-1   ;   ij1 = ij-1   ;   ii2 = -1     ;   ij2 = -1     ;   ii3 = -1     ;   ij3 = -1
+               CASE( 5  )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii+1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1
+               CASE( 6  )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii-1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1
+               CASE( 7  )   ;   ii1 = ii     ;   ij1 = ij-1   ;   ii2 = ii+1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1 
+               CASE( 8  )   ;   ii1 = ii     ;   ij1 = ij-1   ;   ii2 = ii-1   ;   ij2 = ij     ;   ii3 = -1     ;   ij3 = -1
+               CASE( 9  )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii+1   ;   ij2 = ij     ;   ii3 = ii     ;   ij3 = ij-1   
+               CASE( 10 )   ;   ii1 = ii     ;   ij1 = ij+1   ;   ii2 = ii-1   ;   ij2 = ij     ;   ii3 = ii     ;   ij3 = ij-1 
+               CASE( 11 )   ;   ii1 = ii-1   ;   ij1 = ij     ;   ii2 = ii     ;   ij2 = ij-1   ;   ii3 = ii+1   ;   ij3 = ij   
+               CASE( 12 )   ;   ii1 = ii-1   ;   ij1 = ij     ;   ii2 = ii     ;   ij2 = ij+1   ;   ii3 = ii+1   ;   ij3 = ij
+               END SELECT
+               !
+               ! search neighbour in the  west/east  direction
+               ! Rim is on the halo and computed ocean is towards exterior of mpi domain  
+               !      <--    (o exterior)     -->  
+               ! (1)  o|x         OR    (2)   x|o
+               !       |___                 ___| 
+               IF( ii1 == 0     .OR. ii2 == 0     .OR. ii3 == 0     )   lrecv_bdyint(ib_bdy,igrd,1) = .true.
+               IF( ii1 == jpi+1 .OR. ii2 == jpi+1 .OR. ii3 == jpi+1 )   lrecv_bdyint(ib_bdy,igrd,2) = .true.  
+               IF( iibe == 0     )   lrecv_bdyext(ib_bdy,igrd,1) = .true.
+               IF( iibe == jpi+1 )   lrecv_bdyext(ib_bdy,igrd,2) = .true.  
+               ! Check if neighbour has its rim parallel to its mpi subdomain border and located next to its halo
+               ! :¨¨¨¨¨|¨¨-->    |                                             |    <--¨¨|¨¨¨¨¨: 
+               ! :     |  x:o    |    neighbour limited by ... would need o    |    o:x  |     :
+               ! :.....|_._:_____|   (1) W neighbour         E neighbour (2)   |_____:_._|.....:
+               IF( ii == 2     .AND. ( nbondi ==  1 .OR. nbondi == 0 ) &
+                    &          .AND. ( ii1 == 3     .OR. ii2 == 3     .OR. ii3 == 3     ) )   lsend_bdyint(ib_bdy,igrd,1) = .true.
+               IF( ii == jpi-1 .AND. ( nbondi == -1 .OR. nbondi == 0 ) &
+                    &          .AND. ( ii1 == jpi-2 .OR. ii2 == jpi-2 .OR. ii3 == jpi-2 ) )   lsend_bdyint(ib_bdy,igrd,2) = .true.
+               IF( ii == 2     .AND. ( nbondi ==  1 .OR. nbondi == 0 ) .AND. iibe == 3     )   lsend_bdyext(ib_bdy,igrd,1) = .true.
+               IF( ii == jpi-1 .AND. ( nbondi == -1 .OR. nbondi == 0 ) .AND. iibe == jpi-2 )   lsend_bdyext(ib_bdy,igrd,2) = .true.
+               !
+               ! search neighbour in the north/south direction   
+               ! Rim is on the halo and computed ocean is towards exterior of mpi domain
+               !(3)   |       |         ^   ___o___     
+               !  |   |___x___|   OR    |  |   x   |
+               !  v       o           (4)  |       |
+               IF( ij1 == 0     .OR. ij2 == 0     .OR. ij3 == 0     )   lrecv_bdyint(ib_bdy,igrd,3) = .true.
+               IF( ij1 == jpj+1 .OR. ij2 == jpj+1 .OR. ij3 == jpj+1 )   lrecv_bdyint(ib_bdy,igrd,4) = .true.
+               IF( ijbe == 0     )   lrecv_bdyext(ib_bdy,igrd,3) = .true.
+               IF( ijbe == jpj+1 )   lrecv_bdyext(ib_bdy,igrd,4) = .true.
+               ! Check if neighbour has its rim parallel to its mpi subdomain     _________  border and next to its halo
+               !   ^  |    o    |                                                :         : 
+               !   |  |¨¨¨¨x¨¨¨¨|   neighbour limited by ... would need o     |  |....x....|
+               !      :_________:  (3) S neighbour          N neighbour (4)   v  |    o    |   
+               IF( ij == 2     .AND. ( nbondj ==  1 .OR. nbondj == 0 ) &
+                    &          .AND. ( ij1 == 3     .OR. ij2 == 3     .OR. ij3 == 3     ) )   lsend_bdyint(ib_bdy,igrd,3) = .true.
+               IF( ij == jpj-1 .AND. ( nbondj == -1 .OR. nbondj == 0 ) &
+                    &          .AND. ( ij1 == jpj-2 .OR. ij2 == jpj-2 .OR. ij3 == jpj-2 ) )   lsend_bdyint(ib_bdy,igrd,4) = .true.
+               IF( ij == 2     .AND. ( nbondj ==  1 .OR. nbondj == 0 ) .AND. ijbe == 3     )   lsend_bdyext(ib_bdy,igrd,3) = .true.
+               IF( ij == jpj-1 .AND. ( nbondj == -1 .OR. nbondj == 0 ) .AND. ijbe == jpj-2 )   lsend_bdyext(ib_bdy,igrd,4) = .true.
+            END DO
          END DO
       END DO
+
+      DO ib_bdy = 1,nb_bdy
+         IF( cn_dyn2d(ib_bdy) == 'orlanski' .OR. cn_dyn2d(ib_bdy) == 'orlanski_npo' .OR. &
+           & cn_dyn3d(ib_bdy) == 'orlanski' .OR. cn_dyn3d(ib_bdy) == 'orlanski_npo' .OR. &
+           & cn_tra(ib_bdy)   == 'orlanski' .OR. cn_tra(ib_bdy)   == 'orlanski_npo'      ) THEN
+            DO igrd = 1, jpbgrd
+               DO ib = 1, idx_bdy(ib_bdy)%nblenrim(igrd)
+                  ii = idx_bdy(ib_bdy)%nbi(ib,igrd)
+                  ij = idx_bdy(ib_bdy)%nbj(ib,igrd)
+                  IF(  mig(ii) > 2 .AND. mig(ii) < jpiglo-2 .AND. mjg(ij) > 2 .AND. mjg(ij) < jpjglo-2  ) THEN
+                     WRITE(ctmp1,*) ' Orlanski can not be used when the open boundaries are on the interior of the computational domain'
+                     WRITE(ctmp2,*) ' ========== '
+                     CALL ctl_stop( ' ', ctmp1, ctmp2, ' ' )
+                  END IF
+               END DO
+            END DO
+         END IF
+      END DO
+      
       !
       ! Tidy up
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdylib.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdylib.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdylib.F90	(revision 11071)
@@ -187,4 +187,5 @@
          ii  = idx%nbi(jb,igrd)
          ij  = idx%nbj(jb,igrd) 
+         IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )   CYCLE
          flagu = int( idx%flagu(jb,igrd) )
          flagv = int( idx%flagv(jb,igrd) )
@@ -344,4 +345,5 @@
             ii  = idx%nbi(jb,igrd)
             ij  = idx%nbj(jb,igrd) 
+            IF( ii == 1 .OR. ii == jpi .OR. ij == 1 .OR. ij == jpj )   CYCLE
             flagu = int( idx%flagu(jb,igrd) )
             flagv = int( idx%flagv(jb,igrd) )
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdytra.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdytra.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdytra.F90	(revision 11071)
@@ -51,5 +51,5 @@
       INTEGER                        :: ib_bdy, jn, igrd   ! Loop indeces
       TYPE(ztrabdy), DIMENSION(jpts) :: zdta               ! Temporary data structure
-      LOGICAL, DIMENSION(4)          :: lsend1, lrecv1     ! indicate how communications are to be carried out
+      LOGICAL, DIMENSION(4)          :: llsend1, llrecv1     ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       igrd = 1 
@@ -76,24 +76,18 @@
       END DO
       !
-      lsend1(:) = .false.
-      lrecv1(:) = .false.
+      llsend1(:) = .false.
+      llrecv1(:) = .false.
       DO ib_bdy=1, nb_bdy
          SELECT CASE( TRIM(cn_tra(ib_bdy)) )
-         CASE('neumann')
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
-         CASE('orlanski')
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
-         CASE('orlanski_npo')
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
-         CASE('runoff')
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
+         CASE('neumann','runoff')
+            llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:)   ! possibly every direction, T points
+            llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:)   ! possibly every direction, T points
+         CASE('orlanski', 'orlanski_npo')
+            llsend1(:) = llsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! possibly every direction, T points
+            llrecv1(:) = llrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! possibly every direction, T points
          END SELECT
       END DO
-      IF( ANY(lsend1) .OR. ANY(lrecv1) ) THEN   ! if need to send/recv in at least one direction
-         CALL lbc_bdy_lnk( 'bdytra', lsend1, lrecv1, tsa, 'T',  1. )
+      IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+         CALL lbc_bdy_lnk( 'bdytra', llsend1, llrecv1, tsa, 'T',  1. )
       END IF
       !
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/DYN/dynkeg.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/DYN/dynkeg.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/DYN/dynkeg.F90	(revision 11071)
@@ -80,5 +80,5 @@
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   ztrdu, ztrdv 
       REAL(wp)  :: zweightu, zweightv
-      LOGICAL, DIMENSION(4) :: lsend1, lrecv1  ! indicate how bdy communications are to be carried out
+      LOGICAL, DIMENSION(4) :: llsend1, llrecv1  ! indicate how bdy communications are to be carried out
       !!----------------------------------------------------------------------
       !
@@ -136,13 +136,16 @@
                END IF
             END DO
-            ! send 2 and recv jpi, jpj used in the computation of the speed tendencies
-            lsend1(:) = .false.
-            lrecv1(:) = .false.
+            ! send jpi-1, jpj-1 and receive 1 used in the computation of the speed tendencies
+            llsend1(:) = .false.
+            llrecv1(:) = .false.
             DO ib_bdy = 1, nb_bdy
-               lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-               lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
-            END DO
-            IF( COUNT(lsend1) > 0 .OR. COUNT(lrecv1) > 0 ) THEN   ! if need to send/recv in at least one direction
-               CALL lbc_bdy_lnk( 'bdydyn2d', lsend1, lrecv1, zhke, 'T',  1. )
+               llsend1(2) = llsend1(2) .OR. lsend_bdy(ib_bdy,igrd,2)   ! send east
+               llsend1(4) = llsend1(4) .OR. lsend_bdy(ib_bdy,igrd,4)   ! send north
+               llrecv1(1) = llrecv1(1) .OR. lrecv_bdy(ib_bdy,igrd,1)   ! receive west 
+               llrecv1(3) = llrecv1(3) .OR. lrecv_bdy(ib_bdy,igrd,3)   ! receive south
+            END DO
+   
+            IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+               CALL lbc_bdy_lnk( 'bdydyn2d', llsend1, llrecv1, zhke, 'T',  1. )
             END IF
          END IF
Index: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/TOP/trcbdy.F90
===================================================================
--- NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/TOP/trcbdy.F90	(revision 11069)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/TOP/trcbdy.F90	(revision 11071)
@@ -46,8 +46,8 @@
       INTEGER, INTENT( in ) :: kt     ! Main time step counter
       !!
-      INTEGER                           :: ib_bdy ,jn ,igrd ! Loop indeces
+      INTEGER                           :: ib_bdy ,jn ,igrd ! Loop indices
       REAL(wp), POINTER, DIMENSION(:,:) ::  ztrc
       REAL(wp), POINTER                 ::  zfac
-      LOGICAL, DIMENSION(4)             :: lsend1, lrecv1     ! indicate how communications are to be carried out
+      LOGICAL, DIMENSION(4)             :: llsend1, llrecv1     ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       !
@@ -75,21 +75,18 @@
       END DO
       !
-      lsend1(:) = .false.
-      lrecv1(:) = .false.
+      llsend1(:) = .false.
+      llrecv1(:) = .false.
       DO ib_bdy=1, nb_bdy
          SELECT CASE( TRIM(cn_tra(ib_bdy)) )
          CASE('neumann')
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
-         CASE('orlanski')
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
-         CASE('orlanski_npo')
-            lsend1(:) = lsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! to   every bdy neighbour, T points
-            lrecv1(:) = lrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! from every bdy neighbour, T points
+            llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:)   ! possibly every direction, T points
+            llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:)   ! possibly every direction, T points
+         CASE('orlanski','orlanski_npo')
+            llsend1(:) = llsend1(:) .OR. lsend_bdy(ib_bdy,1,:)   ! possibly every direction, T points
+            llrecv1(:) = llrecv1(:) .OR. lrecv_bdy(ib_bdy,1,:)   ! possibly every direction, T points
          END SELECT
       END DO
-      IF( ANY(lsend1) .OR. ANY(lrecv1) ) THEN   ! if need to send/recv in at least one direction
-         CALL lbc_bdy_lnk( 'bdytra', lsend1, lrecv1, tsa, 'T',  1. )
+      IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN   ! if need to send/recv in at least one direction
+         CALL lbc_bdy_lnk( 'bdytra', llsend1, llrecv1, tsa, 'T',  1. )
       END IF
       !
