Skip to content

Cluster jobs

This page shows how to send the points of a matrix to a cluster as jobs and how to pick their results up. You describe the scheduler of your cluster once, in a profile; the matrix and the commands stay the same.

Choosing a profile per row

Put profiles such as alpha.toml and beta.toml in inputs/hpc/ and select them in the last column:

POL | RUN | SETUP | REF | PPROC | VAR_NAMES_VALUES
----|-----|-------|-----|-------|-----------------
1001 | 1 | 001   | 001 | 001 | hpc: alpha / cluster: one
1002 | 1 | 001   | 001 | 001 | hpc: beta / cluster: two

cfd-matrix plan study previews both jobs and cfd-matrix run study submits each with its profile. The row selector wins over --hpc NAME; a row without one uses --hpc, or the only profile when there is one. With several profiles, a row without either selector is refused. --local ignores the row selector. The cluster value fills {cluster} in the selected profile, if it uses it.

The profile

A profile is a file inputs/hpc/<name>.toml. It says what the job description file of your scheduler looks like and which command submits it. cfdbender knows no scheduler: every field name and the submit command are yours.

inputs/hpc/h001.toml:

application_id = "CFD"
max_walltime = "96:00:00"
job_end_files = ["job.done"]

[descriptor]
format = "yaml"
name = "submit.yaml"

[descriptor.fields]
job_name = "{job_name}"
walltime = "{walltime}"
ncpus = "{ncpus}"
version = "{solver_version_alias}"
working_directory = "{workdir}"
config_file = "{config_path}"
output_file = "{stdout_log}"

[submit]
command = ["submit-tool", "{descriptor_path}"]

[builds]
"1.0" = "cfd-1.0"
Key Meaning
application_id The name your scheduler gives the application. Required.
max_walltime The longest wall clock the cluster grants a job, written HH:MM:SS. Optional.
job_end_files Optional list of marker paths relative to each point folder. Collect waits for every marker as well as the solver outputs.
walltime_arithmetic wall writes the WALLTIME cell as the row states it (4h); seconds writes whole seconds. Optional; wall when absent.
[descriptor] format The format of the job description file: yaml, json, toml or text.
[descriptor] name The name of that file. It is written in the folder of each point.
[descriptor.fields] The lines of that file. The names on the left are those your scheduler expects.
[submit] command The submit command, one word per list item.
[builds] For each SOLVER_BUILD a row may name, the name your cluster gives that build. It fills {solver_version_alias}.
[application_ids] For a SOLVER_BUILD, an application_id that replaces the general one. Optional.

A key the profile reader does not know is refused, with the list of the keys it reads, so a misspelt key cannot be ignored in silence.

A value in braces is filled for each point:

Placeholder Filled with
{job_name} The POL and the point name, for example 1001_DP-M200AL+000.
{ncpus}, {walltime} The NCPUS and WALLTIME cells of the row.
{cluster} The row's cluster entry in VAR_NAMES_VALUES.
{solver_version_alias} The [builds] entry of the row's SOLVER_BUILD.
{workdir} The folder of the point.
{config_path}, {script_path} The file the solver reads, in the folder of the point.
{stdout_log}, {stderr_log} stdout.log and stderr.log in the folder of the point.
{descriptor_path} The job description file, for the submit command.

Choosing the cluster per row

Put a placeholder in the profile's descriptor fields:

[descriptor.fields]
cluster = "{cluster}"

Then choose a value in each row using the same profile:

POL | RUN | SETUP | REF | PPROC | VAR_NAMES_VALUES
----|-----|-------|-----|-------|-----------------
1001 | 1 | 001   | 001 | 001 | cluster: alpha

The placeholder also works in the submit command. A row without a value is refused when the profile uses it. An unused row value produces a warning; --warning-refusals makes that warning a refusal. Local runs ignore it.

Overriding the profile per row

The profile is the base of every row. A row can replace one value of it with an hpc.<name> entry in VAR_NAMES_VALUES, next to the hpc: selector:

POL | RUN | SETUP | REF | PPROC | VAR_NAMES_VALUES
----|-----|-------|-----|-------|-----------------
1001 | 1 | 001   | 001 | 001 | hpc: alpha / cluster: one
1002 | 1 | 001   | 001 | 001 | hpc: alpha / hpc.cluster: two / hpc.mode: custom / hpc.application_id: "tools/run_all.sh"

