Index: /branches/DEV_1879_mpp_rep/CONFIG/GYRE/EXP00/namelist
===================================================================
--- /branches/DEV_1879_mpp_rep/CONFIG/GYRE/EXP00/namelist	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/CONFIG/GYRE/EXP00/namelist	(revision 1920)
@@ -627,6 +627,4 @@
    nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
                            !     (no physical validity of the results)
-   nn_bit_cmp  =    0      !  bit comparison mode (1/0): CAUTION use zero except for test
-                           !     of comparison between single and multiple processor runs
 /
 
Index: /branches/DEV_1879_mpp_rep/CONFIG/GYRE_LOBSTER/EXP00/namelist
===================================================================
--- /branches/DEV_1879_mpp_rep/CONFIG/GYRE_LOBSTER/EXP00/namelist	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/CONFIG/GYRE_LOBSTER/EXP00/namelist	(revision 1920)
@@ -627,6 +627,4 @@
    nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
                            !     (no physical validity of the results)
-   nn_bit_cmp  =    0      !  bit comparison mode (1/0): CAUTION use zero except for test
-                           !     of comparison between single and multiple processor runs
 /
 
Index: /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM/EXP00/1_namelist
===================================================================
--- /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM/EXP00/1_namelist	(revision 1920)
@@ -626,6 +626,4 @@
    nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
                            !     (no physical validity of the results)
-   nn_bit_cmp  =    0      !  bit comparison mode (1/0): CAUTION use zero except for test
-                           !     of comparison between single and multiple processor runs
 /
 
Index: /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM/EXP00/namelist
===================================================================
--- /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM/EXP00/namelist	(revision 1920)
@@ -654,6 +654,4 @@
    nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
                            !     (no physical validity of the results)
-   nn_bit_cmp  =    0      !  bit comparison mode (1/0): CAUTION use zero except for test
-                           !     of comparison between single and multiple processor runs
 /
 
Index: /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist
===================================================================
--- /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/CONFIG/ORCA2_LIM_PISCES/EXP00/namelist	(revision 1920)
@@ -654,6 +654,4 @@
    nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
                            !     (no physical validity of the results)
-   nn_bit_cmp  =    0      !  bit comparison mode (1/0): CAUTION use zero except for test
-                           !     of comparison between single and multiple processor runs
 /
 
Index: /branches/DEV_1879_mpp_rep/CONFIG/POMME/EXP00/namelist
===================================================================
--- /branches/DEV_1879_mpp_rep/CONFIG/POMME/EXP00/namelist	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/CONFIG/POMME/EXP00/namelist	(revision 1920)
@@ -651,6 +651,4 @@
    nn_bench    =    0      !  Bench mode (1/0): CAUTION use zero except for bench
                            !     (no physical validity of the results)
-   nn_bit_cmp  =    0      !  bit comparison mode (1/0): CAUTION use zero except for test
-                           !     of comparison between single and multiple processor runs
 /
 
Index: /branches/DEV_1879_mpp_rep/NEMO/LIM_SRC_2/limdyn_2.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/LIM_SRC_2/limdyn_2.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/LIM_SRC_2/limdyn_2.F90	(revision 1920)
@@ -83,5 +83,5 @@
          ! ---------------------------------------------------
          
-         IF( lk_mpp .OR. nbit_cmp == 1 ) THEN                    ! mpp: compute over the whole domain
+         IF( lk_mpp .OR. lk_mpp_rep ) THEN                    ! mpp: compute over the whole domain
             i_j1 = 1   
             i_jpj = jpj
Index: /branches/DEV_1879_mpp_rep/NEMO/LIM_SRC_3/limdyn.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/LIM_SRC_3/limdyn.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/LIM_SRC_3/limdyn.F90	(revision 1920)
@@ -93,5 +93,5 @@
          ! ---------------------------------------------------
 
-         IF( lk_mpp .OR. nbit_cmp == 1 ) THEN                    ! mpp: compute over the whole domain
+         IF( lk_mpp .OR. lk_mpp_rep ) THEN                    ! mpp: compute over the whole domain
             i_j1 = 1
             i_jpj = jpj
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 1920)
@@ -221,4 +221,12 @@
 #endif
 
+   !!----------------------------------------------------------------------
+   !! mpp reproducibility
+   !!----------------------------------------------------------------------
+#if defined key_mpp_rep1 || defined key_mpp_re2
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp_rep = .TRUE.    !: agrif flag
+#else
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp_rep = .FALSE.   !: agrif flag
+#endif
    !!======================================================================
 END MODULE dom_oce
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DOM/domain.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DOM/domain.F90	(revision 1920)
@@ -166,17 +166,21 @@
       ENDIF
 
+#if defined key_agrif
       IF( Agrif_Root() ) THEN
