Index: NEMO/branches/2020/r12581_ticket2418/src/OCE/C1D/step_c1d.F90
===================================================================
--- NEMO/branches/2020/r12581_ticket2418/src/OCE/C1D/step_c1d.F90	(revision 12582)
+++ NEMO/branches/2020/r12581_ticket2418/src/OCE/C1D/step_c1d.F90	(revision 12593)
@@ -56,8 +56,5 @@
       !
       INTEGER ::   jk       ! dummy loop indice
-      INTEGER ::   indic    ! error indicator if < 0
       !! ---------------------------------------------------------------------
-
-                             indic = 0                ! reset to no error condition
       IF( kstp == nit000 )   CALL iom_init( "nemo")   ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
       IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
@@ -139,10 +136,10 @@
       ! Control and restarts
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             CALL stp_ctl( kstp, Nnn, indic )
+                             CALL stp_ctl( kstp, Nnn )
       IF( kstp == nit000 )   CALL iom_close( numror )          ! close input  ocean restart file
       IF( lrst_oce       )   CALL rst_write( kstp, Nbb, Nnn )  ! write output ocean restart file
       !
 #if defined key_iomput
-      IF( kstp == nitend .OR. indic < 0 )   CALL xios_context_finalize()   ! needed for XIOS
+      IF( kstp == nitend .OR. nstop > 0 )   CALL xios_context_finalize()   ! needed for XIOS
       !
 #endif
Index: NEMO/branches/2020/r12581_ticket2418/src/OCE/IOM/in_out_manager.F90
===================================================================
--- NEMO/branches/2020/r12581_ticket2418/src/OCE/IOM/in_out_manager.F90	(revision 12582)
+++ NEMO/branches/2020/r12581_ticket2418/src/OCE/IOM/in_out_manager.F90	(revision 12593)
@@ -100,8 +100,4 @@
    !!----------------------------------------------------------------------
    TYPE :: sn_ctl                !: structure for control over output selection
-      LOGICAL :: l_glochk  = .FALSE.  !: range sanity checks are local (F) or global (T)
-                                      !  Use global setting for debugging only;
-                                      !  local breaches will still be reported
-                                      !  and stop the code in most cases.
       LOGICAL :: l_allon   = .FALSE.  !: overall control; activate all following output options
       LOGICAL :: l_config  = .FALSE.  !: activate/deactivate finer control
Index: NEMO/branches/2020/r12581_ticket2418/src/OCE/LBC/lib_mpp.F90
===================================================================
--- NEMO/branches/2020/r12581_ticket2418/src/OCE/LBC/lib_mpp.F90	(revision 12582)
+++ NEMO/branches/2020/r12581_ticket2418/src/OCE/LBC/lib_mpp.F90	(revision 12593)
@@ -1145,4 +1145,6 @@
          WRITE(numout,*)  'huge E-R-R-O-R : immediate stop'
          WRITE(numout,*)  
+         CALL FLUSH(numout)
+         CALL SLEEP(60)
          CALL mppstop( ld_abort = .true. )
       ENDIF
Index: NEMO/branches/2020/r12581_ticket2418/src/OCE/LBC/mpp_loc_generic.h90
===================================================================
--- NEMO/branches/2020/r12581_ticket2418/src/OCE/LBC/mpp_loc_generic.h90	(revision 12582)
+++ NEMO/branches/2020/r12581_ticket2418/src/OCE/LBC/mpp_loc_generic.h90	(revision 12593)
@@ -32,5 +32,4 @@
       REAL(wp)        , INTENT(  out) ::   pmin    ! Global minimum of ptab
       INDEX_TYPE(:)                                ! index of minimum in global frame
-# if defined key_mpp_mpi
       !
       INTEGER  ::   ierror, ii, idim
@@ -56,20 +55,20 @@
          !
          kindex(1) = mig( ilocs(1) )
-#  if defined DIM_2d || defined DIM_3d    /* avoid warning when kindex has 1 element */
+#if defined DIM_2d || defined DIM_3d    /* avoid warning when kindex has 1 element */
          kindex(2) = mjg( ilocs(2) )
-#  endif
-#  if defined DIM_3d                      /* avoid warning when kindex has 2 elements */
+#endif
+#if defined DIM_3d                      /* avoid warning when kindex has 2 elements */
          kindex(3) = ilocs(3)
