# CPU Management User and Administrator Guide

## Overview

The purpose of this guide is to assist SLURM users and administrators in selecting configuration options and composing command lines to manage the use of CPU resources by jobs, steps and tasks. The document is divided into the following sections:

- Overview
- CPU Management Steps performed by SLURM
- Getting Information about CPU usage by Jobs/Steps/Tasks
- CPU Management and SLURM Accounting
- CPU Management Examples

CPU Management through user commands is constrained by the configuration parameters chosen by the SLURM administrator. The interactions between different CPU management options are complex and often difficult to predict. Some experimentation may be required to discover the exact combination of options needed to produce a desired outcome. Users and administrators should refer to the man pages for slurm.conf, salloc, sbatch and srun for detailed explanations of each option. The following html documents may also be useful:

Consumable Resources in SLURM
Sharing Consumable Resources
Support for Multi-core/Multi-thread Architectures
Plane distribution

The information and examples in this document have been verified on SLURM version 2.2.3. Some information may not be valid for previous SLURM versions.

## CPU Management Steps performed by SLURM

SLURM uses three basic steps to manage CPU resources:

- Step 1: Selection and Allocation of Nodes/CPUs to Jobs/Steps
- Step 2: Distribution of Tasks to Nodes
- Step 3: Optional Distribution and Binding of Tasks to CPUs within a Node (Task Affinity)

### Step 1: Selection and Allocation of Nodes/CPUs to Jobs/Steps

In Step 1, SLURM selects and allocates a set of CPU resources for a job or job step. If SelectType=select/linear is configured, only whole nodes are allocated. If SelectType=select/cons_res is configured, sockets, cores and threads may be allocated as consumable resources from the selected nodes. The consumable resource type is defined by SelectTypeParameters.

When using SelectType=select/cons_res, the default allocation method across nodes is block (allocate all available CPUs in a node before using another node). The default allocation method within a node is cyclic (allocate available CPUs in a round-robin fashion across the sockets within a node). Users may override the default behavior using the appropriate command line options described below.
Step 1 is performed by slurmctld and the select plugin.

slurm.conf options that control Step 1
slurm.conf parameter | Possible values | Description
NodeName | <name of the node> Plus additional parameters. See man page for details. | Defines a node. This includes the number and layout of sockets, cores, threads and processors (logical CPUs) on the node.
PartitionName | <name of the partition> Plus additional parameters. See man page for details. | Defines a partition. Several parameters of the partition definition affect the allocation of CPU resources to jobs (e.g., Nodes, Shared, MaxNodes)
FastSchedule | 0 | 1 | 2 | Controls how the information in a node definition is used.
SelectType | select/linear | select/cons_res | Controls whether CPU resources are allocated to jobs and job steps in units of whole nodes or as consumable resources (sockets, cores or threads).
SelectTypeParameters | CR_CPU | CR_CPU_Memory | CR_Core | CR_Core_Memory | CR_Socket | CR_Socket_Memory Plus additional options. See man page for details. | Defines the consumable resource type and controls other aspects of CPU resource allocation by the select plugin.

srun/salloc/sbatch command line options that control Step 1
Command line option | Possible values | Description
-B, --extra-node-info | <sockets[:cores[:threads]]> | Restricts node selection to nodes with a specified layout of sockets, cores and threads.
-C, --constraint | <list> | Restricts node selection to nodes with specified attributes
--contiguous | N/A | Restricts node selection to contiguous nodes
--cores-per-socket | <cores> | Controls the number of cores allocated per socket
-c, --cpus-per-task | <ncpus> | Controls the number of CPUs allocated per task
--exclusive | N/A | Prevents sharing of allocated nodes with other jobs
-F, --nodefile | <node file> | File containing a list of specific nodes to be selected for the job (salloc and sbatch only)
--hint | compute_bound | memory_bound | [no]multithread | Additional controls on allocation of CPU resources
--mincpus | <n> | Controls the minimum number of CPUs allocated per node
-N, --nodes | <minnodes[-maxnodes]> | Controls the minimum/maximum number of nodes allocated to the job
-n, --ntasks | <number> | Controls the number of tasks to be created for the job
--ntasks-per-core | <number> | Controls the maximum number of tasks per allocated core
--ntasks-per-socket | <number> | Controls the maximum number of tasks per allocated socket
--ntasks-per-node | <number> | Controls the maximum number of tasks per allocated node
-O, --overcommit | N/A | Allows fewer CPUs to be allocated than the number of tasks
-p, --partition | <partition_names> | Controls which partition is used for the job
-s, --share | N/A | Allows sharing of allocated nodes with other jobs
--sockets-per-node | <sockets> | Controls the number of sockets allocated per node
--threads-per-core | <threads> | Controls the number of threads allocated per core
-w, --nodelist | <host1,host2,... or filename> | List of specific nodes to be allocated to the job
-x, --exclude | <host1,host2,... or filename> | List of specific nodes to be excluded from allocation to the job
-Z, --no-allocate | N/A | Bypass normal allocation (privileged option available to users “SlurmUser” and “root” only)

