Skip to main content
⚠ INFORMATION
This page was translated by an AI (LLM) with a cursory human check and is awaiting full review.

Running an OpenMP parallel code in batch

Jobs are managed across all nodes by the Slurm software.

To submit an OpenMP job in batch on Jean Zay, you need to:

  1. Create a submission script:
openmp.slurm
#!/bin/bash
#SBATCH --job-name=omp # nom du job
#SBATCH --nodes=1 # nombre de noeuds
#SBATCH --ntasks=1 # nombre de tâche (un unique processus ici)
#SBATCH --cpus-per-task=20 # nombre de threads OpenMP
# /!\ Attention, la ligne suivante est trompeuse mais dans le vocabulaire
# de Slurm "multithread" fait bien référence à l'hyperthreading.
#SBATCH --hint=nomultithread # on réserve des coeurs physiques et non logiques
#SBATCH --time=00:10:00 # temps d'exécution maximum demande (HH:MM:SS)
#SBATCH --output=omp%j.out # nom du fichier de sortie (%j est remplacé par le numéro du travail)
#SBATCH --error=omp%j.out # nom du fichier d'erreur (ici commun avec la sortie)

# nettoyage des modules charges en interactif et herites par defaut
module purge

# chargement des modules
module load ...

# echo des commandes lancées
set -x

# nombre de threads OpenMP
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

# Binding
export OMP_PLACES=cores

# exécution du code
./executable_omp
  1. Submit this script via the sbatch command:
sbatch openmp.slurm

Notes:

  • We recommend compiling and running your code in the same software environment by loading the same modules.
  • The --hint=nomultithread option ensures the reservation of physical cores (no hyperthreading).
  • The memory allocated for the job is proportional to the number of CPU cores requested. For example, if you request 1/4 of the physical CPU cores of a node, you will have access to 1/4 of its RAM memory. It is important to be consistent with the configuration of the nodes used to avoid overcharging of hours while taking advantage of the memory you are entitled to. You can consult our documentation on this subject: Memory allocation with Slurm.
  • In these examples, it is assumed that the executable executable_omp is located in the submission directory, i.e., the directory in which you are located when using the sbatch command: the $SLURM_SUBMIT_DIR variable is automatically set by Slurm.
  • The output file of the calculation will also be located in the submission directory. It is created at the beginning of the job execution; editing or modifying it during the job execution may disrupt it.
  • The module purge is made necessary by Slurm's default behaviour: the modules you have loaded in your environment at the time you run sbatch are taken into account in the submitted job.
  • All jobs have resources defined by a partition and a "Quality of Service" QoS set by default in Slurm. You can modify these limits by specifying a partition and/or a QoS as indicated in our documentation detailing CPU partitions and QoS.
  • For multi-project accounts as well as those with CPU and GPU hours, it is essential to specify the hour allocation on which to deduct the computing hours of the job as indicated in our documentation detailing the management of computing hours to ensure that the hours consumed by your jobs are deducted from the correct allocation.

Your opinion matters!

To give your feedback, report an error, or suggest an improvement, click here:

quick anonymous questionnaire

This questionnaire is temporary and will take less than a minute, so take the opportunity!