Index: trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 5429)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/LBC/lbclnk.F90	(revision 6140)
@@ -4,11 +4,9 @@
    !! Ocean        : lateral boundary conditions
    !!=====================================================================
-   !! History :  OPA  ! 1997-06  (G. Madec)     Original code
-   !!   NEMO     1.0  ! 2002-09  (G. Madec)     F90: Free form and module
+   !! History :  OPA  ! 1997-06  (G. Madec)  Original code
+   !!   NEMO     1.0  ! 2002-09  (G. Madec)  F90: Free form and module
    !!            3.2  ! 2009-03  (R. Benshila)  External north fold treatment  
-   !!            3.5  ! 2012     (S.Mocavero, I. Epicoco) Add 'lbc_bdy_lnk' 
-   !!                            and lbc_obc_lnk' routine to optimize  
-   !!                            the BDY/OBC communications
-   !!            3.4  ! 2012-12  (R. Bourdalle-Badie and G. Reffray)  add a C1D case  
+   !!            3.5  ! 2012     (S.Mocavero, I. Epicoco) optimization of BDY comm. via lbc_bdy_lnk and lbc_obc_lnk
+   !!            3.4  ! 2012-12  (R. Bourdalle-Badie, G. Reffray)  add a C1D case  
    !!----------------------------------------------------------------------
 #if defined key_mpp_mpi
@@ -17,35 +15,41 @@
    !!----------------------------------------------------------------------
    !!   lbc_lnk      : generic interface for mpp_lnk_3d and mpp_lnk_2d routines defined in lib_mpp
+   !!   lbc_sum      : generic interface for mpp_lnk_sum_3d and mpp_lnk_sum_2d routines defined in lib_mpp
    !!   lbc_lnk_e    : generic interface for mpp_lnk_2d_e routine defined in lib_mpp
    !!   lbc_bdy_lnk  : generic interface for mpp_lnk_bdy_2d and mpp_lnk_bdy_3d routines defined in lib_mpp
    !!----------------------------------------------------------------------
-   USE lib_mpp          ! distributed memory computing library
-
+   USE lib_mpp        ! distributed memory computing library
 
    INTERFACE lbc_lnk_multi
       MODULE PROCEDURE mpp_lnk_2d_9
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk
       MODULE PROCEDURE mpp_lnk_3d_gather, mpp_lnk_3d, mpp_lnk_2d
    END INTERFACE
+   !
+!JMM interface not defined if not key_mpp_mpi : likely do not compile without this CPP key !!!!
+   INTERFACE lbc_sum
+      MODULE PROCEDURE mpp_lnk_sum_3d, mpp_lnk_sum_2d
+   END INTERFACE
 
    INTERFACE lbc_bdy_lnk
       MODULE PROCEDURE mpp_lnk_bdy_2d, mpp_lnk_bdy_3d
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk_e
       MODULE PROCEDURE mpp_lnk_2d_e
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk_icb
       MODULE PROCEDURE mpp_lnk_2d_icb
    END INTERFACE
 
-   PUBLIC lbc_lnk       ! ocean lateral boundary conditions
-   PUBLIC lbc_lnk_multi ! modified ocean lateral boundary conditions
-   PUBLIC lbc_lnk_e
-   PUBLIC lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
-   PUBLIC lbc_lnk_icb
+   PUBLIC   lbc_lnk       ! ocean lateral boundary conditions
+   PUBLIC   lbc_lnk_multi ! modified ocean lateral boundary conditions
+   PUBLIC   lbc_sum
+   PUBLIC   lbc_lnk_e     !
+   PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
+   PUBLIC   lbc_lnk_icb   !
 
    !!----------------------------------------------------------------------
@@ -54,13 +58,15 @@
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
-
 #else
    !!----------------------------------------------------------------------
    !!   Default option                              shared memory computing
    !!----------------------------------------------------------------------
-   !!   lbc_lnk      : generic interface for lbc_lnk_3d and lbc_lnk_2d
-   !!   lbc_lnk_3d   : set the lateral boundary condition on a 3D variable on ocean mesh
-   !!   lbc_lnk_2d   : set the lateral boundary condition on a 2D variable on ocean mesh
-   !!   lbc_bdy_lnk  : set the lateral BDY boundary condition
+   !!   lbc_sum       : generic interface for mpp_lnk_sum_3d and mpp_lnk_sum_2d 
+   !!   lbc_lnk_sum_3d: compute sum over the halos on a 3D variable on ocean mesh
+   !!   lbc_lnk_sum_3d: compute sum over the halos on a 2D variable on ocean mesh
+   !!   lbc_lnk       : generic interface for lbc_lnk_3d and lbc_lnk_2d
+   !!   lbc_lnk_3d    : set the lateral boundary condition on a 3D variable on ocean mesh
+   !!   lbc_lnk_2d    : set the lateral boundary condition on a 2D variable on ocean mesh
+   !!   lbc_bdy_lnk   : set the lateral BDY boundary condition
    !!----------------------------------------------------------------------
    USE oce             ! ocean dynamics and tracers   
@@ -75,13 +81,17 @@
       MODULE PROCEDURE lbc_lnk_3d_gather, lbc_lnk_3d, lbc_lnk_2d
    END INTERFACE