Row 1002 uses the profile alpha with {cluster} set to two, the descriptor field mode written as custom, and tools/run_all.sh as the application. Every other value of the profile is kept.

Name Replaces
a field of [descriptor.fields] That field's line, with the text of the entry.
application_id What the job launches: {application_id} in the descriptor and in the submit command. It takes a solver executable, an installed command, or a script of the workspace.
cluster {cluster}, when the profile uses it.

A name the profile does not declare is refused with the names it accepts. NCPUS and WALLTIME are not overridden here: state them in their columns. An application with a folder or a script extension (.py, .sh) is a file of the workspace, written relative to it between double quotes; it is checked when the plan is made, and written to the descriptor as its absolute path. A row with an hpc.<name> entry needs a selected profile (hpc: in the row, or --hpc), and --local ignores the entries with one warning. The plan record and the run record keep each override with its origin, matrix row.

Grouping rows into jobs: --batch N

cfd-matrix plan study --batch 2 and cfd-matrix run study --batch 2 submit the rows as N scheduler jobs instead of one job per point. N is the number of jobs, as in pyflightstream. The rows (POL, with all their points) are grouped first by profile, processor count (NCPUS) and solver build (SOLVER_BUILD). Within each group, rows retain matrix order and are cut into contiguous jobs so that the longest job is as short as possible (a row's weight is its WALLTIME cells, else one per point); a row is never cut. For interleaved profiles A, B, A on rows 1, 2, 3, --batch 2 produces jobs [1, 3] and [2], in the order of each job's first row. Contiguity is within each group, not across the original matrix. A job holds one profile, one processor count and one solver build. A request below the number of groups produces one job per group, and a request above the number of rows produces one job per row; both warn. The WALLTIME of a job is computed as for a grouped job, and BEST is accepted.

Each job lives in sims/batch/<matrix>_b<ID>/, where <ID> is the next free number of the matrix. There cfd-matrix run writes the descriptor of the job and a shell script, BATCH-<first row>-<last row>.sh, with LF line endings and the executable bit set:

#!/bin/sh
set -u
cd "$(dirname "$0")" || exit 2
failed=0

# 1001/DP-M200AL+000
( cd ../../sim_1001/datapoints/DP-M200AL+000 && SU2_CFD su2.cfg > stdout.log 2> stderr.log )
rc=$?
printf '%s\n' "$rc" > ../../sim_1001/datapoints/DP-M200AL+000/job.exit.tmp && mv ../../sim_1001/datapoints/DP-M200AL+000/job.exit.tmp ../../sim_1001/datapoints/DP-M200AL+000/job.exit
[ "$rc" -eq 0 ] || failed=1

exit "$failed"

The script holds one block per run, in matrix order. Each run starts in its own point folder, by a path relative to the script, with the command line of its row: the adapter's (su2.cfg read by SU2_CFD, the executable and launcher as the setup states them) or the row's hpc.application_id. No restart or solution file passes from one run to the next. A failed run does not stop the next one; its exit status is written to job.exit in its folder, and the script exits non-zero when any run failed. collect waits for job.exit of each run and marks a run failed when it holds a status other than 0.

The descriptor of the job is rendered from the profile as for one point, with {workdir} the job folder, {job_name} the batch name (study_b1), {sims} its rows, {batch} the N, {batch_id} the number, and {script_path} the script, written relative to the job folder. A profile whose job runs a custom command points at the script, for example:

[descriptor.fields]
job_name = "{job_name}"
mode = "custom"
command = "{script_path}"
ncpus = "{ncpus}"
walltime = "{walltime}"
mode: "custom"
command: "BATCH-1001-1003.sh"
job_name: "study_b1"

Rows of one job whose hpc.<name> entries (or cluster) disagree are refused, naming both rows: a job has one value of each. hpc.application_id may differ between rows, because each run has its own command. --batch needs an HPC profile, cannot be combined with --local, --resume, --restart or --force-rerun (it takes --force-rerun-all: a forced rerun of a grouped submission needs no new plan when only the batch folder numbers moved, and the new batch gets a new folder), and run --batch N needs a plan --batch N made for the same N. A solver adapter without a command line of its own (job_command) is grouped only for rows that state hpc.application_id.

One job per polar: --batch-per-polar

cfd-matrix plan study --batch-per-polar and cfd-matrix run study --batch-per-polar submit one job per polar, a matrix row (POL) with all its points. Nothing is split or merged: row 1001 is study_b1, row 1002 is study_b2, and so on, each in its own sims/batch/<matrix>_b<ID>/ with its own BATCH-<POL>-<POL>.sh. Inside a job the points of the row run one after another in the order of the sweep, each in its own point folder, so a polar whose points follow one another keeps its sequence in its own script. The job takes the row's NCPUS, its solver build and its hpc.<name> values; its wall clock is the sum of the WALLTIME of its points, capped by the profile's max_walltime with the warning that cap already gives. The descriptor, the script, the status files and collect are those of --batch.

It is the same grouping as --batch N with one row per job, and the same refusals apply: an HPC profile is needed, and it cannot be combined with --local, --resume, --restart or --force-rerun (--force-rerun-all is accepted), nor with --batch N. run --batch-per-polar needs a plan --batch-per-polar. A selection (--sims, --points) plans the polars it touches, each holding only the selected points.

A row whose RESTART names a point of the same job, earlier in it, is not refused although the source has not run: the script stages the source's restart file after the source ends with status 0, before the dependent's command (or its hpc.application_id wrapper) is called, with cp alone: the job script needs only a POSIX shell, no Python on the node; see restart.

A point that starts from a frozen-rotor solution

A time-accurate sliding rotor row whose RESTART cell is MRF runs two solver stages in its point folder (precursor.cfg, then su2.cfg; see SU2 workspaces), and the solver is launched twice through the same launcher. cfdbender writes run_mrf.sh into the folder and its batch block runs sh run_mrf.sh <the row's command without its configuration file>:

( cd ../../sim_1001/datapoints/DP-M053AL+004RPM00955 && sh run_mrf.sh sh ../../../../tools/su2.sh > stdout.log 2> stderr.log )

The script calls the command once per stage with the stage's configuration file as its last argument. That is the contract of the command already (it receives su2.cfg), so a launcher or an application wrapper that ends in "$@" needs nothing; one that runs a fixed file does not:

#!/bin/sh
exec mpirun -np 16 SU2_CFD "$@"      # the stage's file is the last argument; do not name su2.cfg here

A wrapper that ignores its argument and runs su2.cfg both times is caught: stage 1 then ends without precursor_restart_<zone>.dat, or SU2 stops because the staged solution is missing, and the point's job.exit is 91 with the line PRECURSOR_FAILED: ... the command must run the configuration file it is given as its last argument in stderr.log; stage 2 never starts.

The exit statuses of such a point are 91 (stage 1 ended non-zero, or ran nothing), 92 (NaN in precursor.csv), 93 (a restart file of stage 1 is missing or empty), 94 (staging a copy failed), or stage 2's own status. 97 and 98 stay those of an in-job RESTART source. A stage 1 that ends at its iteration cap without meeting [precursor] converge_to is not a failure; the point's stdout.log gets one PRECURSOR_WARNING line. Every file is written at submission and the job needs only a POSIX shell (cp, grep): no Python runs on the node.

Without --batch the per-point descriptor is rendered from the profile as for any point and the scheduler runs the profile's own application, which cfdbender cannot see: the folder holds run_mrf.sh and the job command must be sh run_mrf.sh <launcher and solver>, as an export window's run_segments.sh is run. A profile that runs su2.cfg directly runs the time-accurate stage without its staged solution, which SU2 refuses (Unable to open SU2 restart file), so the point fails and is never a silent cold start. A local run does both stages itself.

See what would be submitted

With a profile in inputs/hpc/, plan adds the job description of each point and the command that would submit it. It submits nothing. For a matrix row with NCPUS 16, WALLTIME 2h and SOLVER_BUILD 1.0, in a workspace at /home/you/cluster:

cfd-matrix plan polar
descriptor: /home/you/cluster/sims/sim_1001/datapoints/DP-M200AL+000/submit.yaml
job_name: "1001_DP-M200AL+000"
walltime: "2h"
ncpus: 16
version: "cfd-1.0"
working_directory: "/home/you/cluster/sims/sim_1001/datapoints/DP-M200AL+000"
config_file: "/home/you/cluster/sims/sim_1001/datapoints/DP-M200AL+000/mock.in"
output_file: "/home/you/cluster/sims/sim_1001/datapoints/DP-M200AL+000/stdout.log"
would submit: submit-tool /home/you/cluster/sims/sim_1001/datapoints/DP-M200AL+000/submit.yaml

These lines follow the list of points that plan always prints.

Submit

cfd-matrix run polar

With a profile, run prepares the folder of each point, writes the job description there, runs the submit command, and records the point as SUBMITTED. It does not wait for the jobs.

The folder of a point holds every file the solver reads, so the job needs nothing else from the workspace:

Solver Prepared in the folder of the point {config_path} The job must write
su2 su2.cfg, the mesh (mesh.su2 or mesh.cgns) su2.cfg history.csv, stdout.log
openfoam the case folders system, constant, 0, the script Allrun, the mesh Allrun log.simpleFoam (log.pimpleFoam on the LTS route), postProcessing/forceCoeffs/0/coefficient.dat
pyfr case.ini, mesh.msh case.ini forces.csv
xfoil xfoil.in, and airfoil.dat when the row names a coordinate file xfoil.in polar.txt, stdout.log
qprop propeller.prop, qcon.def, sections.json propeller.prop stdout.log

Point the output file of your scheduler at {stdout_log}. Several solvers print their results there, and collect reads that file.

The mesh is a link to the file in inputs/mesh/, written relative to the workspace, so it still works after the whole workspace is copied to the cluster. A point whose files cannot be prepared is recorded as failed with FAILED_STAGING and is not submitted.

Choose where a matrix runs

If an adapter cannot stage a cluster job, the request is skipped with a warning. The warning prints the complete command to type to run locally, preserving your matrix, workspace and selection arguments and adding --local. When plan falls back to a local preview, it checks the local build and executable before reporting success.

Situation What run does
No file in inputs/hpc/ Runs on this machine.
One profile Submits with it. --local runs on this machine instead.
Several profiles Select each row with hpc: NAME, use --hpc NAME as a default, or choose --local.

Pick the results up

cfd-matrix collect polar

collect looks at each submitted point. When the files its job must write are there, it reads them, records the point as COMPLETED with its verdict, and adds it to the tables. A point whose files are not there yet stays SUBMITTED and is counted as outstanding; the exit code is then 3.

cfd-matrix collect polar --watch

--watch repeats the collect until no point is outstanding. --watch-interval sets the seconds between two rounds (60 when absent) and --rounds stops after a number of rounds. Under --watch a file counts as finished when its size and its time of change are the same on two looks 2 s apart; --interval sets that time. An output replaced or removed between observations remains outstanding and is checked again on the next collect.

For a reliable end signal, set job_end_files = ["job.done"] above the first table of the profile. Arrange for the cluster job to write job.done in the point folder only after the solver has closed its outputs, for example with touch job.done as the job script's last command. Marker paths are saved in submission.job_end_files in runs.json. Changing the profile later does not change what an already submitted job must write. --interval checks that the markers and numerical output files have unchanged sizes and modification times.

A cluster job leaves no record of how its process ended, so the verdict of a submitted point rests on the numbers in its output alone.

Builds on a cluster

A cluster job does not read inputs/executables.toml. The SOLVER_BUILD of the row is translated by the [builds] table of the profile, and the job description carries the result. Executables covers runs on your machine.

Redoing a submitted point

A RESTART row or run --restart stages copied solution inputs in the job folder too. SU2's cfg and OpenFOAM's Allrun select the saved state. For PyFR, when restart.pyfrs is present the job must run pyfr restart -b <backend> mesh.pyfrm restart.pyfrs case.ini with the saved native mesh, instead of importing the mesh again and running pyfr run. Only completed source points can be restarted. A submitted point must be collected before it can supply a restart solution.

cfd-matrix run polar --force-rerun POINT archives the point and submits it again. It does not cancel the earlier job: cancel it in your scheduler first. See Run again, resume, records.