### Step 2: Distribution of Tasks to Nodes

In Step 2, SLURM distributes tasks to the nodes that were selected for the job/step in Step 1. Each task is distributed to only one node, but more than one task may be distributed to each node. Unless overcommitment of CPUs to tasks is specified for the job, the number of tasks distributed to a node is constrained by the number of CPUs allocated on the node and the number of CPUs per task. If consumable resources is configured, or resource sharing is allowed, tasks from more than one job/step may be distributed to the same node concurrently.
Step 2 is performed by slurmctld.

slurm.conf options that control Step 2
slurm.conf parameter | Possible values | Description
MaxTasksPerNode | <number> | Controls the maximum number of tasks that a job step can spawn on a single node

srun/salloc/sbatch command line options that control Step 2
Command line option | Possible values | Description
--distribution, -m | block|cyclic |arbitrary|plane=<options>[:block|cyclic] | The first specified distribution (before the ":") controls the sequence in which tasks are distributed to each of the selected nodes. Note that this option does not affect the number of tasks distributed to each node, but only the sequence of distribution.
--ntasks-per-core | <number> | Controls the maximum number of tasks per allocated core
--ntasks-per-socket | <number> | Controls the maximum number of tasks per allocated socket
--ntasks-per-node | <number> | Controls the maximum number of tasks per allocated node
-r, --relative | N/A | Controls which node is used for a job step

### Step 3: Optional Distribution and Binding of Tasks to CPUs within a Node (Task Affinity)

In optional Step 3, SLURM distributes and binds each task to a specified subset of the allocated CPUs on the node to which the task was distributed in Step 2. Different tasks distributed to the same node may be bound to the same subset of CPUs or to different subsets. This step is known as task affinity or task/CPU binding.
Step 3 is performed by slurmd and the task plugin.

slurm.conf options that control Step 3
slurm.conf parameter | Possible values | Description
TaskPlugin | task/none | task/affinity | Controls whether this step is enabled
TaskPluginParam | See man page | Controls the binding unit (sockets, cores or threads) and the binding method (sched or cpusets)

srun/salloc/sbatch command line options that control Step 3
Command line option | Possible values | Description
--cpu_bind | See man page | Controls binding of tasks to CPUs
--ntasks-per-core | <number> | Controls the maximum number of tasks per allocated core
--distribution, -m | block|cyclic |arbitrary|plane=<options>[:block|cyclic] | The second specified distribution (after the ":") controls the sequence in which tasks are distributed to allocated CPUs within a node for binding of tasks to CPUs

## Additional Notes on CPU Management Steps

For consumable resources, it is important for users to understand the difference between allocation (Step 1) and task affinity/binding (Step 3). Exclusive (unshared) allocation of CPUs as consumable resources limits the number of jobs/steps/tasks that can use a node concurrently. But it does not limit the set of CPUs on the node that each task distributed to the node can use. Unless task affinity is enabled, or some other form of binding is used (e.g., a spank plugin), all tasks distributed to a node can use all of the CPUs on the node, including CPUs not allocated to their job/step. This may have unexpected adverse effects on performance, since it allows one job to use CPUs allocated exclusively to another job. For this reason, it may not be advisable to configure consumable resources without also configuring task affinity. Note that task affinity can also be useful when select/linear (whole node allocation) is configured, to improve performance by restricting each task to a particular socket or other subset of CPU resources on a node.

