Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 17 additions & 29 deletions example-configs/density_skj_fat/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import csv
import pandas as pd
import matplotlib.pyplot as plt

# snakemake --jobs 10 --cluster "sbatch -p genoa --mem=20g --nodes=1 --ntasks-per-node={threads} --cpus-per-task=1 --time=01:30:00 --extra-node-info=1:*:1 --distribution=*:block:* --mem-bind=local"
# snakemake --jobs 10 --cluster "sbatch -p genoa --mem=60g --nodes=1 --ntasks-per-node={threads} --cpus-per-task=1 --time=01:30:00 --extra-node-info=1:*:1 --distribution=*:block:* --mem-bind=local"
#

# MPI benchmarking configurations
#N_VALUES = [2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,28,29,30,31,32]
#N_VALUES = [2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,36,40,50]
N_VALUES = [2,3,4,5,6,7,8,9,10,11,12,14,16,17,18,20,22,24,26,28,32,36,40,44,51]
#N_VALUES = [10, 20, ]
REPEATS = range(0,6)
#HOSTS = ["milan", "genoa"]
PROCS = [3, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101]
REPEATS = range(0,3)
HOSTS = ["genoa",]
CASES = ["aplus", "aplus3"]

# -----------------------------
# Top-level workflow
Expand All @@ -27,20 +24,17 @@ rule all:
# -----------------------------
rule run_mpi:
output:
main="results/run_{n}_{r}_{h}-main.out",
best="results/run_{n}_{r}_{h}-best.out"
exp="results/run_{n}_{r}_{h}_{c}.out",
params:
exe_main="../../bin/seapodym_cohort-main",
exe_best="../../bin/seapodym_cohort-best",
parfile="skj_fat.xml"
parfile="../density_skj_fat/skj_Fat.xml"
threads:
lambda wc: int(wc.n)
shell:
r"""
set -x
cd ~/nesi99999/seapodym-codebase-test_shm/
cd ~/nesi99999/seapodym-codebase-exp/

source sourceme-main.sh
source sourceme-exp.sh

cd example-configs/density_skj_fat
mkdir -p results
Expand All @@ -51,19 +45,14 @@ rule run_mpi:
rm -rf $rundir
mkdir $rundir
cd $rundir
# copy the input file
cp ../density_skj_fat/{params.parfile} .


# run main
echo "jobid=$SLURM_JOB_ID" > ../density_skj_fat/{output.main}
srun --distribution=block:block --cpu-bind=cores --cpus-per-task=1 \
{params.exe_main} -s {params.parfile} >> ../density_skj_fat/{output.main} 2>&1

# create directories
mkdir -p output/output_F0/

# run best
echo "jobid=$SLURM_JOB_ID" > ../density_skj_fat/{output.best}
srun --distribution=block:block --cpu-bind=cores --cpus-per-task=1 \
{params.exe_best} -s {params.parfile} >> ../density_skj_fat/{output.best} 2>&1
# run
echo "jobid=$SLURM_JOB_ID" > ../density_skj_fat/{output.exp}
srun --ntasks={threads} --distribution=block:block --cpu-bind=cores --cpus-per-task=1 \
../../bin/seapodym_cohort_{wildcards.c} -s {params.parfile} >> ../density_skj_fat/{output.exp} 2>&1

cd ../
# clean up
Expand All @@ -77,13 +66,12 @@ rule run_mpi:
# -----------------------------
rule collect_results:
input:
expand("results/run_{n}_{r}_{h}-main.out", n=N_VALUES, r=REPEATS, h=HOSTS),
expand("results/run_{n}_{r}_{h}-best.out", n=N_VALUES, r=REPEATS, h=HOSTS)
expand("results/run_{n}_{r}_{h}_{c}.out", n=PROCS, r=REPEATS, h=HOSTS, c=CASES),
output:
"results/timings.csv"
shell:
r"""
module load Python
python assemble_timings.py -d results -o results/timings.csv
python assemble_timings_aplus.py -d results -o results/timings.csv
"""

48 changes: 48 additions & 0 deletions example-configs/density_skj_fat/assemble_timings_aplus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import re
import glob
import defopt
import csv


def main(*, dir : str='results', output : str='results/timings.csv'):
"""
Assemble timings into a csv file
:param dir directory
"""
pattern = re.compile(r"time manager\s*=\s*([0-9.]+)")
rows = []

for f in glob.glob(dir + '/run*.out'):

print(f'working on {f}...')

parts = f.split("/")[-1].replace(".out","").split("_")
n = int(parts[1])
r = int(parts[2])
host = parts[3]
case = parts[4]

jobid = None
manager_time = None

with open(f) as fh:
for line in fh:
if line.startswith("jobid="):
jobid = line.split("=")[1].strip()
m = pattern.search(line)
if m:
manager_time = float(m.group(1))
print(f'manager time = {manager_time}')

rows.append((n, jobid, host, case, manager_time))

rows.sort()

with open(output, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["nprocs","jobid","host","case", "manager_time"])
writer.writerows(rows)

if __name__ == '__main__':
defopt.run(main)

59 changes: 59 additions & 0 deletions example-configs/density_skj_fat/plot_timings_aplus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import defopt


def main(*, input_file: str='results/timings.csv', output_file: str='results/timings.png', show: bool=False):
"""
input_file: CSV input file (e.g. results/timings.csv)
output_file: PNG output file
show: set to True to display
"""

# Load CSV
df = pd.read_csv(input_file)

# Ensure manager_time column exists
if "manager_time" not in df.columns:
print(f"ERROR: 'manager_time' column not found in CSV. Cannot plot.")

# Drop rows with missing manager_time
df = df.dropna(subset=["manager_time"])
if df.empty:
print(f"ERROR: No valid 'manager_time' values found. Cannot plot.")

# Plot curves for Milan & Genoa
cols = {
'aplus': 'b',
'aplus3': 'm',
}
plt.figure(figsize=(8,6))
for case in df["case"].unique():
df2 = df[df.case == case]
df_min = df2.groupby(["nprocs"])["manager_time"].min().reset_index()
df_avg = df2.groupby(["nprocs"])["manager_time"].mean().reset_index()
df_max = df2.groupby(["nprocs"])["manager_time"].max().reset_index()

col = cols[case]
plt.loglog(df_min["nprocs"], df_min["manager_time"], col + '-.', label=case + ' min')
plt.loglog(df_avg["nprocs"], df_avg["manager_time"], col + '-', label=case + ' avg')
plt.loglog(df_max["nprocs"], df_max["manager_time"], col + '--', label=case + ' max')

plt.loglog([1,100], 1000./np.array([1,100]), 'k-', label='ideal')

plt.xlabel("Number of processes (nprocs)")
plt.ylabel("Manager time s")
plt.title("Seapodym cohort timings 1983-2022 skj_Fat.xml A+")
plt.xticks(sorted(df["nprocs"].unique()))
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.savefig(output_file)
if show:
plt.show()
print(f"plot saved to {output_file}")

if __name__ == '__main__':
defopt.run(main)
10 changes: 3 additions & 7 deletions example-configs/density_skj_fat/rungenoa.sl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
#SBATCH --time=00:10:00 # walltime (adjust as needed)
#SBATCH --partition=genoa
#SBATCH --nodes=1
#SBATCH --ntasks=24
#SBATCH --mem-per-cpu=4g
#SBATCH --ntasks=51
#SBATCH --mem=25g
#SBATCH --cpus-per-task=1
#SBATCH --output=seapodym_%j.out
#SBATCH --error=seapodym_%j.err
##SBATCH --profile task
##SBATCH --acctg-freq=1
#SBATCH --extra-node-info=1:*:1
#SBATCH --distribution=*:block:*
#SBATCH --mem-bind=local
Expand All @@ -20,4 +16,4 @@ module load gimkl/2020a
rm log_*.txt

# Run the MPI job
srun ../../bin/seapodym_cohort -s skj_fat.xml >& results/n${SLURM_NTASKS}.txt
srun ../../bin/seapodym_cohort -s skj_fat.xml
24 changes: 20 additions & 4 deletions example-configs/density_skj_fat/skj_fat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
</life_stage>

<nb_cohort_life_stage>
<skj>1 2 47</skj>
<skj>1 2 97</skj>
</nb_cohort_life_stage>

<age_recruit skj="3"/>
Expand All @@ -255,23 +255,39 @@
30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30
30 330</skj>
30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 30 30 30 30 30 30 30 30 30
30 30 30 2970
</skj>
</sp_unit_cohort>

<length>
<skj>3 4.5 7.52 11.65 16.91 21.83 26.43 30.72 34.73 38.49 41.99 45.27
48.33 51.19 53.86 56.36 58.70 60.88 62.92 64.83 66.61 68.27 69.83 71.28
72.64 73.91 75.10 76.21 77.25 78.22 79.12 79.97 80.76 81.50 82.19 82.83
83.50 83.50 83.50 83.50 83.50 83.50 83.50 83.50 83.50 83.50 83.50 83.50
85.00 87.96 </skj>
85.00 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96
87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96
87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96
87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96
87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96 87.96
</skj>
</length>

<weight>
<skj>0.0003 0.00109 0.00571 0.023 0.08 0.18 0.32 0.53 0.78 1.09 1.44 1.84
2.27 2.73 3.21 3.72 4.23 4.76 5.30 5.83 6.36 6.89 7.40 7.91
8.41 8.89 9.36 9.81 10.25 10.66 11.07 11.45 11.82 12.17 12.51 12.83
13.5 13.5 13.5 13.5 13.50 13.50 13.50 13.50 13.50 13.50 13.50 13.50
14.0 15.56 </skj>
14.0 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56
15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56
15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56
15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56
15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56
15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56 15.56
</skj>
</weight>


Expand Down
Loading