#2595 closed Defect (fixed)
Swap DO_2D and DO_3D* macro arguments to a more natural i-j-k ordering
Reported by: | acc | Owned by: | systeam |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | TOP | Version: | v4.0.* |
Severity: | minor | Keywords: | |
Cc: |
Description
Context
The arguments to the current DO_LOOP macros have to specified in an order that can cause confusion. Currently, it is j-loop limits followed by i-loop limits followed (in the 3D cases) by k-loop limits. The order was chosen for the original 2D macros to reflect the nested order of the loops but should be changed to a more natural ordering.
Analysis
This is relatively simple to achieve. This perl script will locate and swap the entries:
#!/bin/bash # DOSTRS=( DO_2D DO_3D ) # # build a list of files that need to be changed # listfile=tmplistfile$$.txt for iunit in ${DOSTRS[@]} do grep -l $iunit `find ./ -name '*.[fFh]90'` >> $listfile done allfiles=`cat $listfile | grep -v substitute | sort -u` echo $allfiles # if [ -f $listfile ] ; then rm $listfile; fi for f in $allfiles do echo "Working on " $f n=0 for n in `seq 0 1 $(( ${#DOSTRS[*]} - 1 ))` do perl -ni -e 'unless ( m@^\s*'${DOSTRS[$n]}'@) { print } else { $line= $_ ; $line=~s@(^\s*'${DOSTRS[$n]}'.*\()([^\,]*),([^\,]*),([^\,]*),(\s*[^\,\s\)]*)(.*)@\1\4,\5,\2,\3\6@ ; print $line }' $f done done
And the changes to do_loop_substitute.h90 are straight-forward:
-
src/OCE/do_loop_substitute.h90
1 1 #if defined show_comments 2 2 ! These comments are not intended to be retained during preprocessing; i.e. do not define "show_comments" 3 3 !!---------------------------------------------------------------------- 4 !! NEMO/OCE 4. 0 , NEMO Consortium (2018)4 !! NEMO/OCE 4.x , NEMO Consortium (2020) 5 5 !! Software governed by the CeCILL license (see ./LICENSE) 6 6 !!---------------------------------------------------------------------- 7 7 ! This header file contains preprocessor definitions and macros used in the do-loop substitutions introduced … … 24 24 ! Lower limits of 1, 2 or fs_2 25 25 ! Upper limits of jpi, jpim1 or fs_jpim1 (for ji) or jpj, jpjm1 or fs_jpjm1 (for jj) 26 26 ! 27 ! The macro naming convention takes the form: DO_2D( B, T, L, R) where: 27 ! The macro naming convention takes the form: DO_2D( L, R, B, T) where: 28 ! L is the Left offset from the PE's inner domain; 29 ! R is the Right offset from the PE's inner domain 28 30 ! B is the Bottom offset from the PE's inner domain; 29 31 ! T is the Top offset from the PE's inner domain; 30 ! L is the Left offset from the PE's inner domain;31 ! R is the Right offset from the PE's inner domain32 32 ! 33 33 ! So, given an inner domain of 2,jpim1 and 2,jpjm1, a typical example would replace: 34 34 ! … … 41 41 ! 42 42 ! with: 43 43 ! 44 ! DO_2D( 0, 1, 1, 0)44 ! DO_2D( 1, 0, 0, 1 ) 45 45 ! . 46 46 ! . 47 47 ! END_2D … … 58 58 ! 59 59 #endif 60 60 61 #define DO_2D( B, T, L, R) DO jj = ntsj-(B), ntej+(T) ; DO ji = ntsi-(L), ntei+(R)61 #define DO_2D(L, R, B, T) DO jj = ntsj-(B), ntej+(T) ; DO ji = ntsi-(L), ntei+(R) 62 62 #define A1Di(H) ntsi-H:ntei+H 63 63 #define A1Dj(H) ntsj-H:ntej+H 64 64 #define A2D(H) A1Di(H),A1Dj(H) … … 69 69 #define JPTS : 70 70 #define KJPT : 71 71 72 #define DO_3D( B, T, L, R, ks, ke) DO jk = ks, ke ; DO_2D(B, T, L, R)72 #define DO_3D(L, R, B, T, ks, ke) DO jk = ks, ke ; DO_2D(L, R, B, T) 73 73 74 #define DO_3DS( B, T, L, R, ks, ke, ki) DO jk = ks, ke, ki ; DO_2D(B, T, L, R)74 #define DO_3DS(L, R, B, T, ks, ke, ki) DO jk = ks, ke, ki ; DO_2D(L, R, B, T) 75 75 76 76 #define END_2D END DO ; END DO 77 77 #define END_3D END DO ; END DO ; END DO
Additionally, because the majority of loop pairs have matching offset limits , only these modules are actually altered by this change:
M src/ABL/ablmod.F90 M src/ICE/icedyn_adv_pra.F90 M src/ICE/icedyn_adv_umx.F90 M src/OCE/DIA/diaptr.F90 M src/OCE/DOM/dommsk.F90 M src/OCE/DYN/dynldf_iso.F90 M src/OCE/DYN/dynspg_ts.F90 M src/OCE/ISF/isftbl.F90 M src/OCE/SBC/geo2ocean.F90 M src/OCE/SBC/sbcice_cice.F90 M src/OCE/TRA/traadv_qck.F90 M src/OCE/TRA/trabbl.F90 M src/OCE/TRA/traldf_lap_blp.F90 M src/OCE/TRA/traldf_triad.F90 M src/OCE/TRA/tranpc.F90 M src/OCE/TRA/traqsr.F90 M src/OCE/TRA/trasbc.F90 M src/OCE/ZDF/zdfosm.F90 M src/OCE/do_loop_substitute.h90 M src/TOP/TRP/trcsbc.F90 M src/TOP/trcbc.F90
Recommendation
Make this change. Confirm before and after SETTE results match and commit asap
...
Commit History (1)
Changeset | Author | Time | ChangeLog |
---|---|---|---|
14215 | acc | 2020-12-18T14:49:22+01:00 | trunk changes to swap the order of arguments to the DO LOOP macros. These changes result in a more natural i-j-k ordering as explained in #2595. SETTE is passed before and after these changes and results are unchanged. This fixes #2595 |
Attachments (3)
Change History (5)
comment:1 Changed 3 years ago by acc
- Resolution set to fixed
- Status changed from new to closed
Changed 3 years ago by acc
First stage perl script to convert classic do loops to final, correctly ordered, version of the DO-LOOP macros
Changed 3 years ago by acc
First stage perl script to convert classic do loops to final, correctly ordered, version of the DO-LOOP macros
Changed 3 years ago by acc
Second stage perl script to convert classic do loops to final, correctly ordered, version of the DO-LOOP macros
comment:2 Changed 3 years ago by acc
Attached perl scripts to provide a direct conversion from classic do loops to this final, correctly ordered version of the DO-LOOP macros. The conversion is a 2-stage process; first stage converts 2D loops; second stage converts 3D loops. For example:
mkdir STAGE1 STAGE2 perl do2dfinder_final.pl trazdf.F90 > STAGE1/trazdf.F90 perl do3dfinder_final.pl STAGE1/trazdf.F90 > STAGE2/trazdf.F90
with the STAGE2 files replacing the originals after checking.
In 14215: