Index: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/ICB/icblbc.F90
===================================================================
--- NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/ICB/icblbc.F90	(revision 14197)
+++ NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/ICB/icblbc.F90	(revision 14644)
@@ -36,5 +36,5 @@
    PRIVATE
 
-#if defined key_mpp_mpi
+#if ! defined key_mpi_off
 
 !$AGRIF_DO_NOT_TREAT
@@ -105,5 +105,5 @@
       IF( l_Jperio)      CALL ctl_stop(' north-south periodicity not implemented for icebergs')
       ! north fold
-      IF( npolj /= 0 )   CALL icb_lbc_nfld()
+      IF( l_IdoNFold )   CALL icb_lbc_nfld()
       !
    END SUBROUTINE icb_lbc
@@ -145,7 +145,7 @@
    END SUBROUTINE icb_lbc_nfld
 
-#if defined key_mpp_mpi
+#if ! defined key_mpi_off
    !!----------------------------------------------------------------------
-   !!   'key_mpp_mpi'             MPI massively parallel processing library
+   !!            MPI massively parallel processing library
    !!----------------------------------------------------------------------
 
@@ -179,11 +179,11 @@
       ipe_W = -1
       ipe_E = -1
-      IF( nbondi .EQ.  0 .OR. nbondi .EQ. 1) ipe_W = nowe
-      IF( nbondi .EQ. -1 .OR. nbondi .EQ. 0) ipe_E = noea
-      IF( nbondj .EQ.  0 .OR. nbondj .EQ. 1) ipe_S = noso
-      IF( nbondj .EQ. -1 .OR. nbondj .EQ. 0) ipe_N = nono
+      IF( mpinei(jpwe) >= 0 ) ipe_W = mpinei(jpwe)
+      IF( mpinei(jpea) >= 0 ) ipe_E = mpinei(jpea)
+      IF( mpinei(jpso) >= 0 ) ipe_S = mpinei(jpso)
+      IF( mpinei(jpno) >= 0 ) ipe_N = mpinei(jpno)
       !
       ! at northern line of processors with north fold handle bergs differently
-      IF( npolj > 0 ) ipe_N = -1
+      IF( l_IdoNFold )   ipe_N = -1
 
       ! if there's only one processor in x direction then don't let mpp try to handle periodicity
@@ -200,6 +200,4 @@
          WRITE(numicb,*) 'processor nimpp : ', nimpp
          WRITE(numicb,*) 'processor njmpp : ', njmpp
-         WRITE(numicb,*) 'processor nbondi: ', nbondi
-         WRITE(numicb,*) 'processor nbondj: ', nbondj
          CALL flush( numicb )
       ENDIF
@@ -271,91 +269,46 @@
       ! pattern here is copied from lib_mpp code
 