-#  endif
+#endif
          ! 
          DEALLOCATE (ilocs)
          !
          index0 = kindex(1)-1   ! 1d index starting at 0
-#  if defined DIM_2d || defined DIM_3d   /* avoid warning when kindex has 1 element */
+#if defined DIM_2d || defined DIM_3d   /* avoid warning when kindex has 1 element */
          index0 = index0 + jpiglo * (kindex(2)-1)
-#  endif
-#  if defined DIM_3d                     /* avoid warning when kindex has 2 elements */
+#endif
+#if defined DIM_3d                     /* avoid warning when kindex has 2 elements */
          index0 = index0 + jpiglo * jpjglo * (kindex(3)-1)
-#  endif
+#endif
       END IF
       zain(1,:) = zmin
@@ -77,23 +76,23 @@
       !
       IF( ln_timing ) CALL tic_tac(.TRUE., ld_global = .TRUE.)
+#if defined key_mpp_mpi
       CALL MPI_ALLREDUCE( zain, zaout, 1, MPI_2DOUBLE_PRECISION, MPI_OPERATION ,MPI_COMM_OCE, ierror)
+#else
+      zaout(:,:) = zain(:,:)
+#endif
       IF( ln_timing ) CALL tic_tac(.FALSE., ld_global = .TRUE.)
       !
       pmin      = zaout(1,1)
       index0    = NINT( zaout(2,1) )
-#  if defined DIM_3d                     /* avoid warning when kindex has 2 elements */
+#if defined DIM_3d                     /* avoid warning when kindex has 2 elements */
       kindex(3) = index0 / (jpiglo*jpjglo)
       index0    = index0 - kindex(3) * (jpiglo*jpjglo)
-#  endif
-#  if defined DIM_2d || defined DIM_3d   /* avoid warning when kindex has 1 element */
+#endif
+#if defined DIM_2d || defined DIM_3d   /* avoid warning when kindex has 1 element */
       kindex(2) = index0 / jpiglo
       index0 = index0 - kindex(2) * jpiglo
-#  endif
+#endif
       kindex(1) = index0
       kindex(:) = kindex(:) + 1   ! start indices at 1
-#else
-      kindex = 0 ; pmin = 0.
-      WRITE(*,*) 'ROUTINE_LOC: You should not have seen this print! error?'
-#endif
 
    END SUBROUTINE ROUTINE_LOC
Index: NEMO/branches/2020/r12581_ticket2418/src/OCE/nemogcm.F90
===================================================================
--- NEMO/branches/2020/r12581_ticket2418/src/OCE/nemogcm.F90	(revision 12582)
+++ NEMO/branches/2020/r12581_ticket2418/src/OCE/nemogcm.F90	(revision 12593)
@@ -528,5 +528,4 @@
          WRITE(numout,*) '~~~~~~~~'
          WRITE(numout,*) '   Namelist namctl'
-         WRITE(numout,*) '                              sn_cfctl%l_glochk  = ', sn_cfctl%l_glochk
          WRITE(numout,*) '                              sn_cfctl%l_allon   = ', sn_cfctl%l_allon
          WRITE(numout,*) '       finer control over o/p sn_cfctl%l_config  = ', sn_cfctl%l_config
Index: NEMO/branches/2020/r12581_ticket2418/src/OCE/step.F90
===================================================================
--- NEMO/branches/2020/r12581_ticket2418/src/OCE/step.F90	(revision 12582)
+++ NEMO/branches/2020/r12581_ticket2418/src/OCE/step.F90	(revision 12593)
@@ -82,5 +82,4 @@
       !!----------------------------------------------------------------------
       INTEGER ::   ji, jj, jk   ! dummy loop indice
-      INTEGER ::   indic        ! error indicator if < 0
 !!gm kcall can be removed, I guess
       INTEGER ::   kcall        ! optional integer argument (dom_vvl_sf_nxt)
@@ -114,8 +113,6 @@
       ! update I/O and calendar 
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                             indic = 0                ! reset to no error condition
-                             
       IF( kstp == nit000 ) THEN                       ! initialize IOM context (must be done after nemo_init for AGRIF+XIOS+OASIS)
-                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including passible AGRIF zoom)
+                             CALL iom_init( cxios_context, ld_closedef=.FALSE. )   ! for model grid (including possible AGRIF zoom)
          IF( lk_diamlr   )   CALL dia_mlr_iom_init    ! with additional setup for multiple-linear-regression analysis
                              CALL iom_init_closedef