## Getting Information about CPU usage by Jobs/Steps/Tasks

There is no easy way to generate a comprehensive set of CPU management information for a job/step (allocation, distribution and binding). However, several commands/options provide limited information about CPU usage.

Command/Option | Information
scontrol show job option: --details | This option provides a list of the nodes selected for the job and the CPU ids allocated to the job on each node. Note that the CPU ids reported by this command are SLURM abstract CPU ids, not Linux/hardware CPU ids (as reported by, for example, /proc/cpuinfo).
Linux command: env | Many SLURM environment variables provide information related to node and CPU usage: SLURM_JOB_CPUS_PER_NODE SLURM_CPUS_PER_TASK SLURM_CPU_BIND SLURM_DISTRIBUTION SLURM_NODELIST SLURM_TASKS_PER_NODE SLURM_STEP_NODELIST SLURM_STEP_NUM_NODES SLURM_STEP_NUM_TASKS SLURM_STEP_TASKS_PER_NODE SLURM_NNODES SLURM_NTASKS SLURM_NPROCS SLURM_CPUS_ON_NODE SLURM_NODEID SLURMD_NODENAME
srun/salloc/sbatch option: --cpu_bind=verbose | This option provides a list of the CPU masks used by task affinity to bind tasks to CPUs. Note that the CPU ids represented by these masks are Linux/hardware CPU ids, not SLURM abstract CPU ids as reported by scontrol, etc.
srun/salloc/sbatch option: -l | This option adds the task id as a prefix to each line of output from a task sent to stdout/stderr. This can be useful for distinguishing node-related and CPU-related information by task id for multi-task jobs/steps.
Linux command: cat /proc/<pid>/status | grep Cpus_allowed_list | Given a task's pid (or "self" if the command is executed by the task itself), this command produces a list of the CPU ids bound to the task. This is the same information that is provided by --cpu_bind=verbose, but in a more readable format.

## CPU Management and SLURM Accounting

CPU management by SLURM users is subject to limits imposed by SLURM Accounting. Accounting limits may be applied on CPU usage at the level of users, groups and clusters. For details, see the sacctmgr man page.

## CPU Management Examples

The following examples illustrate some scenarios for managing CPU resources using SLURM. Many additional scenarios are possible. In each example, it is assumed that all CPUs on each node are available for allocation.

- Example Node and Partition Configuration
- Example 1: Allocation of whole nodes
- Example 2: Simple allocation of cores as consumable resources
- Example 3: Consumable resources with balanced allocation across nodes
- Example 4: Consumable resources with minimization of resource fragmentation
- Example 5: Consumable resources with cyclic distribution of tasks to nodes
- Example 6: Consumable resources with default allocation and plane distribution of tasks to nodes
- Example 7: Consumable resources with overcommitment of CPUs to tasks
- Example 8: Consumable resources with resource sharing between jobs
- Example 9: Consumable resources on multithreaded node, allocating only one thread per core
- Example 10: Consumable resources with task affinity and core binding
- Example 11: Consumable resources with task affinity and socket binding, Case 1
- Example 12: Consumable resources with task affinity and socket binding, Case 2
- Example 13: Consumable resources with task affinity and socket binding, Case 3
- Example 14: Consumable resources with task affinity and customized allocation and distribution
- Example 15: Consumable resources with task affinity to optimize the performance of a multi-task, multi-thread job

### Example Node and Partition Configuration

For these examples, the SLURM cluster contains the following nodes:

Nodename | n0 | n1 | n2 | n3
Number of Sockets | 2 | 2 | 2 | 2
Number of Cores per Socket | 4 | 4 | 4 | 4
Total Number of Cores | 8 | 8 | 8 | 8
Number of Threads (CPUs) per Core | 1 | 1 | 1 | 2
Total Number of CPUs | 8 | 8 | 8 | 16

And the following partitions:

PartitionName | regnodes | hypernode
Nodes | n0 n1 n2 | n3
Default | YES | -

