#!/bin/bash
#SBATCH --job-name=SingularityMPI      # name of job
#SBATCH --ntasks=40                    # total number of MPI processes
#SBATCH --ntasks-per-node=40           # number of MPI processes per node
# /!\ Caution, "multithread" in Slurm vocabulary refers to hyperthreading.
#SBATCH --hint=nomultithread           # 1 MPI process per physical core (no hyperthreading)
#SBATCH --time=00:10:00                # maximum execution time requested (HH:MM:SS)
#SBATCH --output=SingularityMPI%j.out  # name of output file
#SBATCH --error=SingularityMPI%j.out   # name of error file (here, in common with output)

# go into the submission directory
cd ${SLURM_SUBMIT_DIR}

# clean out the modules loaded in interactive and inherited by default
module purge

# loading modules
module load singularity

# echo of launched commands
set -x

# code execution from the allowed execution space
# According to the MPI implementation installed in the container, the srun MPI option must be set to --mpi=pmix_v2 or --mpi=pmix_v3
srun --mpi=pmix_v2 singularity exec $SINGULARITY_ALLOWED_DIR/my-container_CPU.sif ./exec_mpi