Index: /NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd/src/OCE/LBC/lib_mpp.F90
===================================================================
--- /NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd/src/OCE/LBC/lib_mpp.F90	(revision 15275)
+++ /NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd/src/OCE/LBC/lib_mpp.F90	(revision 15276)
@@ -58,4 +58,5 @@
    !
    PUBLIC   ctl_stop, ctl_warn, ctl_opn, ctl_nam
+   PUBLIC   set_mpi_pre_initialised
    PUBLIC   mpp_start, mppstop, mppsync, mpp_comm_free
    PUBLIC   mpp_ini_north
@@ -100,4 +101,5 @@
 !$AGRIF_END_DO_NOT_TREAT
    LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.    !: mpp flag
+   LOGICAL, PUBLIC            ::   mpi_pre_initialised = .FALSE.
 #else   
    INTEGER, PUBLIC, PARAMETER ::   MPI_STATUS_SIZE = 1
@@ -176,4 +178,18 @@
    !!----------------------------------------------------------------------
 CONTAINS
+
+   SUBROUTINE set_mpi_pre_initialised()
+      !!----------------------------------------------------------------------
+      !!                  ***  routine set_mpi_pre_initialised  ***
+      !!
+      !! ** Purpose :   set global variable mpi_pre_initialised
+      !!----------------------------------------------------------------------
+      INTEGER ::   ierr
+      !!----------------------------------------------------------------------
+#if defined key_mpp_mpi
+      call mpi_initialized(mpi_pre_initialised, ierr)
+#endif
+      !
+   END SUBROUTINE set_mpi_pre_initialised
 
    SUBROUTINE mpp_start( localComm )
@@ -692,5 +708,7 @@
       ELSE
          CALL mppsync
-         CALL mpi_finalize( info )
+         IF (.NOT. mpi_pre_initialised) THEN
+             CALL mpi_finalize( info )
+         ENDIF
       ENDIF
       IF( ll_abort ) STOP 123
Index: /NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd/src/OCE/nemogcm.F90
===================================================================
--- /NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd/src/OCE/nemogcm.F90	(revision 15275)
+++ /NEMO/branches/UKMO/NEMO_4.0.1_NGMS_couple_stage3_spmd/src/OCE/nemogcm.F90	(revision 15276)
@@ -100,4 +100,7 @@
 
    PUBLIC   nemo_gcm    ! called by model.F90
+   PUBLIC   nemo_gcm_init ! called by nemo_gcm or external subroutine
+   PUBLIC   nemo_gcm_run ! called by nemo_gcm or external subroutine
+   PUBLIC   nemo_gcm_finalise ! called by nemo_gcm or external subroutine
    PUBLIC   nemo_init   ! needed by AGRIF
    PUBLIC   nemo_alloc  ! needed by TAM
@@ -124,15 +127,26 @@
       !!              curvilinear mesh on the sphere.
       !!
-      !! ** Method  : - model general initialization
-      !!              - launch the time-stepping (stp routine)
-      !!              - finalize the run by closing files and communications
+      !! ** Method  : - calls nemo_gcm_init, nemo_gcm_run, nemo_gcm_finalise
       !!
       !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
       !!              Madec, 2008, internal report, IPSL.
       !!----------------------------------------------------------------------
-      INTEGER ::   istp, nerror   ! time step index
-      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
-      !!----------------------------------------------------------------------
-      !
+      CALL nemo_gcm_init
+      CALL nemo_gcm_run
+      CALL nemo_gcm_finalise
+   END SUBROUTINE nemo_gcm
+
+   SUBROUTINE nemo_gcm_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_gcm_init  ***
+      !!
+      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
+      !!              curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - model general initialization
+      !!
+      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
+      !!              Madec, 2008, internal report, IPSL.
+      !!----------------------------------------------------------------------
 #if defined key_agrif
       CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
@@ -151,4 +165,22 @@
 # endif
 #endif
+   END SUBROUTINE nemo_gcm_init
+
+   SUBROUTINE nemo_gcm_run
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_gcm_run  ***
+      !!
+      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
+      !!              curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - launch the time-stepping (stp routine)
+      !!
+      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
+      !!              Madec, 2008, internal report, IPSL.
+      !!----------------------------------------------------------------------
+      INTEGER ::   istp   ! time step index
+      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
+      !!----------------------------------------------------------------------
+      !
       ! check that all process are still there... If some process have an error,
       ! they will never enter in step and other processes will wait until the end of the cpu time!
@@ -248,4 +280,21 @@
       write(numout,*) "RSRH done closefiles " , lk_oasis; flush(numout)
       !
+   END SUBROUTINE nemo_gcm_run
+
+   SUBROUTINE nemo_gcm_finalise
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_gcm_finalise  ***
+      !!
+      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
+      !!              curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - finalize the run by closing files and communications
+      !!
+      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
+      !!              Madec, 2008, internal report, IPSL.
+      !!----------------------------------------------------------------------
+      integer :: nerror
+      !!----------------------------------------------------------------------
+      !
 #if defined key_iomput
       CALL xios_finalize()  ! end mpp communications with xios
@@ -262,13 +311,15 @@
 #endif
       !
-      IF(lwm) THEN
-         IF( nstop == 0 ) THEN   
-                STOP 0
-         ELSE        
-                STOP 123
+      IF (.NOT. mpi_pre_initialised) THEN
+         IF(lwm) THEN
+            IF( nstop == 0 ) THEN   
+                  STOP 0
+            ELSE        
+                  STOP 123
+            ENDIF
          ENDIF
       ENDIF
       !
-   END SUBROUTINE nemo_gcm
+   END SUBROUTINE nemo_gcm_finalise
 
 
@@ -294,4 +345,5 @@
       !                             !-------------------------------------------------!
       !
+      CALL set_mpi_pre_initialised()
 #if defined key_iomput
 !      IF( Agrif_Root() ) THEN
@@ -305,5 +357,7 @@
 ! RSRH simplify initialisaton for test
       IF( lk_oasis ) THEN
-          CALL mpi_init(nerror)
+          IF (.NOT. mpi_pre_initialised) THEN
+              CALL mpi_init(nerror)
+          ENDIF
           CALL oasis_init_comp ( ncomp_id, "toyoce", nerror, .TRUE. )
 !          CALL cpl_init( "toyoce", ilocal_comm ) 
