SLURM:如何在同一计算节点或不同节点上并行 运行 不同的可执行文件?
SLURM: How can I run different executables on parallel on the same compute node or in different nodes?
目标:
- 了解如何 运行 或共同安排或执行 executables/applications 与 sbatch 作业提交
- 使用 s运行 或 mpi运行
研究:
代码片段:
#!/bin/bash
#SBATCH --job-name LEBT
#SBATCH --partition=angel
#SBATCH --nodelist=node38
#SBATCH --sockets-per-node=1
#SBATCH --cores-per-socket=1
#SBATCH --time 00:10:00
#SBATCH --output LEBT.out
# the slurm module provides the srun command
module load openmpi
srun -n 1 ./LU.exe -i 100 -s 100 &
srun -n 1 ./BT.exe &
wait
手册页:
[srun]-->[https://computing.llnl.gov/tutorials/linux_clusters/man/srun.txt]
[mpirun]-->[https://www.open-mpi.org/doc/v1.8/man1/mpirun.1.php]
经过广泛研究,我得出结论,"srun" 是您要用于并行 运行 作业的命令。此外,您需要一个帮助脚本才能充分执行整个过程。我已经编写了以下脚本来毫无问题地在一个节点中执行应用程序。
#!/usr/bin/python
#SBATCH --job-name TPython
#SBATCH --output=ALL.out
#SBATCH --partition=magneto
#SBATCH --nodelist=node1
import threading
import os
addlock = threading.Lock()
class jobs_queue(threading.Thread):
def __init__(self,job):
threading.Thread.__init__(self,args=(addlock,))
self.job = job
def run(self):
self.job_executor(self.job)
def job_executor(self,cmd):
os.system(cmd)
if __name__ == __main__:
joblist = ["srun ./executable2",
"srun ./executable1 -i 20 -s 20"]
#creating a thread of jobs
threads = [jobs_queue(job) for job in joblist]
#starting jobs in the thread
[t.start() for t in threads]
#no interruptions
[t.join() for t in threads]
在我的特定情况下,激活特定标志的两个可执行文件每个产生大约 55 秒。但是,当它们 运行 并行时,它们都产生 59 秒的执行时间。
您的脚本将在稍作修改后工作。如果您不关心您的进程 运行 是否在同一节点上,请添加 #SBATCH --ntasks=2
#!/bin/bash
#SBATCH --job-name LEBT
#SBATCH --ntasks=2
#SBATCH --partition=angel
#SBATCH --nodelist=node38
#SBATCH --sockets-per-node=1
#SBATCH --cores-per-socket=1
#SBATCH --time 00:10:00
#SBATCH --output LEBT.out
# the slurm module provides the srun command
module load openmpi
srun -n 1 --exclusive ./LU.exe -i 100 -s 100 &
srun -n 1 --exclusive ./BT.exe &
wait
srun
的 --exclusive
参数告诉 srun
到 运行 整个分配的子集见 srun manpage.
如果您希望两个进程都在 sam 节点上 运行,请使用 --cpus-per-task=2
#!/bin/bash
#SBATCH --job-name LEBT
#SBATCH --cpus-per-task=2
#SBATCH --partition=angel
#SBATCH --nodelist=node38
#SBATCH --sockets-per-node=1
#SBATCH --cores-per-socket=1
#SBATCH --time 00:10:00
#SBATCH --output LEBT.out
# the slurm module provides the srun command
module load openmpi
srun -c 1 --exclusive ./LU.exe -i 100 -s 100 &
srun -c 1 --exclusive ./BT.exe &
wait
请注意,您必须 运行 srun
与 -c 1
而不是 -n 1
。
目标:
- 了解如何 运行 或共同安排或执行 executables/applications 与 sbatch 作业提交
- 使用 s运行 或 mpi运行
研究:
代码片段:
#!/bin/bash
#SBATCH --job-name LEBT
#SBATCH --partition=angel
#SBATCH --nodelist=node38
#SBATCH --sockets-per-node=1
#SBATCH --cores-per-socket=1
#SBATCH --time 00:10:00
#SBATCH --output LEBT.out
# the slurm module provides the srun command
module load openmpi
srun -n 1 ./LU.exe -i 100 -s 100 &
srun -n 1 ./BT.exe &
wait
手册页:
[srun]-->[https://computing.llnl.gov/tutorials/linux_clusters/man/srun.txt]
[mpirun]-->[https://www.open-mpi.org/doc/v1.8/man1/mpirun.1.php]
经过广泛研究,我得出结论,"srun" 是您要用于并行 运行 作业的命令。此外,您需要一个帮助脚本才能充分执行整个过程。我已经编写了以下脚本来毫无问题地在一个节点中执行应用程序。
#!/usr/bin/python
#SBATCH --job-name TPython
#SBATCH --output=ALL.out
#SBATCH --partition=magneto
#SBATCH --nodelist=node1
import threading
import os
addlock = threading.Lock()
class jobs_queue(threading.Thread):
def __init__(self,job):
threading.Thread.__init__(self,args=(addlock,))
self.job = job
def run(self):
self.job_executor(self.job)
def job_executor(self,cmd):
os.system(cmd)
if __name__ == __main__:
joblist = ["srun ./executable2",
"srun ./executable1 -i 20 -s 20"]
#creating a thread of jobs
threads = [jobs_queue(job) for job in joblist]
#starting jobs in the thread
[t.start() for t in threads]
#no interruptions
[t.join() for t in threads]
在我的特定情况下,激活特定标志的两个可执行文件每个产生大约 55 秒。但是,当它们 运行 并行时,它们都产生 59 秒的执行时间。
您的脚本将在稍作修改后工作。如果您不关心您的进程 运行 是否在同一节点上,请添加 #SBATCH --ntasks=2
#!/bin/bash
#SBATCH --job-name LEBT
#SBATCH --ntasks=2
#SBATCH --partition=angel
#SBATCH --nodelist=node38
#SBATCH --sockets-per-node=1
#SBATCH --cores-per-socket=1
#SBATCH --time 00:10:00
#SBATCH --output LEBT.out
# the slurm module provides the srun command
module load openmpi
srun -n 1 --exclusive ./LU.exe -i 100 -s 100 &
srun -n 1 --exclusive ./BT.exe &
wait
srun
的 --exclusive
参数告诉 srun
到 运行 整个分配的子集见 srun manpage.
如果您希望两个进程都在 sam 节点上 运行,请使用 --cpus-per-task=2
#!/bin/bash
#SBATCH --job-name LEBT
#SBATCH --cpus-per-task=2
#SBATCH --partition=angel
#SBATCH --nodelist=node38
#SBATCH --sockets-per-node=1
#SBATCH --cores-per-socket=1
#SBATCH --time 00:10:00
#SBATCH --output LEBT.out
# the slurm module provides the srun command
module load openmpi
srun -c 1 --exclusive ./LU.exe -i 100 -s 100 &
srun -c 1 --exclusive ./BT.exe &
wait
请注意,您必须 运行 srun
与 -c 1
而不是 -n 1
。