New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
stopts.F90 in NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/STO – NEMO

source: NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/STO/stopts.F90 @ 12340

Last change on this file since 12340 was 12340, checked in by acc, 4 years ago

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.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1MODULE stopts
2   !!==============================================================================
3   !!                       ***  MODULE  stopts  ***
4   !! Stochastic parameterization: compute stochastic tracer fluctuations
5   !!==============================================================================
6   !! History :  3.3  ! 2011-12 (J.-M. Brankart)  Original code
7   !!----------------------------------------------------------------------
8
9   !!----------------------------------------------------------------------
10   !!   sto_pts        : compute current stochastic tracer fluctuations
11   !!   sto_pts_init   : initialisation for stochastic tracer fluctuations
12   !!----------------------------------------------------------------------
13   USE dom_oce         ! ocean space and time domain
14   USE lbclnk          ! lateral boundary conditions (or mpp link)
15   USE phycst          ! physical constants
16   USE stopar          ! stochastic parameterization
17
18   IMPLICIT NONE
19   PRIVATE
20
21   PUBLIC   sto_pts         ! called by step.F90
22   PUBLIC   sto_pts_init    ! called by nemogcm.F90
23
24   ! Public array with random tracer fluctuations
25   REAL(wp), PUBLIC, DIMENSION(:,:,:,:,:), ALLOCATABLE :: pts_ran
26
27   !! * Substitutions
28#  include "vectopt_loop_substitute.h90"
29#  include "do_loop_substitute.h90"
30   !!----------------------------------------------------------------------
31   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
32   !! $Id$
33   !! Software governed by the CeCILL license (see ./LICENSE)
34   !!----------------------------------------------------------------------
35CONTAINS
36
37   SUBROUTINE sto_pts( pts )
38      !!----------------------------------------------------------------------
39      !!                  ***  ROUTINE sto_pts  ***
40      !!
41      !! ** Purpose :   Compute current stochastic tracer fluctuations
42      !!
43      !! ** Method  :   Compute tracer differences from a random walk
44      !!                around every model grid point
45      !!
46      !!----------------------------------------------------------------------
47      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts), INTENT(inout) ::   pts   ! 1 : potential temperature  [Celsius]
48      !                                                               ! 2 : salinity               [psu]
49      INTEGER  ::   ji, jj, jk, jts, jdof ! dummy loop indices
50      INTEGER  ::   jim1, jjm1, jkm1  ! incremented indices
51      INTEGER  ::   jip1, jjp1, jkp1  !     -          -
52      REAL(wp) ::   zdtsim, zdtsjm, zdtskm         ! temporary scalars
53      REAL(wp) ::   zdtsip, zdtsjp, zdtskp, zdts   !     -        -
54      !!----------------------------------------------------------------------
55
56      DO jts = 1, jpts
57        CALL lbc_lnk( 'stopts', pts(:,:,:,jts), 'T' , 1._wp )
58      ENDDO
59
60      DO jdof = 1, nn_sto_eos
61        DO jts = 1, jpts
62           DO jk = 1, jpkm1
63              jkm1 = MAX(jk-1,1) ; jkp1 = MIN(jk+1,jpkm1)
64              DO jj = 1, jpj
65                 jjm1 = MAX(jj-1,1) ; jjp1 = MIN(jj+1,jpj)
66                 DO ji = 1, jpi
67                    jim1 = MAX(ji-1,1) ; jip1 = MIN(ji+1,jpi)
68                    !
69                    ! compute tracer gradient
70                    zdtsip = ( pts(jip1,jj,jk,jts) - pts(ji,jj,jk,jts) ) * tmask(jip1,jj,jk)
71                    zdtsim = ( pts(ji,jj,jk,jts) - pts(jim1,jj,jk,jts) ) * tmask(jim1,jj,jk)
72                    zdtsjp = ( pts(ji,jjp1,jk,jts) - pts(ji,jj,jk,jts) ) * tmask(ji,jjp1,jk)
73                    zdtsjm = ( pts(ji,jj,jk,jts) - pts(ji,jjm1,jk,jts) ) * tmask(ji,jjm1,jk)
74                    zdtskp = ( pts(ji,jj,jkp1,jts) - pts(ji,jj,jk,jts) ) * tmask(ji,jj,jkp1)
75                    zdtskm = ( pts(ji,jj,jk,jts) - pts(ji,jj,jkm1,jts) ) * tmask(ji,jj,jkm1)
76                    !
77                    ! compute random tracer fluctuation (zdts)
78                    zdts   = ( zdtsip + zdtsim ) * sto2d(ji,jj,jsto_eosi(jdof)) + &
79                           & ( zdtsjp + zdtsjm ) * sto2d(ji,jj,jsto_eosj(jdof)) + &
80                           & ( zdtskp + zdtskm ) * sto2d(ji,jj,jsto_eosk(jdof))
81!                   zdts   = zdtsip * MAX(sto2d(ji,jj,jsto_eosi),0._wp) + &
82!                          & zdtsim * MIN(sto2d(ji,jj,jsto_eosi),0._wp) + &
83!                          & zdtsjp * MAX(sto2d(ji,jj,jsto_eosj),0._wp) + &
84!                          & zdtsjm * MIN(sto2d(ji,jj,jsto_eosj),0._wp) + &
85!                          & zdtskp * MAX(sto2d(ji,jj,jsto_eosk),0._wp) + &
86!                          & zdtskm * MIN(sto2d(ji,jj,jsto_eosk),0._wp)
87                    zdts   = zdts  * tmask(ji,jj,jk) *SIN( gphit(ji,jj) * rad )
88                    pts_ran(ji,jj,jk,jts,jdof) = zdts * 0.5_wp
89                    !
90                  END DO
91               END DO
92            END DO
93         END DO
94      END DO
95
96      ! Eliminate any possible negative salinity
97      DO jdof = 1, nn_sto_eos
98         DO_3D_11_11( 1, jpkm1 )
99            pts_ran(ji,jj,jk,jp_sal,jdof) = MIN( ABS(pts_ran(ji,jj,jk,jp_sal,jdof)) ,  &
100                                          &      MAX(pts(ji,jj,jk,jp_sal),0._wp) )     &
101                                          &  * SIGN(1._wp,pts_ran(ji,jj,jk,jp_sal,jdof))
102         END_3D
103      END DO
104
105      ! Eliminate any temperature lower than -2 degC
106!     DO jdof = 1, nn_sto_eos
107!        DO jk = 1, jpkm1
108!           DO jj = 1, jpj
109!              DO ji = 1, jpi
110!                 pts_ran(ji,jj,jk,jp_tem,jdof) = MIN( ABS(pts_ran(ji,jj,jk,jp_tem,jdof)) ,    &
111!                                               &      MAX(pts(ji,jj,jk,jp_tem)+2._wp,0._wp) ) &
112!                                               &  * SIGN(1._wp,pts_ran(ji,jj,jk,jp_tem,jdof))
113!              END DO
114!           END DO
115!        END DO
116!     END DO
117
118
119      ! Lateral boundary conditions on pts_ran
120      DO jdof = 1, nn_sto_eos
121         DO jts = 1, jpts
122            CALL lbc_lnk( 'stopts', pts_ran(:,:,:,jts,jdof), 'T' , 1._wp )
123         END DO
124      END DO
125
126   END SUBROUTINE sto_pts
127
128
129   SUBROUTINE sto_pts_init
130      !!----------------------------------------------------------------------
131      !!                  ***  ROUTINE sto_pts_init  ***
132      !!
133      !! ** Purpose :   Initialisation for stochastic tracer fluctuations
134      !!
135      !! ** Method  :   Allocate required array
136      !!
137      !!----------------------------------------------------------------------
138
139      ALLOCATE(pts_ran(jpi,jpj,jpk,jpts,nn_sto_eos))
140
141   END SUBROUTINE sto_pts_init
142
143END MODULE stopts
Note: See TracBrowser for help on using the repository browser.