-         SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
-         CASE (  1 ) 
-            CALL ioconf_calendar('gregorian')
-            IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "gregorian", i.e. leap year'
-         CASE (  0 )
-            CALL ioconf_calendar('noleap')
-            IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "noleap", i.e. no leap year'
-         CASE ( 30 )
-            CALL ioconf_calendar('360d')
-            IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "360d", i.e. 360 days in a year'
-         END SELECT
-      ENDIF
+#endif
+      SELECT CASE ( nleapy )        ! Choose calendar for IOIPSL
+      CASE (  1 ) 
+         CALL ioconf_calendar('gregorian')
+         IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "gregorian", i.e. leap year'
+      CASE (  0 )
+         CALL ioconf_calendar('noleap')
+         IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "noleap", i.e. no leap year'
+      CASE ( 30 )
+         CALL ioconf_calendar('360d')
+         IF(lwp) WRITE(numout,*) '   The IOIPSL calendar is "360d", i.e. 360 days in a year'
+      END SELECT
+#if defined key_agrif
+      ENDIF
+#endif
 
       REWIND( numnam )             ! Namelist namdom : space & time domain (bathymetry, mesh, timestep)
@@ -226,5 +230,5 @@
       n_cla = nn_cla                ! conversion DOCTOR names into model names (this should disappear soon)
 
-      IF( nbit_cmp == 1 .AND. n_cla /= 0 )   CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require n_cla = 0' )
+      IF( lk_mpp_rep .AND. n_cla /= 0 )   CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require n_cla = 0' )
       !
    END SUBROUTINE dom_nam
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DYN/dynspg_flt.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 1920)
@@ -47,4 +47,5 @@
    USE iom
    USE restart         ! only for lrst_oce
+   USE lib_fortran
 
    IMPLICIT NONE
@@ -186,6 +187,6 @@
 
 #if defined key_obc
-      IF( lk_obc )   CALL obc_dyn( kt )   ! Update velocities on each open boundary with the radiation algorithm
-      IF( lk_obc )   CALL obc_vol( kt )   ! Correction of the barotropic componant velocity to control the volume of the system
+      CALL obc_dyn( kt )      ! Update velocities on each open boundary with the radiation algorithm
+      CALL obc_vol( kt )      ! Correction of the barotropic componant velocity to control the volume of the system
 #endif
 #if defined key_bdy
@@ -281,6 +282,5 @@
       ! ------------------
       rnorme =0.e0
-      rnorme = SUM( gcb(1:jpi,1:jpj) * gcdmat(1:jpi,1:jpj) * gcb(1:jpi,1:jpj) * bmask(:,:) )
-      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+      rnorme = GLOB_SUM( gcb(1:jpi,1:jpj) * gcdmat(1:jpi,1:jpj) * gcb(1:jpi,1:jpj) * bmask(:,:) )
 
       epsr = eps * eps * rnorme
@@ -315,11 +315,6 @@
 #if defined key_obc
             ! caution : grad D = 0 along open boundaries
-            IF( Agrif_Root() ) THEN
-               spgu(ji,jj) = z2dt * ztdgu * obcumask(ji,jj)
-               spgv(ji,jj) = z2dt * ztdgv * obcvmask(ji,jj)
-            ELSE
-               spgu(ji,jj) = z2dt * ztdgu
-               spgv(ji,jj) = z2dt * ztdgv
-            ENDIF
+            spgu(ji,jj) = z2dt * ztdgu * obcumask(ji,jj)
+            spgv(ji,jj) = z2dt * ztdgv * obcvmask(ji,jj)
 #elif defined key_bdy
             ! caution : grad D = 0 along open boundaries
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 1920)
@@ -80,5 +80,5 @@
 
    !                                              !: OLD namelist names
-   INTEGER ::   nprint, nictls, nictle, njctls, njctle, isplt, jsplt, nbench, nbit_cmp   
+   INTEGER ::   nprint, nictls, nictle, njctls, njctle, isplt, jsplt, nbench
 
    INTEGER            ::   ijsplt     =    1      !: nb of local domain = nb of processors
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SBC/sbcana.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SBC/sbcana.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SBC/sbcana.F90	(revision 1920)
@@ -207,5 +207,5 @@
 
       ! Compute the emp flux such as its integration on the whole domain at each time is zero
-      IF( nbench /= 1 .AND. nbit_cmp /= 1 ) THEN
+      IF( nbench /= 1 ) THEN
          zsumemp = 0.e0   ;   zsurf = 0.e0
          DO jj = 1, jpj
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SBC/sbcfwb.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SBC/sbcfwb.F90	(revision 1920)
@@ -23,4 +23,5 @@
    USE lib_mpp         ! distribued memory computing library
    USE lbclnk          ! ocean lateral boundary conditions
+   USE lib_fortran
 
    IMPLICIT NONE
@@ -65,5 +66,5 @@
       INTEGER  ::   inum                  ! temporary logical unit
       INTEGER  ::   ikty, iyear           ! 
-      REAL(wp) ::   z_emp, z_emp_nsrf, zsum_emp, zsum_erp       ! temporary scalars
+      REAL(wp) ::   z_emp, z_emp_nsrf       ! temporary scalars
       REAL(wp) ::   zsurf_neg, zsurf_pos, zsurf_tospread
       REAL(wp), DIMENSION(jpi,jpj) ::   ztmsk_neg, ztmsk_pos, ztmsk_tospread
@@ -87,6 +88,5 @@
          !
          e1e2_i(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
-         area = SUM( e1e2_i(:,:) )
-         IF( lk_mpp )   CALL  mpp_sum( area    )   ! sum over the global domain
+         area = glob_sum( e1e2_i(:,:) )   ! sum over the global domain
          !
       ENDIF
@@ -103,6 +103,5 @@
       CASE ( 1 )                               ! global mean emp set to zero
          IF( MOD( kt-1, kn_fsbc ) == 0 ) THEN
-            z_emp = SUM( e1e2_i(:,:) * emp(:,:) ) / area
-            IF( lk_mpp )   CALL  mpp_sum( z_emp    )   ! sum over the global domain
+            z_emp = glob_sum( e1e2_i(:,:) * emp(:,:) ) / area   ! sum over the global domain
             emp (:,:) = emp (:,:) - z_emp
             emps(:,:) = emps(:,:) - z_emp
@@ -128,6 +127,5 @@
          IF( MOD( kt, ikty ) == 0 ) THEN
             a_fwb_b = a_fwb
-            a_fwb   = SUM( e1e2_i(:,:) * sshn(:,:) )
-            IF( lk_mpp )   CALL  mpp_sum( a_fwb    )   ! sum over the global domain
+            a_fwb   = glob_sum( e1e2_i(:,:) * sshn(:,:) )   ! sum over the global domain
             a_fwb   = a_fwb * 1.e+3 / ( area * 86400. * 365. )     ! convert in Kg/m3/s = mm/s
 !!gm        !                                                      !!bug 365d year 
@@ -162,9 +160,6 @@
         
             ! emp global mean 
-            z_emp = SUM( e1e2_i(:,:) * emp(:,:) ) / area
+            z_emp = glob_sum( e1e2_i(:,:) * emp(:,:) ) / area
             !
-            IF( lk_mpp )   CALL  mpp_sum( z_emp )
-            IF( lk_mpp )   CALL  mpp_sum( zsurf_neg )
-            IF( lk_mpp )   CALL  mpp_sum( zsurf_pos )
             
             IF( z_emp < 0.e0 ) THEN
@@ -179,12 +174,7 @@
 
             ! emp global mean over <0 or >0 erp area
-            zsum_emp = SUM( e1e2_i(:,:) * z_emp )
-            IF( lk_mpp )   CALL  mpp_sum( zsum_emp )
-            z_emp_nsrf =  zsum_emp / ( zsurf_tospread + rsmall )
+            z_emp_nsrf = SUM( e1e2_i(:,:) * z_emp ) / ( zsurf_tospread + rsmall )
             ! weight to respect erp field 2D structure 
-            zsum_erp = SUM( ztmsk_tospread(:,:) * erp(:,:) * e1e2_i(:,:) )
-            IF( lk_mpp )   CALL  mpp_sum( zsum_erp )
-            z_wgt(:,:) = ztmsk_tospread(:,:) * erp(:,:) / ( zsum_erp + rsmall )
-
+            z_wgt(:,:) = ztmsk_tospread(:,:) * erp(:,:) / ( SUM( ztmsk_tospread(:,:) * erp(:,:) * e1e2_i(:,:) ) + rsmall )
             ! final correction term to apply
             zerp_cor(:,:) = -1. * z_emp_nsrf * zsurf_tospread * z_wgt(:,:)
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solpcg.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solpcg.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solpcg.F90	(revision 1920)
@@ -14,4 +14,5 @@
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
    USE in_out_manager  ! I/O manager
+   USE lib_fortran
 
    IMPLICIT NONE
@@ -95,4 +96,6 @@
       ! Initialization of the algorithm with standard PCG
       ! -------------------------------------------------
+      zgcr = 0.e0 
+      gcr  = 0.e0 
 
       CALL lbc_lnk( gcx, c_solver_pt, 1. )   ! lateral boundary condition
@@ -100,5 +103,4 @@
       ! gcr   = gcb-a.gcx
       ! gcdes = gcr
-
       DO jj = 2, jpjm1
          DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -114,6 +116,5 @@
 
       ! rnorme = (gcr,gcr)
-      rnorme = SUM(  gcr(:,:) * gcdmat(:,:) * gcr(:,:)  )
-      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+      rnorme = glob_sum(  gcr(:,:) * gcdmat(:,:) * gcr(:,:)  )
 
       CALL lbc_lnk( gcdes, c_solver_pt, 1. )   ! lateral boundary condition
@@ -129,6 +130,5 @@
 
       ! alph = (gcr,gcr)/(gcdes,gccd)
-      radd = SUM(  gcdes(:,:) * gcdmat(:,:) * gccd(:,:)  )
-      IF( lk_mpp )   CALL mpp_sum( radd )   ! sum over the global domain
+      radd = glob_sum(  gcdes(:,:) * gcdmat(:,:) * gccd(:,:)  )
       alph = rnorme /radd
 
@@ -162,13 +162,12 @@
          ! rnorme = (gcr,gcr)
          rr = rnorme
-         zsum(1) = SUM(  gcr(:,:) * gcdmat(:,:) * gcr(:,:)  )
 
          ! zgcad = (zgcr,gcr) 
-         zsum(2) = SUM( gcr(2:jpim1,2:jpjm1) * gcdmat(2:jpim1,2:jpjm1) * zgcr(2:jpim1,2:jpjm1) )
-
-         IF( lk_mpp )   CALL mpp_sum( zsum, 2 )   ! sum over the global domain
+         zsum(1) = glob_sum(gcr(:,:) * gcdmat(:,:) * gcr(:,:))
+         zsum(2) = glob_sum(gcr(:,:) * gcdmat(:,:) * zgcr(:,:) * bmask(:,:))
+
+         !!RB we should gather the 2 glob_sum
          rnorme = zsum(1)  
          zgcad  = zsum(2)
-
          ! test of convergence
          IF( rnorme < epsr .OR. jn == nn_nmax ) THEN
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solsor.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solsor.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solsor.F90	(revision 1920)
@@ -22,4 +22,5 @@
    USE lib_mpp         ! distributed memory computing
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE lib_fortran
 
    IMPLICIT NONE
@@ -64,4 +65,5 @@
       INTEGER  ::   ijmppodd, ijmppeven, ijpr2d
       REAL(wp) ::   ztmp, zres, zres2
+      REAL(wp), DIMENSION(jpi,jpj) ::ztab
       !!----------------------------------------------------------------------
       
@@ -131,6 +133,7 @@
                ENDIF
             CASE ( 1 )                 ! relative precision
-               rnorme = SUM( gcr(2:nlci-1,2:nlcj-1) )
-               IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
+               ztab = 0.
+               ztab(:,:) = gcr(2:nlci-1,2:nlcj-1)
+               rnorme = glob_sum( ztab)    ! sum over the global domain
                ! test of convergence
                IF( rnorme < epsr .OR. jn == nn_nmax ) THEN
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solver.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solver.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/SOL/solver.F90	(revision 1920)
@@ -102,11 +102,4 @@
       END SELECT
       !
-      IF( nbit_cmp == 1 ) THEN            ! reproductibility test SOR required
-         IF( nn_solv /= 2 ) THEN
-            CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require the SOR solver: nn_solv = 2' )
-         ELSE IF( MAX( jpr2di, jpr2dj ) > 0 ) THEN
-            CALL ctl_stop( ' Reproductibility tests (nbit_cmp=1) require jpr2di = jpr2dj = 0' )
-         END IF 
-      END IF
 
       !                             !* Grid-point at which the solver is applied
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/lib_mpp.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/lib_mpp.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/lib_mpp.F90	(revision 1920)
@@ -75,4 +75,8 @@
 #endif
 
+# if defined key_mpp_rep1
+   PUBLIC mpp_allgatherv
+# endif
+
    !! * Interfaces
    !! define generic interface for these routine as they are called sometimes
@@ -86,5 +90,10 @@
    END INTERFACE
    INTERFACE mpp_sum
+# if defined key_mpp_rep2
+      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real, &
+                       mppsum_realdd, mppsum_a_realdd
+# else
       MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real
+# endif
    END INTERFACE
    INTERFACE mpp_lbc_north
@@ -97,5 +106,10 @@
       MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
    END INTERFACE
-
+   
+# if defined key_mpp_rep1
+   INTERFACE mpp_allgatherv
+      MODULE PROCEDURE mpp_allgatherv_real, mpp_allgatherv_int
+   END INTERFACE
+# endif
 
    !! ========================= !!
@@ -112,7 +126,7 @@
    INTEGER ::   mppsize        ! number of process
    INTEGER ::   mpprank        ! process number  [ 0 - size-1 ]
-!$AGRIF_DO_NOT_TREAT
-   INTEGER, PUBLIC ::   mpi_comm_opa   ! opa local communicator
-!$AGRIF_END_DO_NOT_TREAT
+   INTEGER ::   mpi_comm_opa   ! opa local communicator
+
+   INTEGER, PUBLIC :: MPI_SUMDD
 
    ! variables used in case of sea-ice
@@ -193,13 +207,67 @@
       WRITE(ldtxt(6),*) '      size in bytes of exported buffer   nn_buffer   = ', nn_buffer
 
-      CALL mpi_initialized ( mpi_was_called, code )
-      IF( code /= MPI_SUCCESS ) THEN
-         WRITE(*, cform_err)
-         WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
-         CALL mpi_abort( mpi_comm_world, code, ierr )
-      ENDIF
-
-      IF( mpi_was_called ) THEN
-         !
+#if defined key_agrif
+      IF( Agrif_Root() ) THEN
+#endif
+         !!bug RB : should be clean to use Agrif in coupled mode
+#if ! defined key_agrif
+         CALL mpi_initialized ( mpi_was_called, code )
+         IF( code /= MPI_SUCCESS ) THEN
+            WRITE(*, cform_err)
+            WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+
+         IF( PRESENT(localComm) .and. mpi_was_called ) THEN
+            mpi_comm_opa = localComm
+            SELECT CASE ( cn_mpi_send )
+            CASE ( 'S' )                ! Standard mpi send (blocking)
+               WRITE(ldtxt(7),*) '           Standard blocking mpi send (send)'
+            CASE ( 'B' )                ! Buffer mpi send (blocking)
+               WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
+               CALL mpi_init_opa( ierr ) 
+            CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+               WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
+               l_isend = .TRUE.
+            CASE DEFAULT
+               WRITE(ldtxt(7),cform_err)
+               WRITE(ldtxt(8),*) '           bad value for cn_mpi_send = ', cn_mpi_send
+               nstop = nstop + 1
+            END SELECT
+         ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
+            WRITE(ldtxt(7),*) ' lib_mpp: You cannot provide a local communicator '
+            WRITE(ldtxt(8),*) '          without calling MPI_Init before ! '
+            nstop = nstop + 1
+         ELSE
+#endif
+            SELECT CASE ( cn_mpi_send )
+            CASE ( 'S' )                ! Standard mpi send (blocking)
+               WRITE(ldtxt(7),*) '           Standard blocking mpi send (send)'
+               CALL mpi_init( ierr )
+            CASE ( 'B' )                ! Buffer mpi send (blocking)
+               WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
+               CALL mpi_init_opa( ierr )
+            CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+               WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
+               l_isend = .TRUE.
+               CALL mpi_init( ierr )
+            CASE DEFAULT
+               WRITE(ldtxt(7),cform_err)
+               WRITE(ldtxt(8),*) '           bad value for cn_mpi_send = ', cn_mpi_send
+               nstop = nstop + 1
+            END SELECT
+
+#if ! defined key_agrif
+            CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
+            IF( code /= MPI_SUCCESS ) THEN
+               WRITE(*, cform_err)
+               WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
+               CALL mpi_abort( mpi_comm_world, code, ierr )
+            ENDIF
+            !
+         ENDIF
+#endif
+#if defined key_agrif
+      ELSE
          SELECT CASE ( cn_mpi_send )
          CASE ( 'S' )                ! Standard mpi send (blocking)
@@ -207,5 +275,4 @@
          CASE ( 'B' )                ! Buffer mpi send (blocking)
             WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
-            CALL mpi_init_opa( ierr ) 
          CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
             WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
@@ -216,44 +283,15 @@
             nstop = nstop + 1
          END SELECT
-      ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
-         WRITE(ldtxt(7),*) ' lib_mpp: You cannot provide a local communicator '
-         WRITE(ldtxt(8),*) '          without calling MPI_Init before ! '
-         nstop = nstop + 1
-      ELSE
-         SELECT CASE ( cn_mpi_send )
-         CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(7),*) '           Standard blocking mpi send (send)'
-            CALL mpi_init( ierr )
-         CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(7),*) '           Buffer blocking mpi send (bsend)'
-            CALL mpi_init_opa( ierr )
-         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(7),*) '           Immediate non-blocking send (isend)'
-            l_isend = .TRUE.
-            CALL mpi_init( ierr )
-         CASE DEFAULT
-            WRITE(ldtxt(7),cform_err)
-            WRITE(ldtxt(8),*) '           bad value for cn_mpi_send = ', cn_mpi_send
-            nstop = nstop + 1
-         END SELECT
-         !
       ENDIF
 
