|
|
|
### Code example
|
|
|
|
|
|
|
|
We will use an [OpenMP](https://en.wikipedia.org/wiki/OpenMP) job as example, you can create a [openmp.cpp](https://gitlab.oca.eu/DSI/HPC/blob/master/SLURM/multithread/openmp.cpp) test program and compile it with:
|
|
|
|
```
|
|
|
|
$icpc -qopenmp ./openmp.cpp -o openmp
|
|
|
|
$
|
|
|
|
```
|
|
|
|
the '-qopenmp' option will tell the compiler to recognize the [OpenMP pragmas](https://en.wikipedia.org/wiki/OpenMP#Clauses).
|
|
|
|
|
|
|
|
This OpenMP example will automatically read the **OMP_NUM_THREADS** environment variable to detect the number of thread to use. Other multitread programs may have other ways to get that information.
|
|
|
|
|
|
|
|
### Slurm script
|
|
|
|
|
|
|
|
We will use the [multithread.slurm](https://gitlab.oca.eu/DSI/HPC/blob/master/SLURM/multithread/multithread.slurm) script to dispatch our job. Slurm option will be provided on the command line for flexibility, but would typically be specified in the script through the `#SBATCH <option>` directive
|
|
|
|
|
|
|
|
### Examples
|
|
|
|
* Running 1 task with only 1 core:
|
|
|
|
```
|
|
|
|
$ sbatch --partition fdr --cpus-per-task=1 ./multithread.slurm
|
|
|
|
Submitted batch job 15292873
|
|
|
|
$ more slurm-15292873.out
|
|
|
|
SLURM_CPUS_PER_TASK 1
|
|
|
|
OMP_NUM_THREADS: 1
|
|
|
|
Hi world, we were 1 on the job.
|
|
|
|
$
|
|
|
|
```
|
|
|
|
* Running one task with 10 cores
|
|
|
|
```
|
|
|
|
$sbatch --partition fdr --cpus-per-task=10 ./multithread.slurm
|
|
|
|
Submitted batch job 15292876
|
|
|
|
$more slurm-1529287
|
|
|
|
slurm-15292873.out slurm-15292876.out
|
|
|
|
$ more slurm-15292876.out
|
|
|
|
SLURM_CPUS_PER_TASK 10
|
|
|
|
OMP_NUM_THREADS: 10
|
|
|
|
Hi world, we were 10 on the job.
|
|
|
|
$
|
|
|
|
```
|
|
|
|
* If no node is available with the requested number of cores:
|
|
|
|
```
|
|
|
|
$ sbatch --partition fdr --cpus-per-task=50 ./multithread.slurm
|
|
|
|
sbatch: error: CPU count per node can not be satisfied
|
|
|
|
sbatch: error: Batch job submission failed: Requested node configuration is not available
|
|
|
|
$
|
|
|
|
``` |
|
|
|
\ No newline at end of file |