Skip to content

Commit 5f53998

Browse files
committed
Merge branch 'mahf708/ig/v3-script' into next (PR #6534)
Automates $PSCRATCH location for code and case, adds custom_pelayout for supported machines, hardens copy_script, and sets default PROJECT for slurm-based machines. [BFB]
2 parents 11ce173 + f84cad1 commit 5f53998

File tree

1 file changed

+59
-11
lines changed

1 file changed

+59
-11
lines changed

run_e3sm.template.sh

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# E3SM Coupled Model Group run_e3sm script template.
44
#
55
# Bash coding style inspired by:
6-
# http://kfirlavi.herokuapp.com/blog/2012/11/14/defensive-bash-programming
7-
8-
# TO DO:
9-
# - custom pelayout
6+
# https://web.archive.org/web/20200620202413/http://kfirlavi.herokuapp.com/blog/2012/11/14/defensive-bash-programming
107

118
main() {
129

@@ -17,8 +14,9 @@ main() {
1714

1815
# Machine and project
1916
readonly MACHINE=pm-cpu
20-
# BEFORE RUNNING: CHANGE this to your project
21-
readonly PROJECT="e3sm"
17+
# NOTE: The command below will return your default project on SLURM-based systems.
18+
# If you are not using SLURM or need a different project, remove the command and set it directly
19+
readonly PROJECT="$(sacctmgr show user $USER format=DefaultAccount | tail -n1 | tr -d ' ')"
2220

2321
# Simulation
2422
readonly COMPSET="WCYCL1850"
@@ -46,8 +44,8 @@ readonly GET_REFCASE=TRUE
4644
#readonly RUN_REFDATE="" # same as MODEL_START_DATE for 'branch', can be different for 'hybrid'
4745

4846
# Set paths
47+
readonly CASE_ROOT="${PSCRATCH}/E3SMv3/${CASE_NAME}"
4948
readonly CODE_ROOT="${HOME}/E3SMv3/code/${CHECKOUT}"
50-
readonly CASE_ROOT="/pscratch/sd/r/${USER}/e3sm-scratch/${CASE_NAME}"
5149

5250
# Sub-directories
5351
readonly CASE_BUILD_DIR=${CASE_ROOT}/build
@@ -56,6 +54,7 @@ readonly CASE_ARCHIVE_DIR=${CASE_ROOT}/archive
5654
# Define type of run
5755
# short tests: 'XS_2x5_ndays', 'XS_1x10_ndays', 'S_1x10_ndays',
5856
# 'M_1x10_ndays', 'M2_1x10_ndays', 'M80_1x10_ndays', 'L_1x10_ndays'
57+
# * can replace XS, M, etc. with custom-XY with XY being the node count
5958
# or 'production' for full simulation
6059
readonly run='XS_2x5_ndays'
6160
if [ "${run}" != "production" ]; then
@@ -118,6 +117,9 @@ fetch_code
118117
# Create case
119118
create_newcase
120119

120+
# Custom PE layout
121+
custom_pelayout
122+
121123
# Setup
122124
case_setup
123125

@@ -322,6 +324,14 @@ create_newcase() {
322324

323325
echo $'\n----- Starting create_newcase -----\n'
324326

327+
328+
if [[ ${PELAYOUT} == custom-* ]];
329+
then
330+
layout="M" # temporary placeholder for create_newcase
331+
else
332+
layout=${PELAYOUT}
333+
fi
334+
325335
if [[ -z "$CASE_GROUP" ]]; then
326336
${CODE_ROOT}/cime/scripts/create_newcase \
327337
--case ${CASE_NAME} \
@@ -333,7 +343,7 @@ create_newcase() {
333343
--machine ${MACHINE} \
334344
--project ${PROJECT} \
335345
--walltime ${WALLTIME} \
336-
--pecount ${PELAYOUT}
346+
--pecount ${layout}
337347
else
338348
${CODE_ROOT}/cime/scripts/create_newcase \
339349
--case ${CASE_NAME} \
@@ -346,7 +356,7 @@ create_newcase() {
346356
--machine ${MACHINE} \
347357
--project ${PROJECT} \
348358
--walltime ${WALLTIME} \
349-
--pecount ${PELAYOUT}
359+
--pecount ${layout}
350360
fi
351361

352362

@@ -398,6 +408,43 @@ case_setup() {
398408
popd
399409
}
400410

411+
#-----------------------------------------------------
412+
custom_pelayout() {
413+
414+
if [[ ${PELAYOUT} == custom-* ]];
415+
then
416+
echo $'\n CUSTOMIZE PROCESSOR CONFIGURATION:'
417+
418+
# Number of cores per node (machine specific)
419+
if [ "${MACHINE}" == "pm-cpu" ]; then
420+
ncore=128
421+
elif [ "${MACHINE}" == "chrysalis" ]; then
422+
ncore=64
423+
elif [ "${MACHINE}" == "compy" ]; then
424+
ncore=40
425+
elif [ "${MACHINE}" == "anvil" ]; then
426+
ncore=36
427+
else
428+
echo 'ERROR: MACHINE = '${MACHINE}' is not supported for custom PE layout.'
429+
exit 400
430+
fi
431+
432+
# Extract number of nodes
433+
tmp=($(echo ${PELAYOUT} | tr "-" " "))
434+
nnodes=${tmp[1]}
435+
436+
# Customize
437+
pushd ${CASE_SCRIPTS_DIR}
438+
./xmlchange NTASKS=$(( $nnodes * $ncore ))
439+
./xmlchange NTHRDS=1
440+
./xmlchange MAX_MPITASKS_PER_NODE=$ncore
441+
./xmlchange MAX_TASKS_PER_NODE=$ncore
442+
popd
443+
444+
fi
445+
446+
}
447+
401448
#-----------------------------------------------------
402449
case_build() {
403450

@@ -534,9 +581,10 @@ copy_script() {
534581

535582
local script_provenance_dir=${CASE_SCRIPTS_DIR}/run_script_provenance
536583
mkdir -p ${script_provenance_dir}
537-
local this_script_name=`basename $0`
584+
local this_script_name=$( basename -- "$0"; )
585+
local this_script_dir=$( dirname -- "$0"; )
538586
local script_provenance_name=${this_script_name}.`date +%Y%m%d-%H%M%S`
539-
cp -vp ${this_script_name} ${script_provenance_dir}/${script_provenance_name}
587+
cp -vp "${this_script_dir}/${this_script_name}" ${script_provenance_dir}/${script_provenance_name}
540588

541589
}
542590

0 commit comments

Comments
 (0)