> For the complete documentation index, see [llms.txt](https://gsds.gitbook.io/gsds/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gsds.gitbook.io/gsds/for-beginners/slurm.md).

# Slurm

### Slurm 이란?

Slurm은 작업 스케줄러의 한 종류로, 클러스터 시스템 상에서 작업을 관리하기 위한 프로그램입니다.&#x20;

로그인 노드에서 slurm 스케줄러에 작업을 제출하면, 비어 있는 계산 노드 중 하나를 할당 받아 작업이 실행하게 됩니다.

slurm 주요 명령어는 다음과 같습니다.

#### srun

공식 문서: <https://slurm.schedmd.com/srun.html>

위 명령어를 사용하여 job 을 실행하면, slurm 이 자원을 할당하여 job을 실행하게 됩니다.

#### sbatch

공식 문서: <https://slurm.schedmd.com/sbatch.html>

job 을 slurm 프로그램에 제출하는 명령어로, 지금 당장 사용할 수 있는 자원이 없을 경우 충분한 자원이 확보될 때까지 기다렸다가 job 을 실행하게 됩니다.

#### sinfo

공식 문서: [https://slurm.schedmd.com/sinfo.html](https://slurm.schedmd.com/sbatch.html)

현재 slurm 으로 관리되는 자원에 대한 정보를 볼 수 있는 명령어입니다.

#### squeue

공식 문서: [https://slurm.schedmd.com/squeue.html](https://slurm.schedmd.com/sbatch.html)

slurm 에 제출된 job 들을 확인할 수 있는 명령어입니다.

#### scancel

공식 문서: [https://slurm.schedmd.com/scancel.html](https://slurm.schedmd.com/sbatch.html)

slurm 에 제출된 job 을 중단하는 명령어입니다.

서버에서 slurm 을 사용하여 프로그램을 실행하는 방법은 크게 2가지 입니다.

### 1. launch-shell 사용

slurm 프로그램을 이용하여 자원을 할당받고, 할당받은 자원을 terminal 형태로 사용할 수 있도록 작성해둔 script 입니다.

```
launch-shell [#GPUs] [timelimit in minutes (optional)] [slurm partition (optional)]
```

{% hint style="warning" %}
다만, 이 방법을 사용하여 할당받은 자원의 경우 사용자가 장시간 사용하지 않더라도, 제한 시간에 도달하거나 사용자가 직접 종료하지 않는 한 할당받은 자원이 해체되지 않으므로, <mark style="color:red;">**GSDS 서버 자원을 효율적으로 사용하지 못하는 직접적인 원인**</mark>이 될 수 있습니다.

따라서, 가능한 디버깅 용도로만 사용하고, <mark style="color:red;">**다수의 작업을 동시에 실행해야 하는 경우 sbatch 명령어를 사용**</mark>해주시기 바랍니다. (launch-shell 최대 사용 시간을 4시간으로 변경했습니다.)
{% endhint %}

사용 예시는 아래와 같습니다.

<figure><img src="/files/XuaKUuIpflHjd33R8rjn" alt=""><figcaption></figcaption></figure>

### 2. sbatch 사용

sbatch 를 사용하여 프로그램을 실행하기 위해서는 아래와 같이 사용하고자 하는 자원에 대한 내용을 명시한 script 가 필요합니다. 아래는 sbatch 를 이용하기 위한  script 의 한 예시입니다.

```bash
#!/bin/bash

#SBATCH --job-name=example                    # Submit a job named "example"
#SBATCH --nodes=1                             # Using 1 node
#SBATCH --gres=gpu:1                          # Using 1 gpu
#SBATCH --time=0-01:00:00                     # 1 hour timelimit
#SBATCH --mem=10000MB                         # Using 10GB CPU Memory
#SBATCH --partition=b                         # Using "b" partition 
#SBATCH --cpus-per-task=4                     # Using 4 maximum processor

source ${HOME}/.bashrc
source ${HOME}/anaconda3/bin/activate
conda activate {conda env}

srun {your job}
```

위와 같이 작성된 script 는 아래와 같이 실행하면 됩니다.

```
sbatch example.sh    // example.sh 가 위에 작성된 script 파일입니다.
```

제출된 job 은 `squeue` 명령어를 통해 확인할 수 있습니다.

### 3. launch-jupyter사용

slurm 프로그램을 이용하여 자원을 할당받고, 할당받은 자원을 통해 Jupyter Notebook을 사용할 수 있도록 작성해해둔 script 입니다.&#x20;

```
launch-jupyter [#GPUs] [conda environment (optional)] [timelimit in minutes (optional)] [slurm partition (optional)]
```

로그인 노드에서 위 형식에 맞게 명령어를 입력하면 아래와 같은 출력을 볼 수 있습니다.

( anaconda가 없는 경우 자동으로 설치됩니다.)

<figure><img src="/files/bP6yvjYlZnsSLbBZrqwU" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/35T9mkkQ4EjGMaSGhmED" alt=""><figcaption></figcaption></figure>

맨 아래 Jupyter Notebook에 접근 가능한 URL이 나타납니다.&#x20;

해당 URL을 복사한 후 노드 이름을 적절한 IP 주소로 변경하여 브라우저 창에 입력하면 됩니다.

각 노드별 접근 가능한 IP는 다음과 같습니다.

**a00-a11 -> 147.47.200.192** &#x20;

**b00-b15 -> 147.47.200.188**&#x20;

**b16-b31 -> 147.47.200.22**

위 예시에서는 노드 b24를 할당받았으므로 URL에서 b24를 147.47.200.22로 바꾸면 접속이 가능합니다.

{% hint style="warning" %}
launch-jupyter 역시 디버깅 용도로만 사용하고, <mark style="color:red;">**다수의 작업을 동시에 실행해야 하는 경우 sbatch 명령어를 사용**</mark>해주시기 바랍니다. ( launch-jupyter 최대 사용 시간은 4시간입니다.)
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gsds.gitbook.io/gsds/for-beginners/slurm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