+   !
+   INTERFACE lbc_sum
+      MODULE PROCEDURE mpp_lnk_sum_3d, mpp_lnk_sum_2d
+   END INTERFACE
 
    INTERFACE lbc_lnk_e
       MODULE PROCEDURE lbc_lnk_2d_e
    END INTERFACE
-
+   !
    INTERFACE lbc_bdy_lnk
       MODULE PROCEDURE lbc_bdy_lnk_2d, lbc_bdy_lnk_3d
    END INTERFACE
-
+   !
    INTERFACE lbc_lnk_icb
       MODULE PROCEDURE lbc_lnk_2d_e
@@ -89,10 +99,10 @@
 
    PUBLIC   lbc_lnk       ! ocean/ice  lateral boundary conditions
-   PUBLIC   lbc_lnk_e 
+   PUBLIC   lbc_lnk_e     !
    PUBLIC   lbc_bdy_lnk   ! ocean lateral BDY boundary conditions
-   PUBLIC   lbc_lnk_icb
+   PUBLIC   lbc_lnk_icb   !
    
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -230,5 +240,4 @@
          ! this is in mpp case. In this module, just do nothing
       ELSE
-         !
          !                                     !  East-West boundaries
          !                                     ! ======================
@@ -249,5 +258,4 @@
             !
          END SELECT
-         !
          !                                     ! North-South boundaries
          !                                     ! ======================
@@ -287,4 +295,5 @@
    END SUBROUTINE lbc_lnk_3d
 
+
    SUBROUTINE lbc_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
       !!---------------------------------------------------------------------
@@ -316,5 +325,4 @@
          ! this is in mpp case. In this module, just do nothing
       ELSE      
-         !
          !                                     ! East-West boundaries
          !                                     ! ====================
@@ -335,5 +343,4 @@
             !
          END SELECT
-         !
          !                                     ! North-South boundaries
          !                                     ! ======================
@@ -375,5 +382,4 @@
 #endif
 
-
    SUBROUTINE lbc_bdy_lnk_3d( pt3d, cd_type, psgn, ib_bdy )
       !!---------------------------------------------------------------------
@@ -381,17 +387,18 @@
       !!
       !! ** Purpose :   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
-      !!                to maintain the same interface with regards to the mpp
-      !case
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout)           ::   pt3d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   )           ::   psgn      ! control of the sign 
-      INTEGER                                                   ::   ib_bdy    ! BDY boundary set
-      !!
+      !!              to maintain the same interface with regards to the mpp case
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the lbc is applied
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! control of the sign 
+      INTEGER                         , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
+      !!----------------------------------------------------------------------
+      !
       CALL lbc_lnk_3d( pt3d, cd_type, psgn)
-
+      !
    END SUBROUTINE lbc_bdy_lnk_3d
 
+
    SUBROUTINE lbc_bdy_lnk_2d( pt2d, cd_type, psgn, ib_bdy )
       !!---------------------------------------------------------------------
@@ -399,15 +406,15 @@
       !!
       !! ** Purpose :   wrapper rountine to 'lbc_lnk_3d'. This wrapper is used
-      !!                to maintain the same interface with regards to the mpp
-      !case
-      !!
-      !!----------------------------------------------------------------------
-      CHARACTER(len=1)                , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj),     INTENT(inout)           ::   pt2d      ! 3D array on which the lbc is applied
-      REAL(wp)                        , INTENT(in   )           ::   psgn      ! control of the sign 
-      INTEGER                                                   ::   ib_bdy    ! BDY boundary set
-      !!
+      !!              to maintain the same interface with regards to the mpp case
+      !!
+      !!----------------------------------------------------------------------
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 3D array on which the lbc is applied
+      REAL(wp)                    , INTENT(in   ) ::   psgn      ! control of the sign 
+      INTEGER                     , INTENT(in   ) ::   ib_bdy    ! BDY boundary set
+      !!----------------------------------------------------------------------
+      !
       CALL lbc_lnk_2d( pt2d, cd_type, psgn)
-
+      !
    END SUBROUTINE lbc_bdy_lnk_2d
 
@@ -426,11 +433,11 @@
       !!                             for closed boundaries.
       !!----------------------------------------------------------------------
-      CHARACTER(len=1)            , INTENT(in   )           ::   cd_type   ! nature of pt3d grid-points
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout)           ::   pt2d      ! 2D array on which the lbc is applied
-      REAL(wp)                    , INTENT(in   )           ::   psgn      ! control of the sign 
-      INTEGER                     , INTENT(in   )           ::   jpri      ! size of extra halo (not needed in non-mpp)
-      INTEGER                     , INTENT(in   )           ::   jprj      ! size of extra halo (not needed in non-mpp)
-      !!----------------------------------------------------------------------
-
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 2D array on which the lbc is applied
+      REAL(wp)                    , INTENT(in   ) ::   psgn      ! control of the sign 
+      INTEGER                     , INTENT(in   ) ::   jpri      ! size of extra halo (not needed in non-mpp)
+      INTEGER                     , INTENT(in   ) ::   jprj      ! size of extra halo (not needed in non-mpp)
+      !!----------------------------------------------------------------------
+      !
       CALL lbc_lnk_2d( pt2d, cd_type, psgn )
       !    
