Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Excerpt

Singularity is a container platform: it lets you create and run containers that package up pieces of software in a way that is portable and reproducible. With a few basic commands, you can set up a workflow to run on Pawsey systems using Singularity. This page introduces how to get or build a Singularity container image and run that image on HPC systems.

...

$ module avail singularity

and then load the singularity module (for applications that do not need mpi, like for many of the bioinformatics containers):

$ module load singularity/3.8.6-mpi

...

nompi


Or, for applications that do not need mpi (like for many of the bioinformatics containers):.

$ module load singularity/3.8.6-nompimpi

To avoid errors when downloading and running containers, run the sequence of commands in the following terminal display:

...

You can pull existing containers from a suitable registry such as Docker Hub, Biocontainers, RedHat Quay or Sylabs Container Library.Quay or Sylabs Container Library. For most users, this will be the most common way you will use containers. It's a good idea to check what containers are already available before deciding to build your own container. 

To import Docker images from, for example, Docker Hub, you can use the  singularity pull  command. As Docker images are written in layers, Singularity pulls the layers instead of just downloading the image, then combines them into a Singularity SIF format container. 

...

To build a container image, we recommend using Docker, either on a local laptop or workstation or on a cloud virtual machine. For example, the Pawsey Nimbus Cloud has Ubuntu installations that come with both Singularity and Docker pre-installed. You cannot build a container image on Setonix because you will not have admin/sudo privileges. 

Docker is recommended for: 

  • Compatibility, portability and shareability: Docker images can be run by any container runtimeengine, while Singularity images can only be run by Singularity.
  • Ease of development: layer caching in Docker may significantly speed up the process of performing repeated image builds. In addition, Docker allows writing in containers by default, allowing for tests on the fly.
  • Community adoption: community experience and know-how in writing good image recipes focuses on Docker and Dockerfiles.

...

  • Minimize image size
    • Each distinct instruction (such as RUN, CMD, etc) in the Dockerfile generates another layer in the container, increasing its size
    • To minimize image size, use multi-line commands, and clean up package manager caches.

  • Avoid software bloat

    • Only install the software you need for a given application into a container.
  • Make containers modular
    • Creating giant, monolithic containers with every possible application you could need is bad practice. It increases image size, reduces performance, and increases complexity. Containers should only contain a few applications (ideally only one) that you'll use. You can chain together workflows that use multiple containers, meaning if you need to change a particular portion you only need to update a single, small container.

...

Listing 3 shows an example of running Gromacs , a popular molecular dynamics package, among the ones that have been optimised to run on GPUs through NVIDIA containers:

Column
width900px


Code Block
languagebash
themeEmacs
titleListing 3. Enabling a container to use GPUs
collapsetrue
#!/bin/bash -l
#SBATCH --job-name=gpu
#SBATCH --gres=gpu:1
#SBATCH --ntasks=1
#SBATCH --time=01:00:00

# Load Singularity
module load singularity/3.8.6-mpi

# Define the container to use
export myRepository=$MYSCRATCH/singularity/myRepository
export containerImage=$myRepository/gromacs_2018.2.sif

# Run Gromacs preliminary step with container
srun singularity exec --nvrocm $containerImage gmx grompp -f pme.mdp

# Run Gromacs MD with container
srun singularity exec --nvrocm $containerImage \
    					   gmx mdrun -ntmpi 1 -nb gpu -pin on -v \
                           -noconfout -nsteps 5000 -s topol.tpr -ntomp 1


...

$ sbatch --account=<your-pawsey-project> --partition=gpuq gpu gpu.sh

Using MPI

MPI applications can be run within Singularity containers. There are two requirements to do so:

...

Column
width900px


Code Block
languagebash
themeEmacs
titleListing 4. Running an MPI application within a Singularity container
collapsetrue
#!/bin/bash -l

#SBATCH --account=projectID
#SBATCH --job-name=mpi-OpenFOAMcase
#SBATCH --ntasks=512
#SBATCH --ntasks-per-node=128
#SBATCH --cpus-per-task=1
#SBATCH --exclusive
#SBATCH --time=00:20:00
#SBATCH --partition=work

# ---
# load Singularity
module load singularity/3.8.6-mpi

# ---
# Note we avoid any inadvertent OpenMP threading by setting OMP_NUM_THREADS=1
export OMP_NUM_THREADS=1

# ---
# Set MPI related environment variables for your system (see specific system guides).
export MPICH_OFI_STARTUP_CONNECT=1
export MPICH_OFI_VERBOSE=1

# ---
# Define the container to use
export theRepository=<pathToPersonalImages>
export containerImage=$theRepository/openfoam-v1912.sif

# ---
# cd into the case directory
cd $MYSCRATCH/myOpenFOAMCase

# ---
# execute the simpleFoam parallel solver with MPI
srun -N $SLURM_JOB_NUM_NODES -n $SLURM_NTASKS -c $OMP_NUM_THREADS \
     singularity exec $containerImage simpleFoam -parallel -fileHandler collated | tee log.simpleFoam

Notes:

  • srun is the Slurm wrapper for the MPI launcher.
  • -n is the flag to indicate the number of processes to be run (512 in this case, as it is the value of the Slurm variable SLURM_NTASKS).
  • Singularity modules at Pawsey have been prepared to automatically set up the right bind mounts of the host MPI paths into the SINGULARITY_BINDPATH and SINGULARITYENV_LD_LIBRARY_PATH variables, so no further action is needed for bind mounting.
  • -parallel  and -fileHandler collated flags are part of OpenFOAM. They are not Singularity or Slurm flags.

...