These entities are defined in slurm.conf as follows:

    Nodename=n0 NodeAddr=node0 Sockets=2 CoresPerSocket=4 ThreadsPerCore=1 Procs=8
    Nodename=n1 NodeAddr=node1 Sockets=2 CoresPerSocket=4 ThreadsPerCore=1 Procs=8 State=IDLE
    Nodename=n2 NodeAddr=node2 Sockets=2 CoresPerSocket=4 ThreadsPerCore=1 Procs=8 State=IDLE
    Nodename=n3 NodeAddr=node3 Sockets=2 CoresPerSocket=4 ThreadsPerCore=2 Procs=16 State=IDLE
    PartitionName=regnodes Nodes=n0,n1,n2 Shared=YES Default=YES State=UP
    PartitionName=hypernode Nodes=n3 State=UP

### Example 1: Allocation of whole nodes

Allocate a minimum of two whole nodes to a job.

slurm.conf options:

    SelectType=select/linear

Command line:

    srun -N2 ...

Comments:

The SelectType=select/linear configuration option specifies allocation in units of whole nodes. The -N2 srun option causes SLURM to allocate at least 2 nodes to the job.

### Example 2: Simple allocation of cores as consumable resources

A job requires 6 CPUs (2 tasks and 3 CPUs per task with no overcommitment). Allocate the 6 CPUs as consumable resources from a single node in the default partition.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core

Command line:

    srun -N1-1 -n2 -c3 ...

Comments:

The SelectType configuration options define cores as consumable resources. The -N1-1 srun option restricts the job to a single node. The following table shows a possible pattern of allocation for this job.

Nodename | n0 | n1 | n2
Number of Allocated CPUs | 6 | 0 | 0
Number of Tasks | 2 | 0 | 0

### Example 3: Consumable resources with balanced allocation across nodes

A job requires 9 CPUs (3 tasks and 3 CPUs per task with no overcommitment). Allocate 3 CPUs from each of the 3 nodes in the default partition.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core

Command line:

    srun -N3-3 -n3 -c3 ...

Comments:

The options specify the following conditions for the job: 3 tasks, 3 unique CPUs per task, using exactly 3 nodes. To satisfy these conditions, SLURM must allocate 3 CPUs from each node. The following table shows the allocation for this job.

Nodename | n0 | n1 | n2
Number of Allocated CPUs | 3 | 3 | 3
Number of Tasks | 1 | 1 | 1

### Example 4: Consumable resources with minimization of resource fragmentation

A job requires 12 CPUs (12 tasks and 1 CPU per task with no overcommitment). Allocate CPUs using the minimum number of nodes and the minimum number of sockets required for the job in order to minimize fragmentation of allocated/unallocated CPUs in the cluster.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core,CR_CORE_DEFAULT_DIST_BLOCK

Command line:

    srun -n12 ...

Comments:

The default allocation method across nodes is block. This minimizes the number of nodes used for the job. The configuration option CR_CORE_DEFAULT_DIST_BLOCK sets the default allocation method within a node to block. This minimizes the number of sockets used for the job within a node. The combination of these two methods causes SLURM to allocate the 12 CPUs using the minimum required number of nodes (2 nodes) and sockets (3 sockets).The following table shows a possible pattern of allocation for this job.

Nodename | n0 | n1 | n2
Socket id | 0 | 1 | 0 | 1 | 0 | 1
Number of Allocated CPUs | 4 | 4 | 4 | 0 | 0 | 0
Number of Tasks | 8 | 4 | 0

### Example 5: Consumable resources with cyclic distribution of tasks to nodes

A job requires 12 CPUs (6 tasks and 2 CPUs per task with no overcommitment). Allocate 6 CPUs from each of 2 nodes in the default partition. Distribute tasks to nodes cyclically.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core

Command line:

    srun -N2-2 --ntasks-per-node=3 --distribution=cyclic -n6 -c2 ...

Comments:

The options specify the following conditions for the job: 6 tasks, 2 unique CPUs per task, using exactly 2 nodes, and with 3 tasks per node. To satisfy these conditions, SLURM must allocate 6 CPUs from each of 2 nodes. The --distribution=cyclic option causes the tasks to be distributed to the nodes in a round-robin fashion. The following table shows a possible pattern of allocation and distribution for this job.

