Running on HPC
On a cluster (HPC facility) MultiFlow is installed and built as described in Obtaining the code and Compiling the code, with a few differences:
- compilers, MPI and CMake come from the module system instead of system packages;
- everything is installed in your home or project directory, without administrator rights;
- you compile on a login node, but the simulations run on compute nodes, which you get from the batch system (on most clusters Slurm).
This page describes our set-up on the cluster sofja (GCC with the MVAPICH2 MPI, Slurm). Module names, paths and limits differ from cluster to cluster; the documentation of your HPC facility tells you which ones to use.
Setting environment variables
Modules
A module system makes software available by setting PATH, LD_LIBRARY_PATH and similar variables. The most
important commands:
| Command | Meaning |
|---|---|
module avail (or module spider <name>) |
list the available modules |
module load <name> ... |
load modules |
module list |
show the loaded modules |
module purge |
unload all modules |
You need a C/C++/Fortran compiler, an MPI library and CMake. On sofja these come with module load os mvapich2
cmake. Load the same modules whenever you build PETSc, the libraries and MultiFlow, and in every job script:
PETSc, MFTL2, IRL and MultiFlow must all be built with the same compiler and MPI, and run with the mpirun of that
MPI.
The MultiFlow variables
MultiFlow finds PETSc and the other libraries through environment variables (see
The environment). On a cluster it is easiest to set them, together with the modules,
at the end of ~/.bashrc, so that they are set in every login shell and in every job:
module purge
module load os mvapich2 cmake
export PETSC_DIR=$HOME/git/Code/petsc
export PETSC_ARCH=linux-mvapich
export MPI_HOME=$MPI_DIR # set by the mvapich2 module
export MF3_DIR=$HOME/git/Code/multiflow
export MFTL2_ROOT=$HOME/git/Code/MFTL2/build-install
export IRL_DIR=$HOME/git/Code/interface-reconstruction-library
export MFIRL_C_DIR=$HOME/git/Code/multiflow-irl-c-interface
| Variable | Meaning |
|---|---|
PETSC_DIR, PETSC_ARCH |
the PETSc directory and the name of the PETSc build (here linux-mvapich) |
MPI_HOME |
the directory of the MPI module (contains bin/mpicc) |
MF3_DIR |
the MultiFlow source directory |
MFTL2_ROOT |
the MFTL2 install prefix; enables front tracking |
IRL_DIR, MFIRL_C_DIR |
IRL and its C interface; enable IRL |
Many MPI modules set $MPI_DIR or $MPI_HOME; if yours does not, use
export MPI_HOME=$(dirname $(dirname $(which mpicc))). Leave out MFTL2_ROOT or IRL_DIR/MFIRL_C_DIR if you do not
use these libraries. After changing ~/.bashrc, log in again (or run source ~/.bashrc) and check the result with
module list
env | grep -E 'PETSC_|MPI_HOME|MF3_DIR|MFTL2_ROOT|IRL_DIR|MFIRL_C_DIR'
which mpicc mpirun
Where to put what. The home directory of a cluster is usually backed up but small; the sources and builds of PETSc, the libraries and MultiFlow fit there well. Simulation results are large: write them to the scratch or work file system of the cluster.
PETSc and other libraries
PETSc
On a cluster it is usually simplest to let PETSc download and build all libraries except MPI, including BLAS/LAPACK,
GSL and zlib, which may not be available as development packages. Use the MPI compiler wrappers of the loaded module.
We keep the build in a script, e.g. ~/petscbuild.sh:
#!/bin/bash
set -euo pipefail
export PETSC_ARCH="linux-mvapich"
module purge
module load os mvapich2 cmake
cd "$PETSC_DIR"
./configure --with-clean \
--with-debugging=0 \
COPTFLAGS="-O3 -march=native -mtune=native" \
CXXOPTFLAGS="-O3 -march=native -mtune=native" \
FOPTFLAGS="-O3 -march=native -mtune=native" \
--with-cc=mpicc --with-cxx=mpicxx --with-fc=mpif90 \
--with-mpi=1 \
--download-hdf5=1 \
--download-gsl=1 \
--download-fblaslapack=1 \
--download-metis=1 --download-parmetis=1 \
--download-p4est=1 --download-triangle=1 \
--download-tetgen=1 \
--download-zlib=1 \
--download-fftw=1 \
--download-slepc=1
make all
make check
Run it with bash ~/petscbuild.sh (with PETSC_DIR exported). Notes:
- Login nodes without internet access, or a download site that is down: give the tarball instead of
=1, e.g.--download-tetgen=$HOME/tarballs/tetgen1.6.0.tar.gzor--download-gsl=$HOME/tarballs/gsl-2.7.1.tar.gz(see Libraries from the system or downloaded by PETSc). -march=nativeoptimises for the processor of the machine where PETSc is compiled, and MultiFlow inherits these flags. If the login nodes have a different processor than the compute nodes, either build on a compute node (in an interactive job, e.g.srun --pty bashorsalloc), or replacenativeby the architecture of the compute nodes (e.g.-march=znver3,-march=icelake-server;gcc -march=native -Q --help=target | grep marchon a compute node shows it).- Vendor libraries: if the cluster provides an optimised BLAS/LAPACK (OpenBLAS, MKL) as a module, you can use it
with
--with-blaslapack-dir=<dir>instead of--download-fblaslapack. make checkruns small parallel tests throughmpiexec; on clusters that forbid MPI runs on login nodes, run it in an interactive job, or skip it and run a small MultiFlow example as a test instead.- A debug build is made the same way with another
PETSC_ARCH(e.g.linux-mvapich-dev), without--with-debugging=0and the*OPTFLAGS.
MFTL2
MFTL2 is built with the MPI wrapper of the loaded module (-DCMAKE_C_COMPILER=mpicc), so that it uses the same MPI as
PETSc and MultiFlow. We keep this in a script as well, e.g. ~/mftl2build.sh:
#!/bin/bash
set -euo pipefail
module purge
module load os mvapich2 cmake
cd $HOME/git/Code
[ -d MFTL2 ] || git clone git@git.multiflow.org:software/MFTL2.git # or https://git.multiflow.org/software/MFTL2.git
rm -rf MFTL2/build-release
cmake -S MFTL2 -B MFTL2/build-release \
-DCMAKE_BUILD_TYPE=Release \
-DMFTL_USE_LAPACK=ON \
-DCMAKE_C_COMPILER=mpicc \
-DCMAKE_INSTALL_PREFIX=$HOME/git/Code/MFTL2/build-install
cmake --build MFTL2/build-release -j8
cmake --install MFTL2/build-release
MFTL2_ROOT in ~/.bashrc points to this install prefix (above). Notes:
- LAPACK. Check that the configure output says
LAPACK : ON. If it saysOFF(with a warning that LAPACK was not found), MFTL2 is built without LAPACK, and MultiFlow's configure stops with MFTL2 … was built without LAPACK. CMake looks for a sharedliblapack/libblas(or OpenBLAS, MKL) in the system directories and inLD_LIBRARY_PATH; the BLAS/LAPACK that PETSc downloads (--download-fblaslapack) is not found this way. Load the BLAS/LAPACK module of the cluster (e.g.module load openblas; also in~/.bashrc, as MultiFlow links-lblas -llapacktoo), or point CMake to it with-DCMAKE_PREFIX_PATH=<dir>, and run the script again. - Updates. After a
git pullinMFTL2/, run the script again. MultiFlow refuses to build against an MFTL2 installation that is older than its sources. - From MFTL1. If you used the old MFTL before: remove
MFTL_DIRfrom~/.bashrc, setMFTL2_ROOT, update MultiFlow (git pull), and configure MultiFlow in a fresh build directory. The old MFTL1 checkout is no longer needed.
IRL and MultiFlow
With the modules loaded and the environment set, Eigen, IRL, its C interface and MultiFlow are built exactly as
described in Obtaining the code. MultiFlow itself always uses $MPI_HOME/bin/mpicc. Configure and
build it, e.g. with cmake --preset <example> and cmake --build build -j8 (see Compiling the code),
and check that the configure output shows
-- MFTL2_ROOT: /home/<user>/git/Code/MFTL2/build-install (front tracking enabled)
Compiling with many parallel jobs on a shared login node may be restricted; use a moderate -j or compile in an
interactive job.
One executable per case. The executable MF3 contains the user files of the case it was built for
(MF3_CASE_DIR), and a job uses the executable at the moment it starts, which can be long after it was submitted.
Keep a build directory per case, or copy MF3 into the case directory (cp build/MF3 $CASE/), so that rebuilding
MultiFlow for another case does not change a job that is still waiting in the queue.
Running a job
The batch system Slurm
The login nodes are shared by all users and are only meant for editing, compiling and small tests. Simulations run on
the compute nodes, which are handed out by a batch system; on most clusters, including sofja, this is
Slurm. You describe the job in a job script, a shell script with the resources it
needs (number of nodes and processes, maximum run time) in #SBATCH lines. You submit it with sbatch; Slurm puts it
into a queue, and runs the script on the allocated compute nodes as soon as they are available.
| Command | Meaning |
|---|---|
sbatch job.sh |
submit a job script; prints the job ID |
squeue -u $USER |
list your jobs (PD pending, R running) |
scontrol show job <id> |
details of a job: resources, nodes, working directory, reason for waiting |
scancel <id> |
cancel a job |
sinfo |
partitions (queues) and the state of their nodes |
sacct -j <id> |
accounting information of a finished job (run time, exit code, memory) |
salloc -N 1 --ntasks-per-node 4 / srun --pty bash |
an interactive job, e.g. to compile or test on a compute node |
The job script
The most important #SBATCH options:
| Option | Meaning |
|---|---|
--job-name=<name> |
the name shown by squeue |
--nodes=<n> |
the number of compute nodes |
--ntasks-per-node=<n> |
the number of MPI processes per node; usually the number of cores of a node |
--ntasks=<n> |
alternatively: the total number of MPI processes |
--time=<hh:mm:ss> |
the maximum run time (wall-clock); also d-hh:mm:ss. The job is stopped when it is reached |
--partition=<name> |
the partition (queue), if the cluster has several |
--output=<file>, --error=<file> |
files for standard output and standard error; %J (or %j) is replaced by the job ID |
--mem=<size> |
the memory per node, if the default is not enough |
--mail-type=END,FAIL, --mail-user=<address> |
e-mail when the job ends or fails |
The number of MPI processes is nodes x ntasks-per-node. Choose the number of processes so that each process has a
reasonable number of cells (as a rule of thumb at least a few thousand; for DEM, enough particles per process), and
choose a run time below the limit of the partition (sinfo or the documentation of the cluster). A job with a short
run time and few nodes usually starts earlier. Long simulations should write restart files regularly
(OutputRestartFrequency, see Input file), so that they can be continued in a new job.
A job script that we use on sofja:
#!/bin/bash
#SBATCH --job-name=FILFD-d3-12
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=36
#SBATCH --time=48:00:00
#SBATCH --error=job.%J.err
#SBATCH --output=job.%J.out
exec 2>&1 # send errors into the stdout stream (job.<id>.out)
# --- information about the job, useful when something goes wrong ---
echo "DEBUG: SLURM_JOB_NODELIST=$SLURM_JOB_NODELIST"
echo "DEBUG: SLURM_NNODES=$SLURM_NNODES"
echo "DEBUG: SLURM_TASKS_PER_NODE=$SLURM_TASKS_PER_NODE"
env | grep -e MPI -e SLURM
echo "DEBUG: host=$(hostname) pwd=$(pwd) ulimit=$(ulimit -v)"
scontrol show job $SLURM_JOBID # the Slurm settings of this job
# --- the same modules as for building PETSc and MultiFlow ---
module purge
module load os mvapich2
echo "DEBUG: LOADEDMODULES=$LOADEDMODULES"
export CASE_DIR=$PWD
HOSTFILE=${CASE_DIR}/slurm-$SLURM_JOBID.hosts
# --- check the free space on /dev/shm (used by MPI for communication within a node) ---
# one check process per node, independent of ntasks-per-node; the two nodes with the least space are shown
srun -l bash -c "[ \$SLURM_LOCALID != 0 ] || \
(df -k /dev/shm | tail -1; uname -n) | xargs" | sort -k 4n | tail -2
scontrol show hostnames $SLURM_JOB_NODELIST > $HOSTFILE # the allocated nodes, one line per node
# --- the simulation ---
mpirun build/MF3 -o FILFD-d3-12.mf -d results-FILFD-d3-12 > outfile-FILFD-d3-12
What the parts do:
#SBATCHlines. One node with 36 MPI processes (one per core) for at most 48 hours. Standard output and standard error go tojob.<id>.outandjob.<id>.err;exec 2>&1sends the errors of the script intojob.<id>.outas well, so that everything is in one file.- Diagnostics. The
echo,envandscontrol show joblines write the allocated nodes, the Slurm and MPI variables and the job settings tojob.<id>.out. They do not influence the run, but help a lot to find out why a job failed. The host file lists the allocated nodes for the same purpose. - Modules. The script loads the same compiler and MPI modules as used for building. Slurm passes the
environment of the shell from which you submit the job (with the variables of
~/.bashrc) to the job, soMF3_DIR,PETSC_DIRetc. are available. /dev/shmcheck. MPI uses the shared memory/dev/shmfor the communication between processes on the same node. If it is full (e.g. by a crashed earlier job), MPI jobs fail at start-up.srunstarts one process per node (SLURM_LOCALIDis 0 for the first task of every node), and the output shows the free space of the two nodes with the least space.- The simulation.
mpirunstarts MultiFlow on all processes of the allocation: within a Slurm job, thempirunof MVAPICH2 (and of most other MPI libraries) takes the nodes and the number of processes from Slurm, so-npis not needed.build/MF3is the executable of this case, relative to the case directory; the screen output of MultiFlow goes tooutfile-FILFD-d3-12, and the results toresults-FILFD-d3-12/.
The job runs in the directory from which it was submitted. To run it:
cd /path/to/my/case # contains the .mf file and build/MF3
sbatch job.sh
squeue -u $USER
tail -f outfile-FILFD-d3-12 # follow the simulation once it runs
Adapting the script
- More nodes. For larger runs increase
--nodes;mpirunthen startsnodes x ntasks-per-nodeprocesses. On some clusterssrun build/MF3 ...is used instead ofmpirun; this depends on how the MPI library was installed (see the documentation of the cluster). - Run time. Every partition has a maximum
--time. For simulations that take longer, write restart files and continue the simulation in a follow-up job (for example withsbatch --dependency=afterok:<id> job2.sh, which starts the second job when the first has finished successfully). - Several runs. Use a separate case directory, input file and output directory per job, and do not rebuild the executable of a case while one of its jobs is still waiting (see One executable per case).
- PETSc options. PETSc options can be appended to the MultiFlow command line, e.g.
-log_viewfor a performance summary at the end of the run.
Common problems
| Problem | Solution |
|---|---|
The job waits for a long time (PD) |
squeue -u $USER shows the reason (e.g. Resources, Priority). Fewer nodes or a shorter --time usually start earlier. |
| illegal instruction, or very slow | PETSc/MultiFlow were compiled with -march=native on a login node with another processor; rebuild on a compute node or with the compute nodes' -march (see PETSc). |
mpirun fails at start-up, or every process runs as rank 0 |
The job uses a different MPI than MultiFlow was built with: load the same MPI module in the job script, and check which mpirun in job.<id>.out. |
| MPI fails with errors about shared memory | /dev/shm on a node is full; the check in the script shows which node. Report it to the administrators of the cluster. |
| The job stops at the time limit | Increase --time (up to the limit of the partition), or continue from the restart files in a new job. |
| error while loading shared libraries | A module is not loaded in the job script; load the same modules as for building. |