Job parameters#
When instantiating a SLURM client or executor, you can provide the parameters
argument
from pyslurmutils.client import SlurmScriptRestClient
parameters={"time_limit": "02:00:00"}
client = SlurmScriptRestClient(
url=url,
user_name=user_name,
token=token,
log_directory=log_directory,
parameters=parameters,
)
Documentation on all available SLURM job parameters can be found here.
The most commonly used ones are
current_working_directory
: working directory where the script will be executed on SLURMtime_limit
: limits the job time (hh:mm:ss format)partition
: SLURM partition to which the job should be submittedcpus_per_task
: number of CPU’s available to the jobmemory_per_cpu
: amount of memory per CPUgpus_per_node
: number of GPU’s available to the job (make sure the partition has nodes with GPU’s)
For example this script
from pyslurmutils.client import SlurmScriptRestClient
SCRIPT = """#!/usr/bin/env python3
import os
host = os.gethostname()
pid = os.gedpid()
ncpus = len(os.sched_getaffinity(pid))
print(f'{host=}, {pid=}, {ncpus=}')
"""
parameters={"cpus_per_task": 4}
client = SlurmScriptRestClient(
url=url,
user_name=user_name,
token=token,
log_directory=log_directory,
parameters=parameters,
)
job_id = client.submit_script(SCRIPT)
try:
print(client.wait_finished(job_id))
client.print_stdout_stderr(job_id)
finally:
client.clean_job_artifacts(job_id)
The output confirm that 4 CPUs are available to the job
COMPLETED
STDOUT/STDERR: /tmp_14_days/<username>/slurm_logs/pyslurmutils.<hostname>.15120368.outerr
-------------------------------------------------------------------------------------
host='<slurmnode>', pid=1774392, ncpus=4