Nodename | n0 | n1 | n2
Number of Allocated CPUs | 6 | 6 | 0
Number of Tasks | 3 | 3 | 0
Distribution of Tasks to Nodes, by Task id | 0 2 4 | 1 3 5 | -

### Example 6: Consumable resources with default allocation and plane distribution of tasks to nodes

A job requires 16 CPUs (8 tasks and 2 CPUs per task with no overcommitment). Use all 3 nodes in the default partition. Distribute tasks to each node in blocks of two in a round-robin fashion.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core

Command line:

    srun -N3-3 --distribution=plane=2 -n8 -c2 ...

Comments:

The options specify the following conditions for the job: 8 tasks, 2 unique CPUs per task, using all 3 nodes in the partition. To satisfy these conditions using the default allocation method across nodes (block), SLURM allocates 8 CPUs from the first node, 6 CPUs from the second node and 2 CPUs from the third node. The --distribution=plane=2 option causes SLURM to distribute tasks in blocks of two to each of the nodes in a round-robin fashion, subject to the number of CPUs allocated on each node. So, for example, only 1 task is distributed to the third node because only 2 CPUs were allocated on that node and each task requires 2 CPUs. The following table shows a possible pattern of allocation and distribution for this job.

Nodename | n0 | n1 | n2
Number of Allocated CPUs | 8 | 6 | 2
Number of Tasks | 4 | 3 | 1
Distribution of Tasks to Nodes, by Task id | 0 1 5 6 | 2 3 7 | 4

### Example 7: Consumable resources with overcommitment of CPUs to tasks

A job has 20 tasks. Run the job in a single node.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core

Command line:

    srun -N1-1 -n20 -O ...

Comments:

The -O option allows the job to run in only one node by overcommitting CPUs to tasks.The following table shows a possible pattern of allocation and distribution for this job.

Nodename | n0 | n1 | n2
Number of Allocated CPUs | 8 | 0 | 0
Number of Tasks | 20 | 0 | 0
Distribution of Tasks to Nodes, by Task id | 0 - 19 | - | -

### Example 8: Consumable resources with resource sharing between jobs

2 jobs each require 6 CPUs (6 tasks per job with no overcommitment). Run both jobs simultaneously in a single node.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core

Command line:

    srun -N1-1 -w n0 -n6 -s ...
    srun -N1-1 -w n0 -n6 -s ...

Comments:

The -N1-1 and -w n0 srun options together restrict both jobs to node n0. The Shared=YES option in the partition definition plus the -s srun option allows the two jobs to share CPUs on the node.

### Example 9: Consumable resources on multithreaded node, allocating only one thread per core

A job requires 8 CPUs (8 tasks with no overcommitment). Run the job on node n3, allocating only one thread per core.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_CPU

Command line:

    srun -p hypernode -n8 --hint=nomultithread ...

Comments:

The CR_CPU configuration option enables the allocation of only one thread per core. The --hint=nomultithread srun option causes SLURM to allocate only one thread from each core to this job. The following table shows a possible pattern of allocation for this job.

Nodename | n3
Socket id | 0 | 1
Core id | 0 | 1 | 2 | 3 | 0 | 1 | 2 | 3
CPU id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15
Number of Allocated CPUs | 4 | 4
Allocated CPU ids | 0 2 4 6 | 8 10 12 14

### Example 10: Consumable resources with task affinity and core binding

A job requires 6 CPUs (6 tasks with no overcommitment). Run the job in a single node in the default partition. Apply core binding to each task.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core
    TaskPlugin=task/affinity
    TaskPluginParam=sched

Command line:

    srun -N1-1 -n6 --cpu_bind=cores ...

Comments:

Using the default allocation method within nodes (cyclic), SLURM allocates 3 CPUs on each socket of 1 node. Using the default distribution method within nodes (cyclic), SLURM distributes and binds each task to an allocated core in a round-robin fashion across the sockets. The following table shows a possible pattern of allocation, distribution and binding for this job. For example, task id 2 is bound to CPU id 1.

Nodename | n0
Socket id | 0 | 1
Number of Allocated CPUs | 3 | 3
Allocated CPU ids | 0 1 2 | 4 5 6
Binding of Tasks to CPUs | CPU id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Task id | 0 | 2 | 4 | - | 1 | 3 | 5 | -