@@ -323,5 +320,5 @@
       ! Control
       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-                         CALL stp_ctl      ( kstp, Nbb, Nnn, indic )
+                         CALL stp_ctl      ( kstp, Nnn )
                          
       IF( kstp == nit000 ) THEN                          ! 1st time step only
@@ -338,8 +335,8 @@
       !
 #if defined key_iomput
-      IF( kstp == nitend .OR. indic < 0 ) THEN 
+      IF( kstp == nitend .OR. nstop > 0 ) THEN 
                       CALL iom_context_finalize(      cxios_context          ) ! needed for XIOS+AGRIF
-                      IF(lrxios) CALL iom_context_finalize(      crxios_context          )
-         IF( ln_crs ) CALL iom_context_finalize( trim(cxios_context)//"_crs" ) ! 
+         IF( lrxios ) CALL iom_context_finalize(      crxios_context         )
+         IF( ln_crs ) CALL iom_context_finalize( TRIM(cxios_context)//"_crs" ) ! 
       ENDIF
 #endif
Index: NEMO/branches/2020/r12581_ticket2418/src/OCE/stpctl.F90
===================================================================
--- NEMO/branches/2020/r12581_ticket2418/src/OCE/stpctl.F90	(revision 12582)
+++ NEMO/branches/2020/r12581_ticket2418/src/OCE/stpctl.F90	(revision 12593)
@@ -33,6 +33,6 @@
    PUBLIC stp_ctl           ! routine called by step.F90
 
-   INTEGER  ::   idrun, idtime, idssh, idu, ids1, ids2, idt1, idt2, idc1, idw1, istatus
-   LOGICAL  ::   lsomeoce
+   INTEGER                ::   nrunid   ! netcdf file id
+   INTEGER, DIMENSION(8)  ::   nvarid   ! netcdf variable id
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -42,5 +42,5 @@
 CONTAINS
 
-   SUBROUTINE stp_ctl( kt, Kbb, Kmm, kindic )
+   SUBROUTINE stp_ctl( kt, Kmm )
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE stp_ctl  ***
@@ -50,5 +50,5 @@
       !! ** Method  : - Save the time step in numstp
       !!              - Print it each 50 time steps
-      !!              - Stop the run IF problem encountered by setting indic=-3
+      !!              - Stop the run IF problem encountered by setting nstop > 0
       !!                Problems checked: |ssh| maximum larger than 10 m
       !!                                  |U|   maximum larger than 10 m/s 
@@ -57,140 +57,166 @@
       !! ** Actions :   "time.step" file = last ocean time-step
       !!                "run.stat"  file = run statistics
-      !!                nstop indicator sheared among all local domain (lk_mpp=T)
+      !!                 nstop indicator sheared among all local domain
       !!----------------------------------------------------------------------
       INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
-      INTEGER, INTENT(in   ) ::   Kbb, Kmm      ! ocean time level index
-      INTEGER, INTENT(inout) ::   kindic   ! error indicator
+      INTEGER, INTENT(in   ) ::   Kmm      ! ocean time level index
       !!
-      INTEGER                ::   ji, jj, jk          ! dummy loop indices
-      INTEGER, DIMENSION(2)  ::   ih                  ! min/max loc indices
-      INTEGER, DIMENSION(3)  ::   iu, is1, is2        ! min/max loc indices
-      REAL(wp)               ::   zzz                 ! local real 
-      REAL(wp), DIMENSION(9) ::   zmax
-      LOGICAL                ::   ll_wrtstp, ll_colruns, ll_wrtruns
-      CHARACTER(len=20) :: clname
+      INTEGER                         ::   ji                                    ! dummy loop indices
+      INTEGER                         ::   idtime, istatus
+      INTEGER, DIMENSION(3,4)         ::   iloc                                  ! min/max loc indices
+      REAL(wp)                        ::   zzz                                   ! local real 
+      REAL(wp), DIMENSION(9)          ::   zmax, zmaxlocal, zarea
+      LOGICAL                         ::   ll_wrtstp, ll_colruns, ll_wrtruns
+      LOGICAL, DIMENSION(jpi,jpj,jpk) ::   llmsk
+      CHARACTER(len=20)               ::   clname
       !!----------------------------------------------------------------------
       !
-      ll_wrtstp  = ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
-      ll_colruns = ll_wrtstp .AND. ( sn_cfctl%l_runstat )
+      ll_wrtstp  = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
+      ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat
       ll_wrtruns = ll_colruns .AND. lwm
-      IF( kt == nit000 .AND. lwp ) THEN
-         WRITE(numout,*)
-         WRITE(numout,*) 'stp_ctl : time-stepping control'
-         WRITE(numout,*) '~~~~~~~'
-         !                                ! open time.step file
-         IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
-         !                                ! open run.stat file(s) at start whatever
-         !                                ! the value of sn_cfctl%ptimincr
-         IF( lwm .AND. ( sn_cfctl%l_runstat ) ) THEN
+      !
+      IF( kt == nit000 ) THEN
+         !
+         IF( lwp ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'stp_ctl : time-stepping control'
+            WRITE(numout,*) '~~~~~~~'
+         ENDIF
+         !                                ! open time.step    ascii file, done only by 1st subdomain
+         IF( lwm )   CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+         !
+         IF( ll_wrtruns ) THEN
+            !                             ! open run.stat     ascii file, done only by 1st subdomain
             CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+            !                             ! open run.stat.nc netcdf file, done only by 1st subdomain
             clname = 'run.stat.nc'
             IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
-            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, idrun )
-            istatus = NF90_DEF_DIM( idrun, 'time', NF90_UNLIMITED, idtime )
-            istatus = NF90_DEF_VAR( idrun, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), idssh )
-            istatus = NF90_DEF_VAR( idrun,   'abs_u_max', NF90_DOUBLE, (/ idtime /), idu   )
-            istatus = NF90_DEF_VAR( idrun,       's_min', NF90_DOUBLE, (/ idtime /), ids1  )
-            istatus = NF90_DEF_VAR( idrun,       's_max', NF90_DOUBLE, (/ idtime /), ids2  )
-            istatus = NF90_DEF_VAR( idrun,       't_min', NF90_DOUBLE, (/ idtime /), idt1  )
-            istatus = NF90_DEF_VAR( idrun,       't_max', NF90_DOUBLE, (/ idtime /), idt2  )
+            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid )
+            istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime )
+            istatus = NF90_DEF_VAR( nrunid, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), nvarid(1) )
+            istatus = NF90_DEF_VAR( nrunid,   'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid(2) )
+            istatus = NF90_DEF_VAR( nrunid,       's_min', NF90_DOUBLE, (/ idtime /), nvarid(3) )
+            istatus = NF90_DEF_VAR( nrunid,       's_max', NF90_DOUBLE, (/ idtime /), nvarid(4) )
+            istatus = NF90_DEF_VAR( nrunid,       't_min', NF90_DOUBLE, (/ idtime /), nvarid(5) )
+            istatus = NF90_DEF_VAR( nrunid,       't_max', NF90_DOUBLE, (/ idtime /), nvarid(6) )
             IF( ln_zad_Aimp ) THEN
-               istatus = NF90_DEF_VAR( idrun,   'abs_wi_max', NF90_DOUBLE, (/ idtime /), idw1  )
-               istatus = NF90_DEF_VAR( idrun,       'Cf_max', NF90_DOUBLE, (/ idtime /), idc1  )
+               istatus = NF90_DEF_VAR( nrunid,   'Cf_max', NF90_DOUBLE, (/ idtime /), nvarid(7) )
+               istatus = NF90_DEF_VAR( nrunid,'abs_wi_max',NF90_DOUBLE, (/ idtime /), nvarid(8) )
             ENDIF
-            istatus = NF90_ENDDEF(idrun)
-            zmax(8:9) = 0._wp    ! initialise to zero in case ln_zad_Aimp option is not in use
-         ENDIF
-      ENDIF
-      IF( kt == nit000 )   lsomeoce = COUNT( ssmask(:,:) == 1._wp ) > 0
-      !
-      IF(lwm .AND. ll_wrtstp) THEN        !==  current time step  ==!   ("time.step" file)
+            istatus = NF90_ENDDEF(nrunid)
+         ENDIF
+         !    
+      ENDIF
+      !
+      !                                   !==              write current time step              ==!
+      !                                   !==  done only by 1st subdomain at writting timestep  ==!
+      IF( lwm .AND. ll_wrtstp ) THEN
          WRITE ( numstp, '(1x, i8)' )   kt
          REWIND( numstp )
       ENDIF
-      !
-      !                                   !==  test of extrema  ==!
+      !                                   !==            test of local extrema           ==!
+      !                                   !==  done by all processes at every time step  ==!
+      llmsk(:,:,1) = ssmask(:,:) == 1._wp
       IF( ll_wd ) THEN
-         zmax(1) = MAXVAL(  ABS( ssh(:,:,Kmm) + ssh_ref*tmask(:,:,1) )  )        ! ssh max 
+         zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) + ssh_ref ), mask = llmsk(:,:,1) )   ! ssh max
       ELSE
