相关疑难解决方法(0)

Python 3中大规模,强力最大化的高效多处理

这是我最近的问题的扩展,避免了Python 3的多处理队列中的竞争条件.希望这个版本的问题更加具体.

TL; DR:在一个多处理模型中,工作进程是从队列中提供的multiprocessing.Queue,为什么我的工作进程如此空闲?每个进程都有自己的输入队列,因此它们不会为共享队列的锁而互相争斗,但队列花费大量时间实际上是空的.主进程是运行I/O绑定线程 - 是否会减慢输入队列的CPU绑定填充?

我试图在一定的约束下找到N个集合的笛卡尔乘积的最大元素,每个集合具有M_i个元素(对于0 <= i <N).回想一下,笛卡尔积的元素是长度为N的元组,其元素是N组的元素.我将这些元组称为"组合",以强调我正在循环遍历原始集合的每个组合.当我的函数is_feasible返回时,组合符合约束True.在我的问题中,我试图找到其元素具有最大权重的组合:sum(element.weight for element in combination).

我的问题规模很大,但我公司的服务器也是如此.我正在尝试将以下串行算法重写为并行算法.

from operator import itemgetter
from itertools import product # Cartesian product function from the std lib
def optimize(sets):
    """Return the largest (total-weight, combination) tuple from all
    possible combinations of the elements in the several sets, subject
    to the constraint that is_feasible(combo) returns True."""
    return max(
                map(
                    lambda combination: (
                        sum(element.weight for element in …
Run Code Online (Sandbox Code Playgroud)

python parallel-processing python-3.x

8
推荐指数
1
解决办法
1078
查看次数

标签 统计

parallel-processing ×1

python ×1

python-3.x ×1