### Example 11: Consumable resources with task affinity and socket binding, Case 1

A job requires 6 CPUs (6 tasks with no overcommitment). Run the job in a single node in the default partition. Apply socket binding to each task.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core
    TaskPlugin=task/affinity
    TaskPluginParam=sched

Command line:

    srun -N1-1 -n6 --cpu_bind=sockets ...

Comments:

Using the default allocation method within nodes (cyclic), SLURM allocates 3 CPUs on each socket of 1 node. Using the default distribution method within nodes (cyclic), SLURM distributes and binds each task to all of the allocated CPUs in one socket in a round-robin fashion across the sockets. The following table shows a possible pattern of allocation, distribution and binding for this job. For example, task ids 1, 3 and 5 are all bound to CPU ids 4, 5 and 6.

Nodename | n0
Socket id | 0 | 1
Number of Allocated CPUs | 3 | 3
Allocated CPU ids | 0 1 2 | 4 5 6
Binding of Tasks to CPUs | CPU id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Task ids | 0 2 4 | - | 1 3 5 | -

### Example 12: Consumable resources with task affinity and socket binding, Case 2

A job requires 6 CPUs (2 tasks with 3 cpus per task and no overcommitment). Run the job in a single node in the default partition. Allocate cores using the block allocation method. Distribute cores using the block distribution method. Apply socket binding to each task.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core,CR_CORE_DEFAULT_DIST_BLOCK
    TaskPlugin=task/affinity
    TaskPluginParam=sched

Command line:

    srun -N1-1 -n2 -c3 --cpu_bind=sockets --distribution=block:block ...

Comments:

Using the block allocation method, SLURM allocates 4 CPUs on one socket and 2 CPUs on the other socket of one node. Using the block distribution method within nodes, SLURM distributes 3 CPUs to each task. Applying socket binding, SLURM binds each task to all allocated CPUs in all sockets in which the task has a distributed CPU. The following table shows a possible pattern of allocation, distribution and binding for this job. In this example, using the block allocation method CPU ids 0-3 are allocated on socket id 0 and CPU ids 4-5 are allocated on socket id 1. Using the block distribution method, CPU ids 0-2 were distributed to task id 0, and CPU ids 3-5 were distributed to task id 1. Applying socket binding, task id 0 is therefore bound to the allocated CPUs on socket 0, and task id 1 is bound to the allocated CPUs on both sockets.

Nodename | n0
Socket id | 0 | 1
Number of Allocated CPUs | 4 | 2
Allocated CPU ids | 0 1 2 3 | 4 5
Binding of Tasks to CPUs | CPU id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Task ids | 0 1 | 1 | -

### Example 13: Consumable resources with task affinity and socket binding, Case 3

A job requires 6 CPUs (2 tasks with 3 cpus per task and no overcommitment). Run the job in a single node in the default partition. Allocate cores using the block allocation method. Distribute cores using the cyclic distribution method. Apply socket binding to each task.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core,CR_CORE_DEFAULT_DIST_BLOCK
    TaskPlugin=task/affinity
    TaskPluginParam=sched

Command line:

    srun -N1-1 -n2 -c3 --cpu_bind=sockets --distribution=block:cyclic ...

Comments:

Using the block allocation method, SLURM allocates 4 CPUs on one socket and 2 CPUs on the other socket of one node. Using the cyclic distribution method within nodes, SLURM distributes 3 CPUs to each task. Applying socket binding, SLURM binds each task to all allocated CPUs in all sockets in which the task has a distributed CPU. The following table shows a possible pattern of allocation, distribution and binding for this job. In this example, using the block allocation method CPU ids 0-3 are allocated on socket id 0 and CPU ids 4-5 are allocated on socket id 1. Using the cyclic distribution method, CPU ids 0, 1 and 4 were distributed to task id 0, and CPU ids 2, 3 and 5 were distributed to task id 1. Applying socket binding, both tasks are therefore bound to the allocated CPUs on both sockets.

