Index: branches/2016/dev_r6519_HPC_4/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90
===================================================================
--- branches/2016/dev_r6519_HPC_4/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 6748)
+++ branches/2016/dev_r6519_HPC_4/NEMOGCM/NEMO/OPA_SRC/DYN/dynspg_ts.F90	(revision 7037)
@@ -72,5 +72,4 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftnw, ftne   !: triad of coriolis parameter
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  ftsw, ftse   !: (only used with een vorticity scheme)
-
    !! Time filtered arrays at baroclinic time step:
    REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   un_adv , vn_adv     !: Advection vel. at "now" barocl. step
@@ -244,7 +243,10 @@
             CALL lbc_lnk( zwz, 'F', 1._wp )
             !
+!$OMP PARALLEL
+!$OMP WORKSHARE
             ftne(1,:) = 0._wp ; ftnw(1,:) = 0._wp ; ftse(1,:) = 0._wp ; ftsw(1,:) = 0._wp
-
-!$OMP PARALLEL DO schedule(static) private(jj, ji)
+!$OMP END WORKSHARE
+
+!$OMP DO schedule(static) private(jj, ji)
             DO jj = 2, jpj
                DO ji = 2, jpi
@@ -255,4 +257,6 @@
                END DO
             END DO
+!$OMP END DO NOWAIT
+!$OMP END PARALLEL
             !
          ELSE                                !== all other schemes (ENE, ENS, MIX)
@@ -272,8 +276,11 @@
 !              zhf(:,:) = gdepw_0(:,:,jk+1)
             ELSE
+!$OMP PARALLEL WORKSHARE
                zhf(:,:) = hbatf(:,:)
+!$OMP END PARALLEL WORKSHARE
             END IF
 
-!$OMP PARALLEL DO schedule(static) private(jj, ji)
+!$OMP PARALLEL
+!$OMP DO schedule(static) private(jj, ji)
             DO jj = 1, jpjm1
                DO ji = 1, jpi
@@ -283,5 +290,5 @@
 
             DO jk = 1, jpkm1
-!$OMP PARALLEL DO schedule(static) private(jj, ji)
+!$OMP DO schedule(static) private(jj, ji)
                DO jj = 1, jpjm1
                   DO ji = 1, jpi
@@ -289,8 +296,11 @@
                   END DO
                END DO
-            END DO
+!$OMP END DO NOWAIT
+            END DO
+!$OMP END PARALLEL
             CALL lbc_lnk( zhf, 'F', 1._wp )
             ! JC: TBC. hf should be greater than 0 
-!$OMP PARALLEL DO schedule(static) private(jj, ji)
+!$OMP PARALLEL 
+!$OMP DO schedule(static) private(jj, ji)
             DO jj = 1, jpj
                DO ji = 1, jpi
@@ -298,7 +308,8 @@
                END DO
             END DO
-!$OMP PARALLEL WORKSHARE
+!$OMP WORKSHARE
             zwz(:,:) = ff(:,:) * zwz(:,:)
-!$OMP END PARALLEL WORKSHARE
+!$OMP END WORKSHARE NOWAIT
+!$OMP END PARALLEL
          ENDIF
       ENDIF
@@ -318,27 +329,28 @@
       !                                   !* e3*d/dt(Ua) (Vertically integrated)
       !                                   ! --------------------------------------------------
-!$OMP PARALLEL WORKSHARE
+!$OMP PARALLEL
+!$OMP WORKSHARE
       zu_frc(:,:) = 0._wp
       zv_frc(:,:) = 0._wp
-!$OMP END PARALLEL WORKSHARE
+!$OMP END WORKSHARE
       !
       DO jk = 1, jpkm1
-!$OMP PARALLEL DO schedule(static) private(jj,ji)
-      DO jj=1,jpj
-         DO ji=1,jpi
-         zu_frc(ji,jj) = zu_frc(ji,jj) + e3u_n(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
-         zv_frc(ji,jj) = zv_frc(ji,jj) + e3v_n(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
-         END DO
-      END DO 
+!$OMP DO schedule(static) private(jj,ji)
+         DO jj=1,jpj
+            DO ji=1,jpi
+               zu_frc(ji,jj) = zu_frc(ji,jj) + e3u_n(ji,jj,jk) * ua(ji,jj,jk) * umask(ji,jj,jk)
+               zv_frc(ji,jj) = zv_frc(ji,jj) + e3v_n(ji,jj,jk) * va(ji,jj,jk) * vmask(ji,jj,jk)
+            END DO
+         END DO 
       END DO
       !
-!$OMP PARALLEL WORKSHARE
+!$OMP WORKSHARE
       zu_frc(:,:) = zu_frc(:,:) * r1_hu_n(:,:)
       zv_frc(:,:) = zv_frc(:,:) * r1_hv_n(:,:)
-!$OMP END PARALLEL WORKSHARE
+!$OMP END WORKSHARE
       !
       !
       !                                   !* baroclinic momentum trend (remove the vertical mean trend)
-!$OMP PARALLEL DO schedule(static) private(jk,jj,ji)
+!$OMP DO schedule(static) private(jk,jj,ji)
       DO jk = 1, jpkm1                    ! -----------------------------------------------------------
          DO jj = 2, jpjm1
@@ -349,10 +361,12 @@
          END DO
       END DO
+!$OMP END DO NOWAIT
       !                                   !* barotropic Coriolis trends (vorticity scheme dependent)
       !                                   ! --------------------------------------------------------
-!$OMP PARALLEL WORKSHARE
+!$OMP WORKSHARE
       zwx(:,:) = un_b(:,:) * hu_n(:,:) * e2u(:,:)        ! now fluxes 
       zwy(:,:) = vn_b(:,:) * hv_n(:,:) * e1v(:,:)
-!$OMP END PARALLEL WORKSHARE
+!$OMP END WORKSHARE NOWAIT
+!$OMP END PARALLEL
       !
       IF( ln_dynvor_ene .OR. ln_dynvor_mix ) THEN      ! energy conserving or mixed scheme
@@ -404,7 +418,10 @@
       IF( .NOT.ln_linssh ) THEN                 ! Variable volume : remove surface pressure gradient
         IF( ln_wd ) THEN                        ! Calculating and applying W/D gravity filters
+!$OMP PARALLEL
+!$OMP WORKSHARE
           wduflt1(:,:) = 1.0_wp
           wdvflt1(:,:) = 1.0_wp
-!$OMP PARALLEL DO schedule(static) private(jj,ji,ll_tmp1,ll_tmp2)
+!$OMP END WORKSHARE
+!$OMP DO schedule(static) private(jj,ji,ll_tmp1,ll_tmp2)
           DO jj = 2, jpjm1
              DO ji = 2, jpim1
@@ -443,4 +460,6 @@
              END DO
            END DO
+!$OMP END DO NOWAIT
+!$OMP END PARALLEL
 
            CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
@@ -502,9 +521,16 @@
       ! Note that the "unclipped" bottom friction parameter is used even with explicit drag
       IF( ln_wd ) THEN
-        zu_frc(:,:) = zu_frc(:,:) + MAX(r1_hu_n(:,:) * bfrua(:,:),-1._wp / rdtbt) * zwx(:,:)
-        zv_frc(:,:) = zv_frc(:,:) + MAX(r1_hv_n(:,:) * bfrva(:,:),-1._wp / rdtbt) * zwy(:,:)
+!$OMP PARALLEL DO schedule(static) private(jj,ji)
+         DO jj = 1, jpj
+            DO ji = 1, jpi   ! vector opt.
+               zu_frc(ji,jj) = zu_frc(ji,jj) + MAX(r1_hu_n(ji,jj) * bfrua(ji,jj),-1._wp / rdtbt) * zwx(ji,jj)
+               zv_frc(ji,jj) = zv_frc(ji,jj) + MAX(r1_hv_n(ji,jj) * bfrva(ji,jj),-1._wp / rdtbt) * zwy(ji,jj)
+            END DO
+         END DO
       ELSE
+!$OMP PARALLEL WORKSHARE
         zu_frc(:,:) = zu_frc(:,:) + r1_hu_n(:,:) * bfrua(:,:) * zwx(:,:)
         zv_frc(:,:) = zv_frc(:,:) + r1_hv_n(:,:) * bfrva(:,:) * zwy(:,:)
+!$OMP END PARALLEL WORKSHARE
       END IF
       !
@@ -579,13 +605,19 @@
       !                                         ! Surface net water flux and rivers
       IF (ln_bt_fw) THEN
+!$OMP PARALLEL WORKSHARE
          zssh_frc(:,:) = zraur * ( emp(:,:) - rnf(:,:) + fwfisf(:,:) )
+!$OMP END PARALLEL WORKSHARE
       ELSE
+!$OMP PARALLEL WORKSHARE
          zssh_frc(:,:) = zraur * z1_2 * (  emp(:,:) + emp_b(:,:) - rnf(:,:) - rnf_b(:,:)   &
                 &                        + fwfisf(:,:) + fwfisf_b(:,:)                     )
+!$OMP END PARALLEL WORKSHARE
       ENDIF
 #if defined key_asminc
       !                                         ! Include the IAU weighted SSH increment
       IF( lk_asminc .AND. ln_sshinc .AND. ln_asmiau ) THEN
+!$OMP PARALLEL WORKSHARE
          zssh_frc(:,:) = zssh_frc(:,:) - ssh_iau(:,:)
+!$OMP END PARALLEL WORKSHARE
       ENDIF
 #endif
@@ -617,8 +649,11 @@
       IF( ln_wd ) THEN      !preserve the positivity of water depth
                           !ssh[b,n,a] should have already been processed for this
-!$OMP PARALLEL WORKSHARE
-         sshbb_e(:,:) = MAX(sshbb_e(:,:), rn_wdmin1 - bathy(:,:))
-         sshb_e(:,:)  = MAX(sshb_e(:,:) , rn_wdmin1 - bathy(:,:))
-!$OMP END PARALLEL WORKSHARE
+!$OMP PARALLEL DO schedule(static) private(jj,ji)
+         DO jj = 1, jpj
+            DO ji = 1, jpi   ! vector opt.
+               sshbb_e(ji,jj) = MAX(sshbb_e(ji,jj), rn_wdmin1 - bathy(ji,jj))
+               sshb_e(ji,jj)  = MAX(sshb_e(ji,jj) , rn_wdmin1 - bathy(ji,jj))
+            END DO
+         END DO
       ENDIF
       !
@@ -688,7 +723,10 @@
             !                                             !  ------------------
             ! Extrapolate Sea Level at step jit+0.5:
+!$OMP PARALLEL 
+!$OMP WORKSHARE
             zsshp2_e(:,:) = za1 * sshn_e(:,:)  + za2 * sshb_e(:,:) + za3 * sshbb_e(:,:)
+!$OMP END WORKSHARE
             !
-!$OMP PARALLEL DO schedule(static) private(jj,ji)
+!$OMP DO schedule(static) private(jj,ji)
             DO jj = 2, jpjm1                                    ! Sea Surface Height at u- & v-points
                DO ji = 2, fs_jpim1   ! Vector opt.
@@ -701,4 +739,6 @@
                END DO
             END DO
+!$OMP END DO NOWAIT
+!$OMP END PARALLEL 
             CALL lbc_lnk_multi( zwx, 'U', 1._wp, zwy, 'V', 1._wp )
             !
@@ -708,6 +748,11 @@
 !$OMP END PARALLEL WORKSHARE
             IF( ln_wd ) THEN
-              zhup2_e(:,:) = MAX(zhup2_e (:,:), rn_wdmin1)
-              zhvp2_e(:,:) = MAX(zhvp2_e (:,:), rn_wdmin1)
+!$OMP PARALLEL DO schedule(static) private(jj,ji)
+            DO jj = 1, jpj
+               DO ji = 1, jpi   ! vector opt.
+                  zhup2_e(ji,jj) = MAX(zhup2_e (ji,jj), rn_wdmin1)
+                  zhvp2_e(ji,jj) = MAX(zhvp2_e (ji,jj), rn_wdmin1)
+               END DO
+            END DO
             END IF
          ELSE
@@ -756,11 +801,12 @@
          ! Sum over sub-time-steps to compute advective velocities
          za2 = wgtbtp2(jn)
-!$OMP PARALLEL WORKSHARE
+!$OMP PARALLEL
+!$OMP WORKSHARE
          un_adv(:,:) = un_adv(:,:) + za2 * zwx(:,:) * r1_e2u(:,:)
          vn_adv(:,:) = vn_adv(:,:) + za2 * zwy(:,:) * r1_e1v(:,:)
-!$OMP END PARALLEL WORKSHARE
+!$OMP END WORKSHARE NOWAIT
          !
          ! Set next sea level:
-!$OMP PARALLEL DO schedule(static) private(jj,ji)
+!$OMP DO schedule(static) private(jj,ji)
          DO jj = 2, jpjm1                                 
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -769,8 +815,16 @@
             END DO
          END DO
-!$OMP PARALLEL WORKSHARE
+!$OMP WORKSHARE
          ssha_e(:,:) = (  sshn_e(:,:) - rdtbt * ( zssh_frc(:,:) + zhdiv(:,:) )  ) * ssmask(:,:)
-!$OMP END PARALLEL WORKSHARE
-         IF( ln_wd ) ssha_e(:,:) = MAX(ssha_e(:,:), rn_wdmin1 - bathy(:,:)) 
+!$OMP END WORKSHARE NOWAIT
+!$OMP END PARALLEL
+         IF( ln_wd ) THEN
+!$OMP PARALLEL DO schedule(static) private(jj,ji)
+            DO jj = 1, jpj
+               DO ji = 1, jpi   ! vector opt.
+                  ssha_e(ji,jj) = MAX(ssha_e(ji,jj), rn_wdmin1 - bathy(ji,jj))
+               END DO
+            END DO
+         END IF 
          CALL lbc_lnk( ssha_e, 'T',  1._wp )
 
@@ -821,7 +875,10 @@
           &            + za2 *  sshb_e(:,:) + za3 *  sshbb_e(:,:)
          IF( ln_wd ) THEN                   ! Calculating and applying W/D gravity filters
+!$OMP PARALLEL
+!$OMP WORKSHARE
            wduflt1(:,:) = 1._wp
            wdvflt1(:,:) = 1._wp
-!$OMP PARALLEL DO schedule(static) private(jj,ji,ll_tmp1,ll_tmp2)
+!$OMP END WORKSHARE
+!$OMP DO schedule(static) private(jj,ji,ll_tmp1,ll_tmp2)
            DO jj = 2, jpjm1
               DO ji = 2, jpim1
@@ -859,4 +916,6 @@
               END DO
             END DO
+!$OMP END DO NOWAIT
+!$OMP END PARALLEL
             CALL lbc_lnk( zcpx, 'U', 1._wp )    ;   CALL lbc_lnk( zcpy, 'V', 1._wp )
          ENDIF
@@ -880,6 +939,11 @@
 
             IF( ln_wd ) THEN
-              zhust_e(:,:) = MAX(zhust_e (:,:), rn_wdmin1 )
-              zhvst_e(:,:) = MAX(zhvst_e (:,:), rn_wdmin1 )
+!$OMP PARALLEL DO schedule(static) private(jj,ji)
+            DO jj = 1, jpj
+               DO ji = 1, jpi   ! vector opt.
+                  zhust_e(ji,jj) = MAX(zhust_e (ji,jj), rn_wdmin1 )
+                  zhvst_e(ji,jj) = MAX(zhvst_e (ji,jj), rn_wdmin1 )
+               END DO
+            END DO
             END IF
 
@@ -953,8 +1017,6 @@
          zu_trd(:,:) = zu_trd(:,:) + bfrua(:,:) * un_e(:,:) * hur_e(:,:)
          zv_trd(:,:) = zv_trd(:,:) + bfrva(:,:) * vn_e(:,:) * hvr_e(:,:)
-!$OMP END PARALLEL WORKSHARE
          !
          ! Add top stresses:
-!$OMP PARALLEL WORKSHARE
          zu_trd(:,:) = zu_trd(:,:) + tfrua(:,:) * un_e(:,:) * hur_e(:,:)
          zv_trd(:,:) = zv_trd(:,:) + tfrva(:,:) * vn_e(:,:) * hvr_e(:,:)
@@ -1039,6 +1101,11 @@
          IF( .NOT.ln_linssh ) THEN                     !* Update ocean depth (variable volume case only)
             IF( ln_wd ) THEN
-              hu_e (:,:) = MAX(hu_0(:,:) + zsshu_a(:,:), rn_wdmin1)
-              hv_e (:,:) = MAX(hv_0(:,:) + zsshv_a(:,:), rn_wdmin1)
+!$OMP PARALLEL DO schedule(static) private(jj,ji)
+            DO jj = 1, jpj
+               DO ji = 1, jpi   ! vector opt.
+                  hu_e (ji,jj) = MAX(hu_0(ji,jj) + zsshu_a(ji,jj), rn_wdmin1)
+                  hv_e (ji,jj) = MAX(hv_0(ji,jj) + zsshv_a(ji,jj), rn_wdmin1)
+               END DO
+            END DO
             ELSE
 !$OMP PARALLEL WORKSHARE
@@ -1150,14 +1217,17 @@
          CALL lbc_lnk_multi( zsshu_a, 'U', 1._wp, zsshv_a, 'V', 1._wp ) ! Boundary conditions
          !
-!$OMP PARALLEL DO schedule(static) private(jk)
+!$OMP PARALLEL
+!$OMP DO schedule(static) private(jk)
          DO jk=1,jpkm1
             ua(:,:,jk) = ua(:,:,jk) + r1_hu_n(:,:) * ( ua_b(:,:) - ub_b(:,:) * hu_b(:,:) ) * z1_2dt_b
             va(:,:,jk) = va(:,:,jk) + r1_hv_n(:,:) * ( va_b(:,:) - vb_b(:,:) * hv_b(:,:) ) * z1_2dt_b
          END DO
+!$OMP END DO NOWAIT
          ! Save barotropic velocities not transport:
-!$OMP PARALLEL WORKSHARE
+!$OMP WORKSHARE
          ua_b(:,:) =  ua_b(:,:) / ( hu_0(:,:) + zsshu_a(:,:) + 1._wp - ssumask(:,:) )
          va_b(:,:) =  va_b(:,:) / ( hv_0(:,:) + zsshv_a(:,:) + 1._wp - ssvmask(:,:) )
-!$OMP END PARALLEL WORKSHARE
+!$OMP END WORKSHARE NOWAIT
+!$OMP END PARALLEL
       ENDIF
       !
@@ -1179,11 +1249,15 @@
       IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) THEN
          IF( Agrif_NbStepint() == 0 ) THEN
+!$OMP PARALLEL WORKSHARE
             ub2_i_b(:,:) = 0._wp
             vb2_i_b(:,:) = 0._wp
+!$OMP END PARALLEL WORKSHARE
          END IF
          !
          za1 = 1._wp / REAL(Agrif_rhot(), wp)
+!$OMP PARALLEL WORKSHARE
          ub2_i_b(:,:) = ub2_i_b(:,:) + za1 * ub2_b(:,:)
          vb2_i_b(:,:) = vb2_i_b(:,:) + za1 * vb2_b(:,:)
+!$OMP END PARALLEL WORKSHARE
       ENDIF
 #endif      