-      IF( PRESENT(localComm) ) THEN 
-         IF( Agrif_Root() ) THEN
-            mpi_comm_opa = localComm
-         ENDIF
-      ELSE
-         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
-         IF( code /= MPI_SUCCESS ) THEN
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-      ENDIF 
-
+      mpi_comm_opa = mpi_comm_world
+#endif
       CALL mpi_comm_rank( mpi_comm_opa, mpprank, ierr )
       CALL mpi_comm_size( mpi_comm_opa, mppsize, ierr )
       mynode = mpprank
+      !
+#if defined key_mpp_rep2
+      CALL MPI_OP_CREATE(DDPDD_MPI, .TRUE., MPI_SUMDD, ierr)
+#endif
       !
    END FUNCTION mynode
@@ -1394,5 +1432,59 @@
    END SUBROUTINE mppsum_real
 
-
+# if defined key_mpp_rep2
+   SUBROUTINE mppsum_realdd( ytab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_realdd ***
+      !!
+      !! ** Purpose :   global sum in Massively Parallel Processing
+      !!                SCALAR argument case for double-double precision
+      !!
+      !!-----------------------------------------------------------------------
+      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+
+      !! * Local variables   (MPI version)
+      INTEGER  ::    ierror
+      INTEGER  ::   localcomm
+      COMPLEX(wp) :: zwork
+
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+
+      ! reduce local sums into global sum
+      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, &
+                       MPI_SUMDD,localcomm,ierror)
+      ytab = zwork
+
+   END SUBROUTINE mppsum_realdd
+  
+  
+   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_realdd  ***
+      !!
+      !! ** Purpose :   global sum in Massively Parallel Processing
+      !!                COMPLEX ARRAY case for double-double precision
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
+      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+
+      !! * Local variables   (MPI version)
+      INTEGER                      :: ierror    ! temporary integer
+      INTEGER                      ::   localcomm
+      COMPLEX(wp), DIMENSION(kdim) :: zwork     ! temporary workspace
+
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+
+      CALL MPI_ALLREDUCE (ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, &
+                       MPI_SUMDD,localcomm,ierror)
+      ytab(:) = zwork(:)
+
+   END SUBROUTINE mppsum_a_realdd
+# endif   
+   
    SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki,kj )
       !!------------------------------------------------------------------------
