How to use the command 'srun' (with examples)

How to use the command 'srun' (with examples)

The ‘srun’ command is a part of the Slurm workload manager and is used to create an interactive Slurm job or connect to an existing job. It allows users to submit jobs and control their execution within a Slurm-managed cluster.

Use case 1: Submit a basic interactive job

Code:

srun --pty /bin/bash

Motivation: The above command is used to submit a basic interactive job. It allows the user to launch an interactive shell session on a compute node allocated by Slurm. This is useful when a user needs to run commands interactively on a compute node.

Explanation:

  • srun: The command to submit a Slurm job.
  • --pty: Allocates a pseudo-terminal for the job, allowing it to behave as if it were running interactively.
  • /bin/bash: Specifies the shell to be used in the interactive session.

Example output:

[user@compute-node ~]$

The above command will provide the user with a new shell prompt on the allocated compute node, indicated by [user@compute-node ~]$. From here, the user can now run commands interactively on the compute node.

Use case 2: Submit an interactive job with different attributes

Code:

srun --ntasks-per-node=num_cores --mem-per-cpu=memory_MB --pty /bin/bash

Motivation: This use case allows the user to submit an interactive job with specific attributes, such as the number of tasks per node and the memory per CPU. By specifying these attributes, the user can tailor the job requirements to match the resources needed for their workload.

Explanation:

  • --ntasks-per-node=num_cores: Specifies the number of tasks that should be launched on each compute node. Replace num_cores with the desired number.
  • --mem-per-cpu=memory_MB: Specifies the memory requirement per CPU in megabytes. Replace memory_MB with the desired memory requirement.
  • --pty: Allocates a pseudo-terminal for the job, allowing it to behave as if it were running interactively.
  • /bin/bash: Specifies the shell to be used in the interactive session.

Example output:

[user@compute-node ~]$

Similar to the previous use case, this command will provide the user with an interactive shell session on a compute node. The difference here is that the job will have specific attributes defined, such as the number of tasks per node and memory per CPU.

Use case 3: Connect to a worker node with a job running

Code:

srun --jobid=job_id --pty /bin/bash

Motivation: This use case is useful when a user needs to connect to a worker node where a job is already running. It allows the user to join the existing job and interact with it.

Explanation:

  • --jobid=job_id: Specifies the job ID of the running job that the user wants to connect to. Replace job_id with the actual job ID.
  • --pty: Allocates a pseudo-terminal for the job, allowing it to behave as if it were running interactively.
  • /bin/bash: Specifies the shell to be used in the interactive session.

Example output:

[user@compute-node ~]$

Running the above command will provide the user with an interactive shell session on the compute node where the specified job is running. This allows the user to connect and interact with the job, enabling them to perform any necessary actions or monitoring.

Conclusion:

The ‘srun’ command is a versatile tool in the Slurm workload manager that allows users to submit interactive jobs and connect to existing jobs. Whether it’s running commands interactively on a compute node, specifying job attributes, or joining a running job, ‘srun’ provides the necessary functionality to efficiently manage and control job execution in a Slurm-managed cluster.

Tags :

Related Posts

Dive: Exploring Docker Images in Depth (with examples)

Dive: Exploring Docker Images in Depth (with examples)

Introduction Docker is a widely used platform for containerization, allowing developers to package applications and their dependencies into a well-defined and isolated environment.

Read More
How to use the command 'needrestart' (with examples)

How to use the command 'needrestart' (with examples)

The ’needrestart’ command is a useful tool that allows you to check which daemons need to be restarted after library upgrades.

Read More
How to use the command 'mokutil' (with examples)

How to use the command 'mokutil' (with examples)

The ‘mokutil’ command is used to configure Secure Boot Machine Owner Keys (MOK).

Read More