# MPI Jobs

MPI jobs run a single program across multiple processes, potentially spanning several nodes. Use the **Tasks** and **Tasks per node** fields to configure the MPI layout.

## Fields to set

<table id="bkmrk-field-sbatch-equival"><thead><tr><th>Field</th><th>sbatch equivalent</th><th>When to use</th></tr></thead><tbody><tr><td>**Nodes**</td><td>`--nodes`</td><td>Number of nodes to allocate.</td></tr><tr><td>**Tasks**</td><td>`--ntasks`</td><td>Total MPI process count across all nodes.</td></tr><tr><td>**Tasks per node**</td><td>`--ntasks-per-node`</td><td>MPI processes per node. Use instead of Tasks when you want even distribution.</td></tr><tr><td>**CPUs per task**</td><td>`--cpus-per-task`</td><td>Threads per MPI process. Set to 1 for pure MPI; higher for hybrid MPI+OpenMP.</td></tr></tbody></table>

## Example — pure MPI, 4 nodes × 32 tasks

```bash
module load openmpi/openmpi-5.0.7-rocky9-slurm
cd $HOME/myproject

mpirun ./simulate --config config.yaml

```

Set **Nodes** to `4`, **Tasks per node** to `32`, **CPUs per task** to `1`. Do not pass `-n` to `mpirun` — Slurm passes the process count automatically via PMI.

## Example — hybrid MPI + OpenMP

```bash
module load openmpi/openmpi-5.0.7-rocky9-slurm
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
cd $HOME/myproject

mpirun ./simulate --config config.yaml

```

Set **Tasks per node** to the number of MPI ranks per node, and **CPUs per task** to the number of OpenMP threads. The product of the two should not exceed the node's core count.

## Choosing a partition

MPI jobs that span nodes require a partition with inter-node connectivity. Check with HPC support if you are unsure which partition to use for multi-node jobs.