-         zmax(1) = MAXVAL(  ABS( ssh(:,:,Kmm) )  )                               ! ssh max
-      ENDIF
-      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) )  )                                  ! velocity max (zonal only)
-      zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm) , mask = tmask(:,:,:) == 1._wp )   ! minus salinity max
-      zmax(4) = MAXVAL(  ts(:,:,:,jp_sal,Kmm) , mask = tmask(:,:,:) == 1._wp )   !       salinity max
-      zmax(5) = MAXVAL( -ts(:,:,:,jp_tem,Kmm) , mask = tmask(:,:,:) == 1._wp )   ! minus temperature max
-      zmax(6) = MAXVAL(  ts(:,:,:,jp_tem,Kmm) , mask = tmask(:,:,:) == 1._wp )   !       temperature max
-      zmax(7) = REAL( nstop , wp )                                            ! stop indicator
-      IF( ln_zad_Aimp ) THEN
-         zmax(8) = MAXVAL(  ABS( wi(:,:,:) ) , mask = wmask(:,:,:) == 1._wp ) ! implicit vertical vel. max
-         zmax(9) = MAXVAL(   Cu_adv(:,:,:)   , mask = tmask(:,:,:) == 1._wp ) ! partitioning coeff. max
-      ENDIF
-      !
+         zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm)           ), mask = llmsk(:,:,1) )   ! ssh max
+      ENDIF
+      llmsk(:,:,:) = umask(:,:,:) == 1._wp
+      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) ), mask = llmsk )                     ! velocity max (zonal only)
+      llmsk(:,:,:) = tmask(:,:,:) == 1._wp
+      zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     ! minus salinity max
+      zmax(4) = MAXVAL(  ts(:,:,:,jp_sal,Kmm), mask = llmsk )                     !       salinity max
+      IF( ll_colruns ) THEN     ! following variables are used only in the netcdf file
+         zmax(5) = MAXVAL( -ts(:,:,:,jp_tem,Kmm), mask = llmsk )                  ! minus temperature max
+         zmax(6) = MAXVAL(  ts(:,:,:,jp_tem,Kmm), mask = llmsk )                  !       temperature max
+         IF( ln_zad_Aimp ) THEN
+            zmax(7) = MAXVAL(   Cu_adv(:,:,:)   , mask = llmsk )                  ! partitioning coeff. max
+            llmsk(:,:,:) = wmask(:,:,:) == 1._wp
+            zmax(8) = MAXVAL(  ABS( wi(:,:,:) ) , mask = llmsk )                  ! implicit vertical vel. max
+         ELSE
+            zmax(7:8) = 0._wp
+         ENDIF
+      ELSE
+         zmax(5:8) = 0._wp
+      ENDIF
+      zmax(9) = REAL( nstop, wp )                                              ! stop indicator
+      !                                   !==               get global extrema             ==!
+      !                                   !==  done by all processes if writting run.stat  ==!
       IF( ll_colruns ) THEN