Nodename | n0
Socket id | 0 | 1
Number of Allocated CPUs | 4 | 2
Allocated CPU ids | 0 1 2 3 | 4 5
Binding of Tasks to CPUs | CPU id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Task ids | 0 1 | 0 1 | -

### Example 14: Consumable resources with task affinity and customized allocation and distribution

A job requires 18 CPUs (18 tasks with no overcommitment). Run the job in the default partition. Allocate 6 CPUs on each node using block allocation within nodes. Use cyclic distribution of tasks to nodes and block distribution of tasks for CPU binding.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core,CR_CORE_DEFAULT_DIST_BLOCK
    TaskPlugin=task/affinity
    TaskPluginParam=sched

Command line:

    srun -N3-3 -n18 –-ntasks-per-node=6 –-distribution cyclic:block --cpu_bind=cores ...

Comments:

This example shows the use of task affinity with customized allocation of CPUs and distribution of tasks across nodes and within nodes for binding. The srun options specify the following conditions for the job: 18 tasks, 1 unique CPU per task, using all 3 nodes in the partition, with 6 tasks per node. The CR_CORE_DEFAULT_DIST_BLOCK configuration option specifies block allocation within nodes. To satisfy these conditions, SLURM allocates 6 CPUs on each node, with 4 CPUs allocated on one socket and 2 CPUs on the other socket. The --distribution cyclic:block option specifies cyclic distribution of tasks to nodes and block distribution of tasks to CPUs within nodes for binding. The following table shows a possible pattern of allocation, distribution and binding for this job. For example, task id 10 is bound to CPU id 3 on node n1.

Nodename | n0 | n1 | n2
Socket id | 0 | 1 | 0 | 1 | 0 | 1
Number of Allocated CPUs | 4 | 2 | 4 | 2 | 4 | 2
Allocated CPU ids | 0 1 2 3 4 5 | 0 1 2 3 4 5 | 0 1 2 3 4 5
Number of Tasks | 6 | 6 | 6
Distribution of Tasks to Nodes, by Task id | 0 3 6 9 12 15 | 1 4 7 10 13 16 | 2 5 8 11 14 17
Binding of Tasks to CPUs | CPU id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Task id | 0 | 3 | 6 | 9 | 12 | 15 | - | - | 1 | 4 | 7 | 10 | 13 | 16 | - | - | 2 | 5 | 8 | 11 | 14 | 17 | - | -

### Example 15: Consumable resources with task affinity to optimize the performance of a multi-task, multi-thread job

A job requires 9 CPUs (3 tasks and 3 CPUs per task with no overcommitment). Run the job in the default partition, managing the CPUs to optimize the performance of the job.

slurm.conf options:

    SelectType=select/cons_res
    SelectTypeParameters=CR_Core
    TaskPlugin=task/affinity
    TaskPluginParam=sched

Command line:

    srun -N3-3 -n3 -c3 --cores-per-socket=3 --cpu_bind=cores ...

Comments:

To optimize the performance of this job, the user wishes to allocate 3 CPUs from each of 3 sockets and bind each task to the 3 CPUs in a single socket. The TaskPlugin and TaskPluginParam configuration options enable task affinity. The srun options specify the following conditions for the job: 3 tasks, with 3 unique CPUs per task, allocated on exactly 3 nodes, with 3 CPUs per socket. To satisfy these conditions, SLURM allocates 3 CPUs from one socket in each of the 3 nodes in the default partition. The --cpu_bind=cores option causes SLURM to bind each task to the 3 allocated CPUs on the node to which it is distributed. The following table shows a possible pattern of allocation, distribution and binding for this job. For example, task id 2 is bound to CPU ids 0, 1 and 2 on socket id 0 of node n2.

Nodename | n0 | n1 | n2
Socket id | 0 | 1 | 0 | 1 | 0 | 1
Number of Allocated CPUs | 3 | 0 | 3 | 0 | 3 | 0
Allocated CPU ids | 0 1 2 | 0 1 2 | 0 1 2
Number of Tasks | 1 | 1 | 1
Distribution of Tasks to Nodes, by Task id | 0 | 1 | 2
Binding of Tasks to CPUs | CPU id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Task id | 0 | - | 1 | - | 2 | --

Last modified 30 March 2011