@@ -2049,5 +2141,4 @@
       ijpj   = 4
       ijpjm1 = 3
-      ztab(:,:,:) = 0.e0
       !
       DO jj = nlcj - ijpj +1, nlcj          ! put in znorthloc the last 4 jlines of pt3d
@@ -2115,5 +2206,4 @@
       ijpj   = 4
       ijpjm1 = 3
-      ztab(:,:) = 0.e0
       !
       DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d
@@ -2181,5 +2271,4 @@
       !
       ijpj=4
-      ztab(:,:) = 0.e0
 
       ij=0
@@ -2265,10 +2354,165 @@
    END SUBROUTINE mpi_init_opa
 
+#if defined key_mpp_rep1
+   SUBROUTINE mpp_allgatherv_real( pvalsin, knoin, pvalsout, ksizeout, &
+      &                            knoout, kstartout )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_allgatherv_real ***
+      !!          
+      !! ** Purpose : Gather a real array on all processors
+      !!
+      !! ** Method  : MPI all gatherv
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  08-08  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & knoin,     &
+         & ksizeout
+      REAL(wp), DIMENSION(knoin), INTENT(IN) :: &
+         & pvalsin
+      REAL(wp), DIMENSION(ksizeout), INTENT(OUT) :: &
+         & pvalsout
+      INTEGER, DIMENSION(jpnij), INTENT(OUT) :: &
+         & kstartout, &
+         & knoout
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ierr
+      INTEGER :: &
+         & ji
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to get number of data per processor
+      !-----------------------------------------------------------------------
+      CALL mpi_allgather( knoin,  1, mpi_integer, &
+         &                knoout, 1, mpi_integer, &
+         &                mpi_comm_opa, ierr )
+      !-----------------------------------------------------------------------
+      ! Compute starts of each processors contribution
+      !-----------------------------------------------------------------------
+      kstartout(1) = 0
+      DO ji = 2, jpnij
+         kstartout(ji) = kstartout(ji-1) + knoout(ji-1) 
+      ENDDO
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to do the gathering of the data
+      !-----------------------------------------------------------------------
+      CALL mpi_allgatherv( pvalsin,  knoin,  MPI_DOUBLE_PRECISION,            &
+         &                 pvalsout, knoout, kstartout, MPI_DOUBLE_PRECISION, &
+         &                 mpi_comm_opa, ierr )
+     
+   END SUBROUTINE mpp_allgatherv_real
+
+   SUBROUTINE mpp_allgatherv_int( kvalsin, knoin, kvalsout, ksizeout, &
+      &                               knoout, kstartout )
+      !!----------------------------------------------------------------------
+      !!               ***  ROUTINE mpp_allgatherv ***
+      !!          
+      !! ** Purpose : Gather an integer array on all processors
+      !!
+      !! ** Method  : MPI all gatherv
+      !!
+      !! ** Action  : This does only work for MPI. 
+      !!              It does not work for SHMEM.
+      !!
+      !! References : http://www.mpi-forum.org
+      !!
+      !! History :
+      !!        !  06-07  (K. Mogensen)  Original code
+      !!----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT(IN) :: &
+         & knoin,     &
+         & ksizeout
+      INTEGER, DIMENSION(knoin), INTENT(IN) :: &
+         & kvalsin
+      INTEGER, DIMENSION(ksizeout), INTENT(OUT) :: &
+         & kvalsout
+      INTEGER, DIMENSION(jpnij), INTENT(OUT) :: &
+         & kstartout, &
+         & knoout
+      
+      !! * Local declarations
+      INTEGER :: &
+         & ierr
+      INTEGER :: &
+         & ji
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to get number of data per processor
+      !-----------------------------------------------------------------------
+      CALL mpi_allgather( knoin,  1, mpi_integer, &
+         &                knoout, 1, mpi_integer, &
+         &                mpi_comm_opa, ierr )
+      !-----------------------------------------------------------------------
+      ! Compute starts of each processors contribution
+      !-----------------------------------------------------------------------
+      kstartout(1) = 0
+      DO ji = 2, jpnij
+         kstartout(ji) = kstartout(ji-1) + knoout(ji-1)
+      ENDDO
+      !-----------------------------------------------------------------------
+      ! Call the MPI library to do the gathering of the data
+      !-----------------------------------------------------------------------
+      CALL mpi_allgatherv( kvalsin,  knoin,  mpi_integer,            &
+         &                 kvalsout, knoout, kstartout, mpi_integer, &
+         &                 mpi_comm_opa, ierr )
+      
+   END SUBROUTINE mpp_allgatherv_int
+#endif
+
+#if defined key_mpp_rep2
+   SUBROUTINE DDPDD_MPI (ydda, yddb, ilen, itype)
+      !!---------------------------------------------------------------------
+      !!   Routine DDPDD_MPI: used by reduction operator MPI_SUMDD
+      !!
+      !!   Modification of original codes written by David H. Bailey
+      !!   This subroutine computes yddb(i) = ydda(i)+yddb(i)
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)                         :: ilen, itype
+      COMPLEX(wp), DIMENSION(ilen), INTENT(in)     :: ydda
+      COMPLEX(wp), DIMENSION(ilen), INTENT(inout)  :: yddb
+      !
+      REAL(wp) :: zerr, zt1, zt2    ! local work variables
+      INTEGER :: ji, ztmp           ! local scalar
+
+      ztmp = itype   ! avoid compilation warning
+
+      DO ji=1,ilen
+      ! Compute ydda + yddb using Knuth's trick.
+         zt1  = real(ydda(ji)) + real(yddb(ji))
+         zerr = zt1 - real(ydda(ji))
+         zt2  = ((real(yddb(ji)) - zerr) + (real(ydda(ji)) - (zt1 - zerr))) &
+                + aimag(ydda(ji)) + aimag(yddb(ji))
+
+         ! The result is zt1 + zt2, after normalization.
+         yddb(ji) = cmplx ( zt1 + zt2, zt2 - ((zt1 + zt2) - zt1),wp )
+      END DO
+
+   END SUBROUTINE DDPDD_MPI
+#endif
+
 #else
    !!----------------------------------------------------------------------
    !!   Default case:            Dummy module        share memory computing
    !!----------------------------------------------------------------------