-      SELECT CASE ( nbondi )
-      CASE( -1 )
-         zwebergs(1) = ibergs_to_send_e
-         CALL mppsend( 12, zwebergs(1), 1, ipe_E, iml_req1)
-         CALL mpprecv( 11, zewbergs(2), 1, ipe_E )
-         CALL mpi_wait( iml_req1, iml_stat, iml_err )
-         ibergs_rcvd_from_e = INT( zewbergs(2) )
-      CASE(  0 )
-         zewbergs(1) = ibergs_to_send_w
-         zwebergs(1) = ibergs_to_send_e
-         CALL mppsend( 11, zewbergs(1), 1, ipe_W, iml_req2)
-         CALL mppsend( 12, zwebergs(1), 1, ipe_E, iml_req3)
-         CALL mpprecv( 11, zewbergs(2), 1, ipe_E )
-         CALL mpprecv( 12, zwebergs(2), 1, ipe_W )
-         CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         CALL mpi_wait( iml_req3, iml_stat, iml_err )
-         ibergs_rcvd_from_e = INT( zewbergs(2) )
-         ibergs_rcvd_from_w = INT( zwebergs(2) )
-      CASE(  1 )
-         zewbergs(1) = ibergs_to_send_w
-         CALL mppsend( 11, zewbergs(1), 1, ipe_W, iml_req4)
-         CALL mpprecv( 12, zwebergs(2), 1, ipe_W )
-         CALL mpi_wait( iml_req4, iml_stat, iml_err )
-         ibergs_rcvd_from_w = INT( zwebergs(2) )
-      END SELECT
+      IF( mpinei(jpwe) >= 0  )   zewbergs(1) = ibergs_to_send_w
+      IF( mpinei(jpea) >= 0  )   zwebergs(1) = ibergs_to_send_e
+      IF( mpinei(jpwe) >= 0  )   CALL mppsend( 11, zewbergs(1), 1, ipe_W, iml_req2)
+      IF( mpinei(jpea) >= 0  )   CALL mppsend( 12, zwebergs(1), 1, ipe_E, iml_req3)
+      IF( mpinei(jpea) >= 0  )   CALL mpprecv( 11, zewbergs(2), 1, ipe_E )
+      IF( mpinei(jpwe) >= 0  )   CALL mpprecv( 12, zwebergs(2), 1, ipe_W )
+      IF( mpinei(jpwe) >= 0  )   CALL mpi_wait( iml_req2, iml_stat, iml_err )
+      IF( mpinei(jpea) >= 0  )   CALL mpi_wait( iml_req3, iml_stat, iml_err )
+      IF( mpinei(jpea) >= 0  )   ibergs_rcvd_from_e = INT( zewbergs(2) )
+      IF( mpinei(jpwe) >= 0  )   ibergs_rcvd_from_w = INT( zwebergs(2) )
+      
       IF( nn_verbose_level >= 3) THEN
          WRITE(numicb,*) 'bergstep ',nktberg,' recv ew: ', ibergs_rcvd_from_w, ibergs_rcvd_from_e
          CALL flush(numicb)
       ENDIF
