คำสั่งต่าง ๆ bash script ของการสร้างไฟล์ Slurm
man sbatch
หรือsbatch -help
หรือ sbatch documentation
$ vi script.sh
#!/bin/bash
#SBATCH --job-name=test ## ชื่อของงาน
#SBATCH --output=test_%j.out ## ชื่อไฟล์ Output (%j = Job-ID)
#SBATCH --error=test_%j.err ## ชื่อไฟล์ error (%j = Job-ID)
#SBATCH --time=10:00 ## เวลาที่ใช้รันงาน
#SBATCH --ntasks=1 ## จำนวน tasks ที่ต้องการใช้ในการรัน
#SBATCH --cpus-per-task=1 ## จำนวน code ที่ต้องการใช้ในการรัน
#SBATCH --partition=cpu ## ระบุ partition ที่ต้องการใช้งาน
module purge ## unload module ทั้งหมด เพราะว่าอาจจะมีการ load module ไว้ก่อนหน้านั้น
module load anaconda3 ## load module ที่ต้องการใช้งาน ตัวอย่างนี้คือ Anaconda
srun python script.py ## สั่งรัน code
หมายเหตุ
- การ Submit งานที่ใช้ thread ให้กำหนด #SBATCH --cpus-per-task= ตามจำนวน threads ที่ใช้งาน
- การ Submit งานที่เป็น MPI ให้กำหนด #SBATCH --ntasks= ตามจำนวน Process ที่ต้องการ
- การ Submit งานที่ใช้ GPU เป็นหลัก ที่ partition GPU ให้กำหนด #SBATCH --cpus-per-task ตามความเหมาะสม หากงาน ไม่ได้แตก thread ให้กำหนดเป็น 1 หากแตก thread กำหนดได้ระหว่าง 2-4 threads เพื่อแบ่งปันคอร์ที่เหลือกับการ์ดใบอื่น ๆ จะได้ใช้งานระบบได้อย่างเต็มความสามารถ
$ sbatch script.sh
Sbatch option | Description |
---|---|
-J, --job-name=<job_name> |
Specify a name for the job allocation |
-o, --output=<filename_pattern> |
Standard output of the job script will be connected to the file specified by filename_pattern %x : Job name %j : Job-ID %t : Task identifier (aka rank). This will create a seperate file per task %N : Short hostname. This will create a separate file per node |
-e, --error=<filename_pattern> |
Standard error of the job script will be connected to the file specified by filename_pattern as described above |
-i, --input=<filename pattern> |
Standard input of the job script will be connected to the file specified by filename pattern |
-D, --chdir=<directory> |
Set the working directory of the batch script to directory before it is executed |
Sbatch option | Description |
---|---|
--mail-user=<email> |
Defines user who will receive email notification of state changes as defined by --mail-type |
--mail-type=[TYPE\|ALL\|NONE] |
Notifies user by email when certain event types occur. Valid type values are BEGIN, END, FAIL. The user to be notified is indicated with --mail-user. The values of the --mail-type directive can be declared in one line like so: --mail-type BEGIN, END, FAIL |
Sbatch option | Description |
---|---|
--time=<time> |
Sets a limit on the total run time of the job allocation |
-b, --begin=<time> |
Submit the batch script to the Slurm controller immediately, like normal, but tell the controller to defer the allocation of the job until the specified time |
Sbatch option | Description |
---|---|
--mem=<size>[units] |
Specify the memory required per node |
--mem-per-cpu=<size>[units] |
Specify the memory required per CPU |
--mem-per-gpu=<size>[units] |
Specify the memory required per GPU |
Sbatch option | Description |
---|---|
-n, --ntasks=<number> |
This option advises the Slurm controller that job steps run within the allocation will launch a maximum of number tasks and offer sufficient resources. The default is 1 task per node |
-N, --nodes=<minnodes>[-maxnodes] |
Request that a minimum of minnodes nodes be allocated to this job. A maximum node count may also be specified with maxnodes. If only one number is specified, this is used as both the minimum and maximum node count |
--ntasks-per-node=<ntasks> |
Request that ntasks be invoked on each node |
-c, --cpus-per-task=<ncpus> |
Advise the Slurm controller that ensuing job steps will require ncpus number of processors per task |
-p, --partition=<partition_names> |
Request a specific partition |
-w, --nodelist=<node_name_list> |
Request a specific list of hosts |
Sbatch option | Description |
---|---|
--gpus=[type:]<number> |
Specify the total number of GPUs required for the job |
--gpus-per-node=[type:]<number> |
Specify the number of GPUs required for the job on each node included in the job's resource allocation |