Ignore:
Timestamp:
2020-01-27T15:31:53+01:00 (18 months ago)
Author:
acc
Message:

Branch 2019/dev_r11943_MERGE_2019. This commit introduces basic do loop macro
substitution to the 2019 option 1, merge branch. These changes have been SETTE
tested. The only addition is the do_loop_substitute.h90 file in the OCE directory but
the macros defined therein are used throughout the code to replace identifiable, 2D-
and 3D- nested loop opening and closing statements with single-line alternatives. Code
indents are also adjusted accordingly.

The following explanation is taken from comments in the new header file:

This header file contains preprocessor definitions and macros used in the do-loop
substitutions introduced between version 4.0 and 4.2. The primary aim of these macros
is to assist in future applications of tiling to improve performance. This is expected
to be achieved by alternative versions of these macros in selected locations. The
initial introduction of these macros simply replaces all identifiable nested 2D- and
3D-loops with single line statements (and adjusts indenting accordingly). Do loops
are identifiable if they comform to either:

DO jk = ….

DO jj = …. DO jj = …

DO ji = …. DO ji = …
. OR .
. .

END DO END DO

END DO END DO

END DO

and white-space variants thereof.

Additionally, only loops with recognised jj and ji loops limits are treated; these are:
Lower limits of 1, 2 or fs_2
Upper limits of jpi, jpim1 or fs_jpim1 (for ji) or jpj, jpjm1 or fs_jpjm1 (for jj)

The macro naming convention takes the form: DO_2D_BT_LR where:

B is the Bottom offset from the PE's inner domain;
T is the Top offset from the PE's inner domain;
L is the Left offset from the PE's inner domain;
R is the Right offset from the PE's inner domain

So, given an inner domain of 2,jpim1 and 2,jpjm1, a typical example would replace:

DO jj = 2, jpj

DO ji = 1, jpim1
.
.

END DO

END DO

with:

DO_2D_01_10
.
.
END_2D

similar conventions apply to the 3D loops macros. jk loop limits are retained
through macro arguments and are not restricted. This includes the possibility of
strides for which an extra set of DO_3DS macros are defined.

In the example definition below the inner PE domain is defined by start indices of
(kIs, kJs) and end indices of (kIe, KJe)

#define DO_2D_00_00 DO jj = kJs, kJe ; DO ji = kIs, kIe
#define END_2D END DO ; END DO

TO DO:


Only conventional nested loops have been identified and replaced by this step. There are constructs such as:

DO jk = 2, jpkm1

z2d(:,:) = z2d(:,:) + e3w(:,:,jk,Kmm) * z3d(:,:,jk) * wmask(:,:,jk)

END DO