+# if defined key_mpp_rep1
+   USE par_kind
+   USE par_oce
+
+   PUBLIC mpp_allgatherv
+# endif
+
    INTERFACE mpp_sum
-      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i
+      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i,  &
+             &         mpp_sum_c, mpp_sum_ac 
    END INTERFACE
    INTERFACE mpp_max
@@ -2288,4 +2532,10 @@
    END INTERFACE
 
+# if defined key_mpp_rep1
+   INTERFACE mpp_allgatherv
+      MODULE PROCEDURE mpp_allgatherv_real, mpp_allgatherv_int
+   END INTERFACE
+# endif
+
 
    LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
@@ -2325,4 +2575,11 @@
    END SUBROUTINE mpp_sum_ai
 
+   SUBROUTINE mpp_sum_ac( yarr, kdim, kcom )      ! Dummy routine
+      COMPLEX, DIMENSION(:) :: yarr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom 
+      WRITE(*,*) 'mpp_sum_ac: You should not have seen this print! error?', kdim, yarr(1), kcom
+   END SUBROUTINE mpp_sum_ac
+
    SUBROUTINE mpp_sum_s( psca, kcom )            ! Dummy routine
       REAL                  :: psca
@@ -2330,10 +2587,16 @@
       WRITE(*,*) 'mpp_sum_s: You should not have seen this print! error?', psca, kcom
    END SUBROUTINE mpp_sum_s