+         zmaxlocal(:) = zmax(:)
          CALL mpp_max( "stpctl", zmax )          ! max over the global domain
-         nstop = NINT( zmax(7) )                 ! nstop indicator sheared among all local domains
-      ENDIF
-      !                                   !==  run statistics  ==!   ("run.stat" files)
+         nstop = NINT( zmax(9) )                 ! update nstop indicator (now sheared among all local domains)
+      ENDIF
+      !                                   !==              write "run.stat" files              ==!
+      !                                   !==  done only by 1st subdomain at writting timestep  ==!
       IF( ll_wrtruns ) THEN
          WRITE(numrun,9500) kt, zmax(1), zmax(2), -zmax(3), zmax(4)
-         istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( idrun,   idu, (/ zmax(2)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( idrun,  ids1, (/-zmax(3)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( idrun,  ids2, (/ zmax(4)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( idrun,  idt1, (/-zmax(5)/), (/kt/), (/1/) )
-         istatus = NF90_PUT_VAR( idrun,  idt2, (/ zmax(6)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ zmax(1)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/ zmax(2)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(3), (/-zmax(3)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(4), (/ zmax(4)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(5), (/-zmax(5)/), (/kt/), (/1/) )
+         istatus = NF90_PUT_VAR( nrunid, nvarid(6), (/ zmax(6)/), (/kt/), (/1/) )
          IF( ln_zad_Aimp ) THEN
-            istatus = NF90_PUT_VAR( idrun,  idw1, (/ zmax(8)/), (/kt/), (/1/) )
-            istatus = NF90_PUT_VAR( idrun,  idc1, (/ zmax(9)/), (/kt/), (/1/) )
-         ENDIF
-         IF( MOD( kt , 100 ) == 0 ) istatus = NF90_SYNC(idrun)
-         IF( kt == nitend         ) istatus = NF90_CLOSE(idrun)
+            istatus = NF90_PUT_VAR( nrunid, nvarid(7), (/ zmax(7)/), (/kt/), (/1/) )
+            istatus = NF90_PUT_VAR( nrunid, nvarid(8), (/ zmax(8)/), (/kt/), (/1/) )
+         ENDIF
+         IF( kt == nitend )   istatus = NF90_CLOSE(nrunid)
       END IF
-      !                                   !==  error handling  ==!
-      IF( ( sn_cfctl%l_glochk .OR. lsomeoce ) .AND. (   &  ! domain contains some ocean points, check for sensible ranges
-         &  zmax(1) >   20._wp .OR.   &                    ! too large sea surface height ( > 20 m )
-         &  zmax(2) >   10._wp .OR.   &                    ! too large velocity ( > 10 m/s)
-         &  zmax(3) >=   0._wp .OR.   &                    ! negative or zero sea surface salinity
-         &  zmax(4) >= 100._wp .OR.   &                    ! too large sea surface salinity ( > 100 )
-         &  zmax(4) <    0._wp .OR.   &                    ! too large sea surface salinity (keep this line for sea-ice)
-         &  ISNAN( zmax(1) + zmax(2) + zmax(3) ) ) ) THEN   ! NaN encounter in the tests
-         IF( lk_mpp .AND. sn_cfctl%l_glochk ) THEN
-            ! have use mpp_max (because sn_cfctl%l_glochk=.T. and distributed)
-            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,Kmm))        , ssmask(:,:)  , zzz, ih  )
-            CALL mpp_maxloc( 'stpctl', ABS(uu(:,:,:,Kmm))          , umask (:,:,:), zzz, iu  )
-            CALL mpp_minloc( 'stpctl', ts(:,:,:,jp_sal,Kmm), tmask (:,:,:), zzz, is1 )
-            CALL mpp_maxloc( 'stpctl', ts(:,:,:,jp_sal,Kmm), tmask (:,:,:), zzz, is2 )
-         ELSE
-            ! find local min and max locations
-            ih(:)  = MAXLOC( ABS( ssh(:,:,Kmm)   )                              ) + (/ nimpp - 1, njmpp - 1    /)
-            iu(:)  = MAXLOC( ABS( uu  (:,:,:,Kmm) )                              ) + (/ nimpp - 1, njmpp - 1, 0 /)
-            is1(:) = MINLOC( ts(:,:,:,jp_sal,Kmm), mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
-            is2(:) = MAXLOC( ts(:,:,:,jp_sal,Kmm), mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
-         ENDIF
-         
+      !                                   !==               error handling               ==!
+      !                                   !==  done by all processes at every time step  ==!
+      !
+      IF(   zmax(1) >   20._wp .OR.   &                   ! too large sea surface height ( > 20 m )
+         &  zmax(2) >   10._wp .OR.   &                   ! too large velocity ( > 10 m/s)
+         &  zmax(3) >=   0._wp .OR.   &                   ! negative or zero sea surface salinity
+         &  zmax(4) >= 100._wp .OR.   &                   ! too large sea surface salinity ( > 100 )
+         &  zmax(4) <    0._wp .OR.   &                   ! too large sea surface salinity (keep this line for sea-ice)
+         &  ISNAN( zmax(1) + zmax(2) + zmax(3) ) ) THEN   ! NaN encounter in the tests
+         !
+         IF( ll_colruns ) THEN   ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc
+            ! first: close the netcdf file, so we can read it
+            IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
+            ! get global loc on the min/max
+            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,         Kmm)), ssmask(:,:  ), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F 
+            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,       Kmm)),  umask(:,:,:), zzz, iloc(1:3,2) )
+            CALL mpp_minloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,3) )
+            CALL mpp_maxloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,4) )
+            ! find which subdomain has the max.
+            zarea(:) = 0._wp
+            DO ji = 1, 9
+               IF( zmaxlocal(ji) == zmax(ji) )   zarea(ji) = narea 
+            END DO
+            CALL mpp_max( "stpctl", zarea )         ! max over the global domain
+         ELSE                    ! find local min and max locations:
+            ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
+            iloc(1:2,1) = MAXLOC( ABS( ssh(:,:,         Kmm)), mask = ssmask(:,:  ) == 1._wp ) + (/ nimpp - 1, njmpp - 1    /)
+            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask =  umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
+            iloc(1:3,3) = MINLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
+            iloc(1:3,4) = MAXLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
+            zarea(:) = narea     ! this is local information
+         ENDIF
+         !
          WRITE(ctmp1,*) ' stp_ctl: |ssh| > 20 m  or  |U| > 10 m/s  or  S <= 0  or  S >= 100  or  NaN encounter in the tests'
