Python API basics
from slurm_script_generator.slurm_script import SlurmScript
%load_ext autoreload%autoreload 2slurm_script = SlurmScript( nodes=2, ntasks_per_core=16, custom_commands=[ "# Run simulation", "srun ./bin > run.out", ],)
print(slurm_script)#!/bin/bash######################################################### This script was generated using ## slurm-script-generator v0.4.0 ## https://github.com/max-models/slurm-script-generator ## `pip install slurm-script-generator==0.4.0` #########################################################
######################################################### Pragmas for Core Node And Task Allocation ##SBATCH --nodes=2 # number of nodes on which to run# ## Pragmas for Cpu Topology And Binding ##SBATCH --ntasks-per-core=16 # number of tasks to invoke on each core######################################################### Run simulationsrun ./bin > run.outYou can also retreive the string representation
script_str = slurm_script.to_string()print(script_str)#!/bin/bash######################################################### This script was generated using ## slurm-script-generator v0.4.0 ## https://github.com/max-models/slurm-script-generator ## `pip install slurm-script-generator==0.4.0` #########################################################
######################################################### Pragmas for Core Node And Task Allocation ##SBATCH --nodes=2 # number of nodes on which to run# ## Pragmas for Cpu Topology And Binding ##SBATCH --ntasks-per-core=16 # number of tasks to invoke on each core######################################################### Run simulationsrun ./bin > run.outor save the script to file with
slurm_script.save("slurm_script.sh")MPI batch job without hyperthreading (Raven)
Section titled “MPI batch job without hyperthreading (Raven)”Here is a sligtly more detailed example
# Template from Raven user guide:# https://docs.mpcdf.mpg.de/doc/computing/raven-user-guide.html#mpi-batch-job-without-hyperthreading
slurm_script = SlurmScript( error="./job.err.%j", output="./job.out.%j", chdir="./", job_name="test_slurm", nodes=16, ntasks_per_node=72, mail_type="none", mail_user="userid@example.mpg.de", time="12:00:00", modules=["intel/21.2.0", "impi/2021.2"], custom_commands=[ "# Run the program:", "srun ./myprog > prog.out", ],)
print(slurm_script)#!/bin/bash######################################################### This script was generated using ## slurm-script-generator v0.4.0 ## https://github.com/max-models/slurm-script-generator ## `pip install slurm-script-generator==0.4.0` #########################################################
######################################################### Pragmas for Job Config ##SBATCH --job-name=test_slurm # name of job# ## Pragmas for Time And Priority ##SBATCH --time=12:00:00 # time limit# ## Pragmas for Io And Directory ##SBATCH --chdir=./ # change working directory#SBATCH --output=./job.out.%j # File to redirect output (%%x=jobname, %%j=jobid)#SBATCH --error=./job.err.%j # File to redirect error (%%x=jobname, %%j=jobid)# ## Pragmas for Notifications ##SBATCH --mail-user=userid@example.mpg.de # who to send email notification for job state changes#SBATCH --mail-type=none # notify on state change# ## Pragmas for Core Node And Task Allocation ##SBATCH --nodes=16 # number of nodes on which to run#SBATCH --ntasks-per-node=72 # number of tasks to invoke on each node########################################################module purge # Purge modulesmodule load intel/21.2.0 impi/2021.2 # modulesmodule list # List loaded modules# Run the program:srun ./myprog > prog.outHybrid MPI/OpenMP batch job without hyperthreading on Raven
Section titled “Hybrid MPI/OpenMP batch job without hyperthreading on Raven”# Template from Raven user guide:# https://docs.mpcdf.mpg.de/doc/computing/raven-user-guide.html#mpi-batch-job-without-hyperthreading
slurm_script = SlurmScript( error="./job_hybrid.err.%j", output="./job_hybrid.out.%j", chdir="./", job_name="test_slurm", nodes=16, ntasks_per_node=4, cpus_per_task=18, mail_type="none", mail_user="userid@example.mpg.de", time="12:00:00", modules=["intel/21.2.0", "impi/2021.2"], custom_commands=[ "\nexport OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK", "\n# For pinning threads correctly:", "export OMP_PLACES=cores", "\n# Run the program:", "srun ./myprog > prog.out", ],)
print(slurm_script)#!/bin/bash######################################################### This script was generated using ## slurm-script-generator v0.4.0 ## https://github.com/max-models/slurm-script-generator ## `pip install slurm-script-generator==0.4.0` #########################################################
######################################################### Pragmas for Job Config ##SBATCH --job-name=test_slurm # name of job# ## Pragmas for Time And Priority ##SBATCH --time=12:00:00 # time limit# ## Pragmas for Io And Directory ##SBATCH --chdir=./ # change working directory#SBATCH --output=./job_hybrid.out.%j # File to redirect output (%%x=jobname, %%j=jobid)#SBATCH --error=./job_hybrid.err.%j # File to redirect error (%%x=jobname, %%j=jobid)# ## Pragmas for Notifications ##SBATCH --mail-user=userid@example.mpg.de # who to send email notification for job state changes#SBATCH --mail-type=none # notify on state change# ## Pragmas for Core Node And Task Allocation ##SBATCH --nodes=16 # number of nodes on which to run#SBATCH --ntasks-per-node=4 # number of tasks to invoke on each node#SBATCH --cpus-per-task=18 # number of cpus required per task########################################################module purge # Purge modulesmodule load intel/21.2.0 impi/2021.2 # modulesmodule list # List loaded modules
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
# For pinning threads correctly:export OMP_PLACES=cores
# Run the program:srun ./myprog > prog.out# Try out the repr which can be used to# re-create the object from the string# representation using the python APIslurm_script = SlurmScript( nodes=2, ntasks_per_core=16, custom_commands=[ "# Run simulation", "srun ./bin > run.out", ],)slurm_scriptSlurmScript( nodes=2, ntasks_per_core=16, custom_commands=['# Run simulation', 'srun ./bin > run.out'],)script = SlurmScript( nodes=2, ntasks_per_core=16, custom_commands=["# Run simulation", "srun ./bin > run.out"],)