Slurm多处理Python作业 [英] Slurm Multiprocessing Python Job
问题描述
我有一个4节点的Slurm集群,每个集群有6个核心.我想使用以下多重处理提交一个测试Python脚本(它生成打印正在运行其的节点的主机名的进程):
I have a 4 node Slurm cluster, each with 6 cores. I would like to submit a test Python script (it spawns processes that print the hostname of the node it's being run on) utilizing Multiprocessing as follows:
def print_something():
print gethostname()
# number of processes allowed to run on the cluster at a given time
n_procs = int(environ['SLURM_JOB_CPUS_PER_NODE']) * int(environ['SLURM_JOB_NUM_NODES'])
# tell Python how many processes can run at a time
pool = Pool(n_procs)
# spawn an arbitrary number of processes
for i in range(200):
pool.apply_async(print_something)
pool.close()
pool.join()
我使用SBATCH脚本提交了该脚本,该脚本指定了node = 4和ntasks-per-node = 6,但是我发现Python脚本执行了4 * 6次.我只希望作业执行一次脚本,并允许Slurm在整个集群中分布进程生成.
I submit this with an SBATCH script, which specifies nodes=4 and ntasks-per-node=6, but I am finding that the Python script gets executed 4*6 times. I just want the job to execute the script once, and allow Slurm to distribute the process spawns across the cluster.
我在这里显然不明白...?
I'm obviously not understanding something here...?
推荐答案
好,我知道了.
我需要对SBATCH和SRUN之间的关系有更好的了解.主要是,SBATCH可以充当SRUN调用的全局作业容器.
I needed to have a better understanding of the relationship between SBATCH and SRUN. Mainly, SBATCH may act as a global job container for SRUN invocations.
这里最大的因素是从Python多处理变为子处理.这样,SBATCH可以执行一个python脚本,而该脚本又可以动态调用另一个python脚本的SRUN子进程,并适当地分配群集资源.
The biggest factor here was changing from Python Multiprocessing to Subprocess. This way, the SBATCH can execute a python script, which in turn can dynamically invoke SRUN subprocesses of another python script, and allocate cluster resources appropriately.
这篇关于Slurm多处理Python作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!