-
+ 
    SUBROUTINE mpp_sum_i( kint, kcom )            ! Dummy routine
       integer               :: kint
-      INTEGER, OPTIONAL     :: kcom 
+      INTEGER, OPTIONAL     :: kcom
       WRITE(*,*) 'mpp_sum_i: You should not have seen this print! error?', kint, kcom
    END SUBROUTINE mpp_sum_i
+
+   SUBROUTINE mpp_sum_c( ysca, kcom )            ! Dummy routine
+      COMPLEX               :: ysca
+      INTEGER, OPTIONAL     :: kcom 
+      WRITE(*,*) 'mpp_sum_c: You should not have seen this print! error?', ysca, kcom
+   END SUBROUTINE mpp_sum_c
 
    SUBROUTINE mppmax_a_real( parr, kdim, kcom )
@@ -2459,4 +2722,41 @@
    END SUBROUTINE mpp_comm_free
 
+# if defined key_mpp_rep1 
+   SUBROUTINE mpp_allgatherv_real( pvalsin, knoin, pvalsout, ksizeout, &
+      &                            knoout, kstartout )
+      INTEGER, INTENT(IN) :: &
+         & knoin,     &
+         & ksizeout
+      REAL(wp), DIMENSION(knoin), INTENT(IN) :: &
+         & pvalsin
+      REAL(wp), DIMENSION(ksizeout), INTENT(OUT) :: &
+         & pvalsout
+      INTEGER, DIMENSION(jpnij), INTENT(OUT) :: &
+         & kstartout, &
+         & knoout
+      pvalsout(1:knoin) = pvalsin(1:knoin)
+      kstartout(1) = 0
+      knoout(1) = knoin          
+   END SUBROUTINE mpp_allgatherv_real
+
+   SUBROUTINE mpp_allgatherv_int( kvalsin, knoin, kvalsout, ksizeout, &
+      &                               knoout, kstartout )
+      INTEGER, INTENT(IN) :: &
+         & knoin,     &
+         & ksizeout
+      INTEGER, DIMENSION(knoin), INTENT(IN) :: &
+         & kvalsin
+      INTEGER, DIMENSION(ksizeout), INTENT(OUT) :: &
+         & kvalsout
+      INTEGER, DIMENSION(jpnij), INTENT(OUT) :: &
+         & kstartout, &
+         & knoout
+      
+      kvalsout(1:knoin) = kvalsin(1:knoin)
+      kstartout(1) = 0
+      knoout(1) = knoin            
+   END SUBROUTINE mpp_allgatherv_int
+# endif
+
 #endif
    !!----------------------------------------------------------------------