-
-      SELECT CASE ( nbondi )
-      CASE( -1 )
-         IF( ibergs_to_send_e > 0 ) CALL mppsend( 14, obuffer_e%data, ibergs_to_send_e*jp_buffer_width, ipe_E, iml_req1 )
-         IF( ibergs_rcvd_from_e > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_e, ibergs_rcvd_from_e)
-            CALL mpprecv( 13, ibuffer_e%data, ibergs_rcvd_from_e*jp_buffer_width )
-         ENDIF
-         IF( ibergs_to_send_e > 0 ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
-         DO i = 1, ibergs_rcvd_from_e
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_e%data(16,i)),' from east'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_e, i)
-         ENDDO
-      CASE(  0 )
-         IF( ibergs_to_send_w > 0 ) CALL mppsend( 13, obuffer_w%data, ibergs_to_send_w*jp_buffer_width, ipe_W, iml_req2 )
-         IF( ibergs_to_send_e > 0 ) CALL mppsend( 14, obuffer_e%data, ibergs_to_send_e*jp_buffer_width, ipe_E, iml_req3 )
-         IF( ibergs_rcvd_from_e > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_e, ibergs_rcvd_from_e)
-            CALL mpprecv( 13, ibuffer_e%data, ibergs_rcvd_from_e*jp_buffer_width )
-         ENDIF
-         IF( ibergs_rcvd_from_w > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_w, ibergs_rcvd_from_w)
-            CALL mpprecv( 14, ibuffer_w%data, ibergs_rcvd_from_w*jp_buffer_width )
-         ENDIF
-         IF( ibergs_to_send_w > 0 ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         IF( ibergs_to_send_e > 0 ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
-         DO i = 1, ibergs_rcvd_from_e
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_e%data(16,i)),' from east'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_e, i)
-         END DO
-         DO i = 1, ibergs_rcvd_from_w
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_w%data(16,i)),' from west'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_w, i)
-         ENDDO
-      CASE(  1 )
-         IF( ibergs_to_send_w > 0 ) CALL mppsend( 13, obuffer_w%data, ibergs_to_send_w*jp_buffer_width, ipe_W, iml_req4 )
-         IF( ibergs_rcvd_from_w > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_w, ibergs_rcvd_from_w)
-            CALL mpprecv( 14, ibuffer_w%data, ibergs_rcvd_from_w*jp_buffer_width )
-         ENDIF
-         IF( ibergs_to_send_w > 0 ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
-         DO i = 1, ibergs_rcvd_from_w
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_w%data(16,i)),' from west'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_w, i)
-         END DO
-      END SELECT
+      
+      IF( ibergs_to_send_w > 0 ) CALL mppsend( 13, obuffer_w%data, ibergs_to_send_w*jp_buffer_width, ipe_W, iml_req2 )
+      IF( ibergs_to_send_e > 0 ) CALL mppsend( 14, obuffer_e%data, ibergs_to_send_e*jp_buffer_width, ipe_E, iml_req3 )
+      IF( ibergs_rcvd_from_e > 0 ) THEN
+         CALL icb_increase_ibuffer(ibuffer_e, ibergs_rcvd_from_e)
+         CALL mpprecv( 13, ibuffer_e%data, ibergs_rcvd_from_e*jp_buffer_width )
+      ENDIF
+      IF( ibergs_rcvd_from_w > 0 ) THEN
+         CALL icb_increase_ibuffer(ibuffer_w, ibergs_rcvd_from_w)
+         CALL mpprecv( 14, ibuffer_w%data, ibergs_rcvd_from_w*jp_buffer_width )
+      ENDIF
+      IF( ibergs_to_send_w > 0 ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
+      IF( ibergs_to_send_e > 0 ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
+      DO i = 1, ibergs_rcvd_from_e
+         IF( nn_verbose_level >= 4 ) THEN
+            WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_e%data(16,i)),' from east'
+            CALL FLUSH( numicb )
+         ENDIF
+         CALL icb_unpack_from_buffer(first_berg, ibuffer_e, i)
+      END DO
+      DO i = 1, ibergs_rcvd_from_w
+         IF( nn_verbose_level >= 4 ) THEN
+            WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_w%data(16,i)),' from west'
+            CALL FLUSH( numicb )
+         ENDIF
+         CALL icb_unpack_from_buffer(first_berg, ibuffer_w, i)
+      END DO
 
       ! Find number of bergs that headed north/south
@@ -400,93 +353,48 @@
       ! send bergs north
       ! and receive bergs from south (ie ones sent north)
