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.
diacfl.F90 in NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/DIA – NEMO

source: NEMO/branches/2019/dev_r11943_MERGE_2019/src/OCE/DIA/diacfl.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: 8.2 KB
Line 
1MODULE diacfl
2   !!======================================================================
3   !!                       ***  MODULE  diacfl  ***
4   !! Output CFL diagnostics to ascii file
5   !!======================================================================
6   !! History :  3.4  !  2010-03  (E. Blockley)  Original code
7   !!            3.6  !  2014-06  (T. Graham)  Removed CPP key & Updated to vn3.6
8   !!            4.0  !  2017-09  (G. Madec)  style + comments
9   !!----------------------------------------------------------------------
10   !!   dia_cfl        : Compute and output Courant numbers at each timestep
11   !!----------------------------------------------------------------------
12   USE oce             ! ocean dynamics and active tracers
13   USE dom_oce         ! ocean space and time domain
14   USE domvvl          !
15   !
16   USE lib_mpp         ! distribued memory computing
17   USE lbclnk          ! ocean lateral boundary condition (or mpp link)
18   USE in_out_manager  ! I/O manager
19   USE iom             !
20   USE timing          ! Performance output
21
22   IMPLICIT NONE
23   PRIVATE
24
25   CHARACTER(LEN=50) :: clname="cfl_diagnostics.ascii"    ! ascii filename
26   INTEGER           :: numcfl                            ! outfile unit
27   !
28   INTEGER, DIMENSION(3) ::   nCu_loc, nCv_loc, nCw_loc   ! U, V, and W run max locations in the global domain
29   REAL(wp)              ::   rCu_max, rCv_max, rCw_max   ! associated run max Courant number
30
31   PUBLIC   dia_cfl       ! routine called by step.F90
32   PUBLIC   dia_cfl_init  ! routine called by nemogcm
33
34   !! * Substitutions
35#  include "vectopt_loop_substitute.h90"
36#  include "do_loop_substitute.h90"
37   !!----------------------------------------------------------------------
38   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
39   !! $Id$
40   !! Software governed by the CeCILL license (see ./LICENSE)
41   !!----------------------------------------------------------------------
42CONTAINS
43
44   SUBROUTINE dia_cfl ( kt, Kmm )
45      !!----------------------------------------------------------------------
46      !!                  ***  ROUTINE dia_cfl  ***
47      !!
48      !! ** Purpose :  Compute the Courant numbers Cu=u*dt/dx and Cv=v*dt/dy
49      !!               and output to ascii file 'cfl_diagnostics.ascii'
50      !!----------------------------------------------------------------------
51      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
52      INTEGER, INTENT(in) ::   Kmm  ! ocean time level index
53      !
54      INTEGER                          ::   ji, jj, jk                       ! dummy loop indices
55      REAL(wp)                         ::   z2dt, zCu_max, zCv_max, zCw_max  ! local scalars
56      INTEGER , DIMENSION(3)           ::   iloc_u , iloc_v , iloc_w , iloc  ! workspace
57      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zCu_cfl, zCv_cfl, zCw_cfl        ! workspace
58      !!----------------------------------------------------------------------
59      !
60      IF( ln_timing )   CALL timing_start('dia_cfl')
61      !
62      !                       ! setup timestep multiplier to account for initial Eulerian timestep
63      IF( neuler == 0 .AND. kt == nit000 ) THEN   ;    z2dt = rdt
64      ELSE                                        ;    z2dt = rdt * 2._wp
65      ENDIF
66      !
67      !               
68      DO_3D_11_11( 1, jpk )
69         zCu_cfl(ji,jj,jk) = ABS( uu(ji,jj,jk,Kmm) ) * z2dt / e1u  (ji,jj)      ! for i-direction
70         zCv_cfl(ji,jj,jk) = ABS( vv(ji,jj,jk,Kmm) ) * z2dt / e2v  (ji,jj)      ! for j-direction
71         zCw_cfl(ji,jj,jk) = ABS( ww(ji,jj,jk) ) * z2dt / e3w(ji,jj,jk,Kmm)   ! for k-direction
72      END_3D
73      !
74      ! write outputs
75      IF( iom_use('cfl_cu') )   CALL iom_put( 'cfl_cu', MAXVAL( zCu_cfl, dim=3 ) )
76      IF( iom_use('cfl_cv') )   CALL iom_put( 'cfl_cv', MAXVAL( zCv_cfl, dim=3 ) )
77      IF( iom_use('cfl_cw') )   CALL iom_put( 'cfl_cw', MAXVAL( zCw_cfl, dim=3 ) )
78
79      !                    ! calculate maximum values and locations
80      IF( lk_mpp ) THEN
81         CALL mpp_maxloc( 'diacfl', zCu_cfl, umask, zCu_max, iloc_u )
82         CALL mpp_maxloc( 'diacfl', zCv_cfl, vmask, zCv_max, iloc_v )
83         CALL mpp_maxloc( 'diacfl', zCw_cfl, wmask, zCw_max, iloc_w )
84      ELSE
85         iloc = MAXLOC( ABS( zcu_cfl(:,:,:) ) )
86         iloc_u(1) = iloc(1) + nimpp - 1
87         iloc_u(2) = iloc(2) + njmpp - 1
88         iloc_u(3) = iloc(3)
89         zCu_max = zCu_cfl(iloc(1),iloc(2),iloc(3))
90         !
91         iloc = MAXLOC( ABS( zcv_cfl(:,:,:) ) )
92         iloc_v(1) = iloc(1) + nimpp - 1
93         iloc_v(2) = iloc(2) + njmpp - 1
94         iloc_v(3) = iloc(3)
95         zCv_max = zCv_cfl(iloc(1),iloc(2),iloc(3))
96         !
97         iloc = MAXLOC( ABS( zcw_cfl(:,:,:) ) )
98         iloc_w(1) = iloc(1) + nimpp - 1
99         iloc_w(2) = iloc(2) + njmpp - 1
100         iloc_w(3) = iloc(3)
101         zCw_max = zCw_cfl(iloc(1),iloc(2),iloc(3))
102      ENDIF
103      !
104      !                    ! write out to file
105      IF( lwp ) THEN
106         WRITE(numcfl,FMT='(2x,i6,3x,a6,4x,f7.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zCu_max, iloc_u(1), iloc_u(2), iloc_u(3)
107         WRITE(numcfl,FMT='(11x,     a6,4x,f7.4,1x,i4,1x,i4,1x,i4)')     'Max Cv', zCv_max, iloc_v(1), iloc_v(2), iloc_v(3)
108         WRITE(numcfl,FMT='(11x,     a6,4x,f7.4,1x,i4,1x,i4,1x,i4)')     'Max Cw', zCw_max, iloc_w(1), iloc_w(2), iloc_w(3)
109      ENDIF
110      !
111      !                    ! update maximum Courant numbers from whole run if applicable
112      IF( zCu_max > rCu_max ) THEN   ;   rCu_max = zCu_max   ;   nCu_loc(:) = iloc_u(:)   ;   ENDIF
113      IF( zCv_max > rCv_max ) THEN   ;   rCv_max = zCv_max   ;   nCv_loc(:) = iloc_v(:)   ;   ENDIF
114      IF( zCw_max > rCw_max ) THEN   ;   rCw_max = zCw_max   ;   nCw_loc(:) = iloc_w(:)   ;   ENDIF
115
116      !                    ! at end of run output max Cu and Cv and close ascii file
117      IF( kt == nitend .AND. lwp ) THEN
118         ! to ascii file
119         WRITE(numcfl,*) '******************************************'
120         WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cu', rCu_max, nCu_loc(1), nCu_loc(2), nCu_loc(3)
121         WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCu_max
122         WRITE(numcfl,*) '******************************************'
123         WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cv', rCv_max, nCv_loc(1), nCv_loc(2), nCv_loc(3)
124         WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCv_max
125         WRITE(numcfl,*) '******************************************'
126         WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cw', rCw_max, nCw_loc(1), nCw_loc(2), nCw_loc(3)
127         WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCw_max
128         CLOSE( numcfl ) 
129         !
130         ! to ocean output
131         WRITE(numout,*)
132         WRITE(numout,*) 'dia_cfl : Maximum Courant number information for the run '
133         WRITE(numout,*) '~~~~~~~'
134         WRITE(numout,*) '   Max Cu = ', rCu_max, ' at (i,j,k) = (',nCu_loc(1),nCu_loc(2),nCu_loc(3),') => dt/C = ', z2dt/rCu_max
135         WRITE(numout,*) '   Max Cv = ', rCv_max, ' at (i,j,k) = (',nCv_loc(1),nCv_loc(2),nCv_loc(3),') => dt/C = ', z2dt/rCv_max
136         WRITE(numout,*) '   Max Cw = ', rCw_max, ' at (i,j,k) = (',nCw_loc(1),nCw_loc(2),nCw_loc(3),') => dt/C = ', z2dt/rCw_max
137      ENDIF
138      !
139      IF( ln_timing )   CALL timing_stop('dia_cfl')
140      !
141   END SUBROUTINE dia_cfl
142
143
144   SUBROUTINE dia_cfl_init
145      !!----------------------------------------------------------------------
146      !!                  ***  ROUTINE dia_cfl_init  ***
147      !!                   
148      !! ** Purpose :   create output file, initialise arrays
149      !!----------------------------------------------------------------------
150      !
151      IF(lwp) THEN
152         WRITE(numout,*)
153         WRITE(numout,*) 'dia_cfl : Outputting CFL diagnostics to ',TRIM(clname), ' file'
154         WRITE(numout,*) '~~~~~~~'
155         WRITE(numout,*)
156         !
157         ! create output ascii file
158         CALL ctl_opn( numcfl, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
159         WRITE(numcfl,*) 'Timestep  Direction  Max C     i    j    k'
160         WRITE(numcfl,*) '******************************************'
161      ENDIF
162      !
163      rCu_max = 0._wp
164      rCv_max = 0._wp
165      rCw_max = 0._wp
166      !
167   END SUBROUTINE dia_cfl_init
168
169   !!======================================================================
170END MODULE diacfl
Note: See TracBrowser for help on using the repository browser.