Opened 5 months ago

Closed 5 months ago

#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: 4.0-HEAD
Severity: minor Keywords:
Cc: Branch review:
MP ready?: Task progress:

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

     
    11#if defined show_comments 
    22! These comments are not intended to be retained during preprocessing; i.e. do not define "show_comments" 
    33!!---------------------------------------------------------------------- 
    4 !! NEMO/OCE 4.0 , NEMO Consortium (2018) 
     4!! NEMO/OCE 4.x , NEMO Consortium (2020) 
    55!! Software governed by the CeCILL license (see ./LICENSE) 
    66!!---------------------------------------------------------------------- 
    77! This header file contains preprocessor definitions and macros used in the do-loop substitutions introduced 
     
    2424! Lower limits of 1, 2 or fs_2 
    2525! Upper limits of jpi, jpim1 or fs_jpim1 (for ji) or jpj, jpjm1 or fs_jpjm1 (for jj) 
    2626! 
    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 
    2830!   B is the Bottom offset from the PE's inner domain; 
    2931!   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 domain 
    3232! 
    3333! So, given an inner domain of 2,jpim1 and 2,jpjm1, a typical example would replace: 
    3434! 
     
    4141! 
    4242! with: 
    4343! 
    44 !   DO_2D( 0, 1, 1, 0 ) 
     44!   DO_2D( 1, 0, 0, 1 ) 
    4545!      . 
    4646!      . 
    4747!   END_2D 
     
    5858! 
    5959#endif 
    6060 
    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) 
    6262#define A1Di(H) ntsi-H:ntei+H 
    6363#define A1Dj(H) ntsj-H:ntej+H 
    6464#define A2D(H) A1Di(H),A1Dj(H) 
     
    6969#define JPTS  : 
    7070#define KJPT  : 
    7171 
    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) 
    7373 
    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) 
    7575 
    7676#define END_2D   END DO   ;   END DO 
    7777#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)

ChangesetAuthorTimeChangeLog
14215acc2020-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

Change History (1)

comment:1 Changed 5 months ago by acc

  • Resolution set to fixed
  • Status changed from new to closed

In 14215:

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

Note: See TracTickets for help on using tickets.