which may need to be considered.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2019/dev_r11943_MERGE_2019/src/OFF/dtadyn.F90

    r12250 r12340  
    8989   INTEGER, SAVE  :: nprevrec, nsecdyn 
    9090 
     91   !! * Substitutions 
     92#  include "do_loop_substitute.h90" 
    9193   !!---------------------------------------------------------------------- 
    9294   !! NEMO/OFF 4.0 , NEMO Consortium (2018) 
     
    350352        gdepw(:,:,1,Kmm) = 0.0_wp 
    351353 
    352         DO jk = 2, jpk 
    353            DO jj = 1,jpj 
    354               DO ji = 1,jpi 
    355                 !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere 
    356                 !    tmask = wmask, ie everywhere expect at jk = mikt 
    357                                                                    ! 1 for jk = 
    358                                                                    ! mikt 
    359                  zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk)) 
    360                  gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm) 
    361                  gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  & 
    362                      &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) + e3w(ji,jj,jk,Kmm)) 
    363               END DO 
    364            END DO 
    365         END DO 
     354        DO_3D_11_11( 2, jpk ) 
     355          !    zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk))   ! 0 everywhere 
     356          !    tmask = wmask, ie everywhere expect at jk = mikt 
     357                                                             ! 1 for jk = 
     358                                                             ! mikt 
     359           zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk)) 
     360           gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm) 
     361           gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  & 
     362               &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) + e3w(ji,jj,jk,Kmm)) 
     363        END_3D 
    366364 
    367365        gdept(:,:,:,Kbb) = gdept(:,:,:,Kmm) 
     
    378376         ! 
    379377         nk_rnf(:,:) = 0                               ! set the number of level over which river runoffs are applied 
    380          DO jj = 1, jpj 
    381             DO ji = 1, jpi 
    382                IF( h_rnf(ji,jj) > 0._wp ) THEN 
    383                   jk = 2 
    384                   DO WHILE ( jk /= mbkt(ji,jj) .AND. gdept_0(ji,jj,jk) < h_rnf(ji,jj) ) ;  jk = jk + 1 
    385                   END DO 
    386                   nk_rnf(ji,jj) = jk 
    387                ELSEIF( h_rnf(ji,jj) == -1._wp   ) THEN   ;  nk_rnf(ji,jj) = 1 
    388                ELSEIF( h_rnf(ji,jj) == -999._wp ) THEN   ;  nk_rnf(ji,jj) = mbkt(ji,jj) 
    389                ELSE 
    390                   CALL ctl_stop( 'sbc_rnf_init: runoff depth not positive, and not -999 or -1, rnf value in file fort.999'  ) 
    391                   WRITE(999,*) 'ji, jj, h_rnf(ji,jj) :', ji, jj, h_rnf(ji,jj) 
    392                ENDIF 
     378         DO_2D_11_11 
     379            IF( h_rnf(ji,jj) > 0._wp ) THEN 
     380               jk = 2 
     381               DO WHILE ( jk /= mbkt(ji,jj) .AND. gdept_0(ji,jj,jk) < h_rnf(ji,jj) ) ;  jk = jk + 1 
     382               END DO 
     383               nk_rnf(ji,jj) = jk 
     384            ELSEIF( h_rnf(ji,jj) == -1._wp   ) THEN   ;  nk_rnf(ji,jj) = 1 
     385            ELSEIF( h_rnf(ji,jj) == -999._wp ) THEN   ;  nk_rnf(ji,jj) = mbkt(ji,jj) 
     386            ELSE 
     387               CALL ctl_stop( 'sbc_rnf_init: runoff depth not positive, and not -999 or -1, rnf value in file fort.999'  ) 
     388               WRITE(999,*) 'ji, jj, h_rnf(ji,jj) :', ji, jj, h_rnf(ji,jj) 
     389            ENDIF 
     390         END_2D 
     391         DO_2D_11_11 
     392            h_rnf(ji,jj) = 0._wp 
     393            DO jk = 1, nk_rnf(ji,jj) 
     394               h_rnf(ji,jj) = h_rnf(ji,jj) + e3t(ji,jj,jk,Kmm) 
    393395            END DO 
    394          END DO 
    395          DO jj = 1, jpj                                ! set the associated depth 
    396             DO ji = 1, jpi 
    397                h_rnf(ji,jj) = 0._wp 
    398                DO jk = 1, nk_rnf(ji,jj) 
    399                   h_rnf(ji,jj) = h_rnf(ji,jj) + e3t(ji,jj,jk,Kmm) 
    400                END DO 
    401             END DO 
    402          END DO 
     396         END_2D 
    403397      ELSE                                       ! runoffs applied at the surface 
    404398         nk_rnf(:,:) = 1 
     
    586580      gdepw(:,:,1,Kmm) = 0.0_wp 
    587581      ! 
    588       DO jk = 2, jpk 
    589          DO jj = 1,jpj 
    590             DO ji = 1,jpi 
    591                zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk)) 
    592                gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm) 
    593                gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  & 
    594                   &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) + e3w(ji,jj,jk,Kmm)) 
    595             END DO 
    596          END DO 
    597       END DO 
     582      DO_3D_11_11( 2, jpk ) 
     583         zcoef = (tmask(ji,jj,jk) - wmask(ji,jj,jk)) 
     584         gdepw(ji,jj,jk,Kmm) = gdepw(ji,jj,jk-1,Kmm) + e3t(ji,jj,jk-1,Kmm) 
     585         gdept(ji,jj,jk,Kmm) =      zcoef  * ( gdepw(ji,jj,jk  ,Kmm) + 0.5 * e3w(ji,jj,jk,Kmm))  & 
     586            &                + (1-zcoef) * ( gdept(ji,jj,jk-1,Kmm) + e3w(ji,jj,jk,Kmm)) 
     587      END_3D 
    598588      ! 
    599589   END SUBROUTINE dta_dyn_sf_interp 
     
    667657      !!---------------------------------------------------------------------- 
    668658      ! 
    669       DO jj = 1, jpj                   ! update the depth over which runoffs are distributed 
    670          DO ji = 1, jpi 
    671             h_rnf(ji,jj) = 0._wp 
    672             DO jk = 1, nk_rnf(ji,jj)                           ! recalculates h_rnf to be the depth in metres 
    673                 h_rnf(ji,jj) = h_rnf(ji,jj) + e3t(ji,jj,jk,Kmm)   ! to the bottom of the relevant grid box 
    674             END DO 
    675         END DO 
    676       END DO 
     659      DO_2D_11_11 
     660         h_rnf(ji,jj) = 0._wp 
     661         DO jk = 1, nk_rnf(ji,jj)                           ! recalculates h_rnf to be the depth in metres 
     662             h_rnf(ji,jj) = h_rnf(ji,jj) + e3t(ji,jj,jk,Kmm)   ! to the bottom of the relevant grid box 
     663         END DO 
     664      END_2D 
    677665      ! 
    678666   END SUBROUTINE dta_dyn_hrnf 
Note: See TracChangeset for help on using the changeset viewer.