-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_fertilizer_scaling_full.jcf
More file actions
executable file
·85 lines (68 loc) · 2.64 KB
/
Copy pathsubmit_fertilizer_scaling_full.jcf
File metadata and controls
executable file
·85 lines (68 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#SBATCH --job-name=fert_scaling_full
#SBATCH --output=/p/projects/macmit/data/GGCMI/AgMIP.input/phase3/n-fertilizer/group_iii/logs/fert_scaling_%A_%a.out
#SBATCH --error=/p/projects/macmit/data/GGCMI/AgMIP.input/phase3/n-fertilizer/group_iii/logs/fert_scaling_%A_%a.err
#SBATCH --time=01:00:00
#SBATCH --qos=standby
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
###SBATCH --mem=6G
#SBATCH --account=macmit
#SBATCH --mail-type=END,FAIL
#SBATCH --array=0-464%100
set -eo pipefail
# Ensure expected runtime directories exist.
mkdir -p /p/projects/macmit/data/GGCMI/AgMIP.input/phase3/n-fertilizer/group_iii/logs
# PIK R/module environment.
source /p/system/modulefiles/defaults/piam/module_load_piam
# Enable nounset after cluster/module init scripts, which may read unset vars.
set -u
SCRIPT_DIR="/p/projects/macmit/users/cmueller/repos/AgMIP-GGCMI/fertilizer_rates"
if [[ ! -f "$SCRIPT_DIR/fertilizer_scaling.R" ]]; then
echo "ERROR: fertilizer_scaling.R not found in working directory: $SCRIPT_DIR"
exit 4
fi
cd "$SCRIPT_DIR"
# Full matrix (15 crops) x (1 histsoc + 3 SSP x 2 IAM x 5 GCM) = 465 jobs.
crops=(swh wwh mai ri1 ri2 soy mil sor pea sgb cas rap sun nut sgc)
ssps=(ssp126 ssp370 ssp585)
iams=(image magpie)
gcms=(gfdl-esm4 ipsl-cm6a-lr mpi-esm1-2-hr mri-esm2-0 ukesm1-0-ll)
declare -a TASKS
for crop in "${crops[@]}"; do
TASKS+=("$crop histsoc")
for ssp in "${ssps[@]}"; do
for iam in "${iams[@]}"; do
for gcm in "${gcms[@]}"; do
TASKS+=("$crop $ssp $iam $gcm")
done
done
done
done
TOTAL_TASKS=${#TASKS[@]}
if [[ "$TOTAL_TASKS" -ne 465 ]]; then
echo "ERROR: expected 465 tasks, found $TOTAL_TASKS"
exit 1
fi
if [[ -z "${SLURM_ARRAY_TASK_ID:-}" ]]; then
echo "ERROR: This script is intended for sbatch array execution."
exit 2
fi
if (( SLURM_ARRAY_TASK_ID < 0 || SLURM_ARRAY_TASK_ID >= TOTAL_TASKS )); then
echo "ERROR: SLURM_ARRAY_TASK_ID=$SLURM_ARRAY_TASK_ID out of range 0..$((TOTAL_TASKS - 1))"
exit 3
fi
TASK="${TASKS[$SLURM_ARRAY_TASK_ID]}"
echo "[$(date -Iseconds)] Job ${SLURM_JOB_ID:-NA}, array task $SLURM_ARRAY_TASK_ID/$((TOTAL_TASKS - 1))"
echo "[$(date -Iseconds)] CWD: $(pwd)"
echo "[$(date -Iseconds)] Script dir: $SCRIPT_DIR"
echo "[$(date -Iseconds)] Submit dir: ${SLURM_SUBMIT_DIR:-NA}"
echo "[$(date -Iseconds)] Running: Rscript --vanilla fertilizer_scaling.R $TASK"
# Use module/system library stack on batch nodes; do not auto-activate project renv.
export RENV_CONFIG_AUTOLOADER_ENABLED=FALSE
# TASK is intentionally split into positional CLI args.
# shellcheck disable=SC2086
Rscript --vanilla fertilizer_scaling.R $TASK
RC=$?
echo "[$(date -Iseconds)] Finished with exit code $RC"
exit $RC