Index: /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/opa.F90
===================================================================
--- /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/opa.F90	(revision 1919)
+++ /branches/DEV_1879_mpp_rep/NEMO/OPA_SRC/opa.F90	(revision 1920)
@@ -156,7 +156,5 @@
       CALL opa_closefile
 #if defined key_oasis3 || defined key_oasis4
-      IF( Agrif_Root() ) THEN
-         CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
-     ENDIF 
+      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
 #else
       IF( lk_mpp )   CALL mppstop       ! end mpp communications
@@ -180,5 +178,5 @@
       !!
       NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
-         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle, nn_bench, nn_bit_cmp
+         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle, nn_bench
       !!----------------------------------------------------------------------
       !
@@ -193,12 +191,8 @@
 #if defined key_iomput
 # if defined key_oasis3 || defined key_oasis4
-      IF( Agrif_Root() ) THEN
-         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
-         CALL init_ioclient()                    ! io_server will get its communicators (if needed) from oasis (we don't see it)
-      ENDIF
+      CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
+      CALL init_ioclient()                    ! io_server will get its communicators (if needed) from oasis (we don't see it)
 # else
-      IF( Agrif_Root() ) THEN
-         CALL init_ioclient( ilocal_comm )       ! nemo local communicator (used or not) given by the io_server
-      ENDIF
+      CALL init_ioclient( ilocal_comm )       ! nemo local communicator (used or not) given by the io_server
 # endif
       narea = mynode( cltxt, ilocal_comm )    ! Nodes selection
@@ -206,7 +200,5 @@
 #else
 # if defined key_oasis3 || defined key_oasis4
-      IF( Agrif_Root() ) THEN
-         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
-      ENDIF
+      CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
       narea = mynode( cltxt, ilocal_comm )    ! Nodes selection (control print return in cltxt)
 # else
@@ -312,5 +304,4 @@
          WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
          WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
-         WRITE(numout,*) '      bit comparison mode (0/1)       nn_bit_cmp = ', nn_bit_cmp
       ENDIF
 
@@ -323,5 +314,4 @@
       jsplt     = nn_jsplt
       nbench    = nn_bench
-      nbit_cmp  = nn_bit_cmp
 
       !                           ! Parameter control
@@ -372,9 +362,4 @@
       ENDIF
 
-      IF( nbit_cmp == 1 )   THEN          ! Bit compare
-         CALL ctl_warn( ' Bit comparison enabled. Single and multiple processor results must bit compare', &
-              &         ' WARNING: RESULTS ARE NOT PHYSICAL.' )
-      ENDIF
-
       REWIND( numnam )              ! Read Namelist namdyn_hpg : ln_dynhpg_imp must be read at the initialisation phase
       READ  ( numnam, namdyn_hpg )
