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 11049)
+++ NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/src/OCE/BDY/bdydyn3d.F90	(revision 11067)
@@ -43,6 +43,7 @@
       !
       INTEGER ::   ib_bdy   ! loop index
-      !!----------------------------------------------------------------------
-      !
+      LOGICAL, DIMENSION(4) :: lsend2, lrecv2, lsend3, lrecv3  ! indicate how communications are to be carried out
+
+      !!----------------------------------------------------------------------
       DO ib_bdy=1, nb_bdy
          !
@@ -60,4 +61,40 @@
       END DO
       !
+      lsend2(:) = .false.
+      lrecv2(:) = .false.
+      lsend3(:) = .false.
+      lrecv3(:) = .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('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
+         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
+         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. )
+      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. )
+      END IF
+      !
    END SUBROUTINE bdy_dyn3d
 
@@ -78,5 +115,4 @@
       INTEGER  ::   jb, jk         ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
-      REAL(wp) ::   zwgt           ! boundary weight
       !!----------------------------------------------------------------------
       !
@@ -98,7 +134,4 @@
          END DO
       END DO
-      !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )   ! Boundary points should be updated  
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )
       !
    END SUBROUTINE bdy_dyn3d_spe
@@ -156,7 +189,4 @@
       END DO
       !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )   ! Boundary points should be updated  
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )   
-      !
    END SUBROUTINE bdy_dyn3d_zgrad
 
@@ -176,5 +206,4 @@
       INTEGER  ::   ib, ik         ! dummy loop indices
       INTEGER  ::   ii, ij, igrd   ! local integers
-      REAL(wp) ::   zwgt           ! boundary weight
       !!----------------------------------------------------------------------
       !
@@ -187,5 +216,5 @@
          END DO
       END DO
-
+      !
       igrd = 3                       ! Everything is at T-points here
       DO ib = 1, idx%nblenrim(igrd)
@@ -196,6 +225,4 @@
          END DO
       END DO
-      !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )   ;   CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1.,ib_bdy )   ! Boundary points should be updated
       !
    END SUBROUTINE bdy_dyn3d_zro
@@ -241,8 +268,5 @@
             va(ii,ij,jk) = ( va(ii,ij,jk) + zwgt * ( dta%v3d(jb,jk) - va(ii,ij,jk) ) ) * vmask(ii,ij,jk)
          END DO
-      END DO 
-      !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )   
+      END DO   
       !
    END SUBROUTINE bdy_dyn3d_frs
@@ -276,7 +300,4 @@
       !  
       CALL bdy_orlanski_3d( idx, igrd, vb, va, dta%v3d, ll_npo )
-      !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )   
       !
    END SUBROUTINE bdy_dyn3d_orlanski
@@ -326,6 +347,4 @@
       END DO
       !
-      CALL lbc_lnk_multi( 'bdydyn3d', ua, 'U', -1.,  va, 'V', -1. )   ! Boundary points should be updated
-      !
       IF( ln_timing )   CALL timing_stop('bdy_dyn3d_dmp')
       !
@@ -346,4 +365,5 @@
 
       INTEGER  ::   jb, igrd                               ! dummy loop indices
+      LOGICAL, DIMENSION(4) :: lsend2, lrecv2, lsend3, lrecv3  ! indicate how communications are to be carried out
       !!----------------------------------------------------------------------
       !
@@ -358,7 +378,4 @@
       CALL bdy_nmn( idx, igrd, va )   ! va is masked
       !
-      CALL lbc_bdy_lnk( 'bdydyn3d', ua, 'U', -1., ib_bdy )    ! Boundary points should be updated
-      CALL lbc_bdy_lnk( 'bdydyn3d', va, 'V', -1., ib_bdy )
-      !
    END SUBROUTINE bdy_dyn3d_nmn
 