-
-      SELECT CASE ( nbondj )
-      CASE( -1 )
-         zsnbergs(1) = ibergs_to_send_n
-         CALL mppsend( 16, zsnbergs(1), 1, ipe_N, iml_req1)
-         CALL mpprecv( 15, znsbergs(2), 1, ipe_N )
-         CALL mpi_wait( iml_req1, iml_stat, iml_err )
-         ibergs_rcvd_from_n = INT( znsbergs(2) )
-      CASE(  0 )
-         znsbergs(1) = ibergs_to_send_s
-         zsnbergs(1) = ibergs_to_send_n
-         CALL mppsend( 15, znsbergs(1), 1, ipe_S, iml_req2)
-         CALL mppsend( 16, zsnbergs(1), 1, ipe_N, iml_req3)
-         CALL mpprecv( 15, znsbergs(2), 1, ipe_N )
-         CALL mpprecv( 16, zsnbergs(2), 1, ipe_S )
-         CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         CALL mpi_wait( iml_req3, iml_stat, iml_err )
-         ibergs_rcvd_from_n = INT( znsbergs(2) )
-         ibergs_rcvd_from_s = INT( zsnbergs(2) )
-      CASE(  1 )
-         znsbergs(1) = ibergs_to_send_s
-         CALL mppsend( 15, znsbergs(1), 1, ipe_S, iml_req4)
-         CALL mpprecv( 16, zsnbergs(2), 1, ipe_S )
-         CALL mpi_wait( iml_req4, iml_stat, iml_err )
-         ibergs_rcvd_from_s = INT( zsnbergs(2) )
-      END SELECT
-      if( nn_verbose_level >= 3) then
-         write(numicb,*) 'bergstep ',nktberg,' recv ns: ', ibergs_rcvd_from_s, ibergs_rcvd_from_n
-         call flush(numicb)
-      endif
-
-      SELECT CASE ( nbondj )
-      CASE( -1 )
-         IF( ibergs_to_send_n > 0 ) CALL mppsend( 18, obuffer_n%data, ibergs_to_send_n*jp_buffer_width, ipe_N, iml_req1 )
-         IF( ibergs_rcvd_from_n > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_n, ibergs_rcvd_from_n)
-            CALL mpprecv( 17, ibuffer_n%data, ibergs_rcvd_from_n*jp_buffer_width )
-         ENDIF
-         IF( ibergs_to_send_n > 0 ) CALL mpi_wait( iml_req1, iml_stat, iml_err )
-         DO i = 1, ibergs_rcvd_from_n
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_n%data(16,i)),' from north'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_n, i)
-         END DO
-      CASE(  0 )
-         IF( ibergs_to_send_s > 0 ) CALL mppsend( 17, obuffer_s%data, ibergs_to_send_s*jp_buffer_width, ipe_S, iml_req2 )
-         IF( ibergs_to_send_n > 0 ) CALL mppsend( 18, obuffer_n%data, ibergs_to_send_n*jp_buffer_width, ipe_N, iml_req3 )
-         IF( ibergs_rcvd_from_n > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_n, ibergs_rcvd_from_n)
-            CALL mpprecv( 17, ibuffer_n%data, ibergs_rcvd_from_n*jp_buffer_width )
-         ENDIF
-         IF( ibergs_rcvd_from_s > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_s, ibergs_rcvd_from_s)
-            CALL mpprecv( 18, ibuffer_s%data, ibergs_rcvd_from_s*jp_buffer_width )
-         ENDIF
-         IF( ibergs_to_send_s > 0 ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
-         IF( ibergs_to_send_n > 0 ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
-         DO i = 1, ibergs_rcvd_from_n
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_n%data(16,i)),' from north'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_n, i)
-         END DO
-         DO i = 1, ibergs_rcvd_from_s
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_s%data(16,i)),' from south'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_s, i)
-         ENDDO
-      CASE(  1 )
-         IF( ibergs_to_send_s > 0 ) CALL mppsend( 17, obuffer_s%data, ibergs_to_send_s*jp_buffer_width, ipe_S, iml_req4 )
-         IF( ibergs_rcvd_from_s > 0 ) THEN
-            CALL icb_increase_ibuffer(ibuffer_s, ibergs_rcvd_from_s)
-            CALL mpprecv( 18, ibuffer_s%data, ibergs_rcvd_from_s*jp_buffer_width )
-         ENDIF
-         IF( ibergs_to_send_s > 0 ) CALL mpi_wait( iml_req4, iml_stat, iml_err )
-         DO i = 1, ibergs_rcvd_from_s
-            IF( nn_verbose_level >= 4 ) THEN
-               WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_s%data(16,i)),' from south'
-               CALL flush( numicb )
-            ENDIF
-            CALL icb_unpack_from_buffer(first_berg, ibuffer_s, i)
-         END DO
-      END SELECT
-
+      
+      IF( mpinei(jpso) >= 0  )   znsbergs(1) = ibergs_to_send_s
+      IF( mpinei(jpno) >= 0  )   zsnbergs(1) = ibergs_to_send_n
+      IF( mpinei(jpso) >= 0  )   CALL mppsend( 15, znsbergs(1), 1, ipe_S, iml_req2)
+      IF( mpinei(jpno) >= 0  )   CALL mppsend( 16, zsnbergs(1), 1, ipe_N, iml_req3)
+      IF( mpinei(jpno) >= 0  )   CALL mpprecv( 15, znsbergs(2), 1, ipe_N )
+      IF( mpinei(jpso) >= 0  )   CALL mpprecv( 16, zsnbergs(2), 1, ipe_S )
+      IF( mpinei(jpso) >= 0  )   CALL mpi_wait( iml_req2, iml_stat, iml_err )
+      IF( mpinei(jpno) >= 0  )   CALL mpi_wait( iml_req3, iml_stat, iml_err )
+      IF( mpinei(jpno) >= 0  )   ibergs_rcvd_from_n = INT( znsbergs(2) )
+      IF( mpinei(jpso) >= 0  )   ibergs_rcvd_from_s = INT( zsnbergs(2) )
+      
+      IF( nn_verbose_level >= 3) THEN
+         WRITE(numicb,*) 'bergstep ',nktberg,' recv ns: ', ibergs_rcvd_from_s, ibergs_rcvd_from_n
+         CALL FLUSH(numicb)
+      ENDIF
+
+      IF( ibergs_to_send_s > 0 ) CALL mppsend( 17, obuffer_s%data, ibergs_to_send_s*jp_buffer_width, ipe_S, iml_req2 )
+      IF( ibergs_to_send_n > 0 ) CALL mppsend( 18, obuffer_n%data, ibergs_to_send_n*jp_buffer_width, ipe_N, iml_req3 )
+      IF( ibergs_rcvd_from_n > 0 ) THEN
+         CALL icb_increase_ibuffer(ibuffer_n, ibergs_rcvd_from_n)
+         CALL mpprecv( 17, ibuffer_n%data, ibergs_rcvd_from_n*jp_buffer_width )
+      ENDIF
+      IF( ibergs_rcvd_from_s > 0 ) THEN
+         CALL icb_increase_ibuffer(ibuffer_s, ibergs_rcvd_from_s)
+         CALL mpprecv( 18, ibuffer_s%data, ibergs_rcvd_from_s*jp_buffer_width )
+      ENDIF
+      IF( ibergs_to_send_s > 0 ) CALL mpi_wait( iml_req2, iml_stat, iml_err )
+      IF( ibergs_to_send_n > 0 ) CALL mpi_wait( iml_req3, iml_stat, iml_err )
+      DO i = 1, ibergs_rcvd_from_n
+         IF( nn_verbose_level >= 4 ) THEN
+            WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_n%data(16,i)),' from north'
+            CALL FLUSH( numicb )
+         ENDIF
+         CALL icb_unpack_from_buffer(first_berg, ibuffer_n, i)
+      END DO
+      DO i = 1, ibergs_rcvd_from_s
+         IF( nn_verbose_level >= 4 ) THEN
+            WRITE(numicb,*) 'bergstep ',nktberg,' unpacking berg ',INT(ibuffer_s%data(16,i)),' from south'
+            CALL FLUSH( numicb )
+         ENDIF
+         CALL icb_unpack_from_buffer(first_berg, ibuffer_s, i)
+      END DO
+      
       IF( nn_verbose_level > 0 ) THEN
          ! compare the number of icebergs on this processor from the start to the end
@@ -527,5 +435,5 @@
       ! deal with north fold if we necessary when there is more than one top row processor
       ! note that for jpni=1 north fold has been dealt with above in call to icb_lbc
-      IF( npolj /= 0 .AND. jpni > 1 ) CALL icb_lbc_mpp_nfld( )
+      IF( l_IdoNFold .AND. jpni > 1 ) CALL icb_lbc_mpp_nfld( )
 
       IF( nn_verbose_level > 0 ) THEN