-         WRITE(ctmp2,9100) kt,   zmax(1), ih(1) , ih(2)
-         WRITE(ctmp3,9200) kt,   zmax(2), iu(1) , iu(2) , iu(3)
-         WRITE(ctmp4,9300) kt, - zmax(3), is1(1), is1(2), is1(3)
-         WRITE(ctmp5,9400) kt,   zmax(4), is2(1), is2(2), is2(3)
+         WRITE(ctmp2,9100) kt, ' |ssh| max ',  zmax(1), iloc(1,1), iloc(2,1),            NINT(zarea(1))-1
+         WRITE(ctmp3,9200) kt, ' |U|   max ',  zmax(2), iloc(1,2), iloc(2,2), iloc(3,2), NINT(zarea(2))-1
+         WRITE(ctmp4,9200) kt, ' Sal   min ', -zmax(3), iloc(1,3), iloc(2,3), iloc(3,3), NINT(zarea(3))-1
+         WRITE(ctmp5,9200) kt, ' Sal   max ',  zmax(4), iloc(1,4), iloc(2,4), iloc(3,4), NINT(zarea(4))-1
          WRITE(ctmp6,*) '      ===> output of last computed fields in output.abort.nc file'
-         
+         !
          CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
-         
-         IF( .NOT. sn_cfctl%l_glochk ) THEN
-            WRITE(ctmp8,*) 'E R R O R message from sub-domain: ', narea
-            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp8, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ctmp6 )
-         ELSE
-            CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6, ' ' )
-         ENDIF
-
-         kindic = -3
-         !
-      ENDIF
-      !
-9100  FORMAT (' kt=',i8,'   |ssh| max: ',1pg11.4,', at  i j  : ',2i5)
-9200  FORMAT (' kt=',i8,'   |U|   max: ',1pg11.4,', at  i j k: ',3i5)
-9300  FORMAT (' kt=',i8,'   S     min: ',1pg11.4,', at  i j k: ',3i5)
-9400  FORMAT (' kt=',i8,'   S     max: ',1pg11.4,', at  i j k: ',3i5)
+         !
+         IF( ll_colruns ) THEN   ! all processes are synchronized -> use lwp to do the print in opened ocean.output files
+            IF(lwp)   CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 )
+         ELSE   ! only mpi subdomains with errors are here -> STOP now
+            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 )
+         ENDIF
+         !
+         IF( nstop == 0 )   nstop = 1 
+         !
+      ENDIF
+      !
+9100  FORMAT(' kt ',i8,a,1pg11.4,' at i j  ',2i6, 6x,' MPI rank',i6)
+9200  FORMAT(' kt ',i8,a,1pg11.4,' at i j k',2i6, i6,' MPI rank',i6)
 9500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16)
       !
