【问题标题】:Behavior of multiprocessing module on cluster集群上多处理模块的行为
【发布时间】:2015-02-20 12:11:38
【问题描述】:

有些模块适合集群上的多处理,列出了here。但我有一个脚本已经在使用multiprocessing 模块。 This answer 声明在集群上使用这个模块只会让它在一个节点内进行进程。但是这种行为是什么样的呢?

假设我有一个名为 multi.py 的脚本,它看起来像这样:

import multiprocessing as mp

output = mp.Queue()

def square(num, output):
""" example function. square num """
res = num**2
output.put(res)

processes = [mp.Process(target=square, args=(x, output)) for x in range(100000)]

# Run processes
for p in processes:
   p.start()

# Exit the completed processes
for p in processes:
    p.join()

# Get process results from the output queue
results = [output.get() for p in processes]

print(results)

我会将此脚本提交到集群(例如 Sun Grid Engine):

#!/bin/bash
# this script is called run.sh
python multi.py

qsub:

qsub -q short -lnodes=1:ppn=4 run.sh

会发生什么? python 是否会在qsub 命令中指定的边界内生成进程(仅在 4 个 CPU 上)?还是会尝试使用节点上的每个 CPU?

【问题讨论】:

    标签: python multiprocessing cluster-computing qsub


    【解决方案1】:

    您的qsub 调用为每个节点提供 4 个处理器,其中 1 个节点。因此multiprocessing 将被限制为最多使用 4 个处理器。

    顺便说一句,如果您想进行分层并行计算:使用套接字或 ssh 跨多个集群,使用 MPI 并与集群调度程序协调,以及使用多处理和线程……您可能想看看 pathos 它是姐妹包pyina(与 MPI 和集群调度程序交互)。

    例如,请参阅:https://stackoverflow.com/questions/28203774/how-to-do-hierarchical-parallelism-in-ipython-parallel

    在此处获取pathoshttps://github.com/uqfoundation

    【讨论】:

    • 新版本即将发布(稳定版本太老了,早于pip 的版本控制要求)。但是,它是纯 python,如果你从 github 获得它,它会使用 easy_install 安装。
    猜你喜欢
    • 1970-01-01
    • 2020-06-23
    • 2018-05-19
    • 1970-01-01
    • 2011-10-16
    • 2016-09-10
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    相关资源
    最近更新 更多