Parallel Python PP是否总能找回工作并按照我们创建它们的顺序产生结果?

时间:2014-05-26 09:45:16

标签: python numpy parallel-processing

我们正在使用PP启动流程,需要按照我们将其发送到服务器的顺序聚合作业结果。有没有一种堆来控制结果的聚合?

import pp, numpy
def my_silly_function(a,b):
   return a**4+b**15

# call the server (with pile?)
ppservers = ()
job_server = pp.Server(ppservers=ppservers, secret="password")
# launch jobs and aggregate them into a list 
jobs1=numpy.array[job_server.submit(my_silly_function, args=(w,w+40)) for w in xrange(1000)]

- >我们希望结果将以我们发送的顺序返回(因此不需要lexsort来按照我们要求的顺序获取它们吗?

1 个答案:

答案 0 :(得分:1)

答案是肯定的。订单得以维持。如果您想选择如何使用阻塞映射,迭代映射或异步(无序)映射来返回结果,那么您可以在pp中使用pathos的分支。 pathos.pp fork也适用于python 3.x。

>>> # instantiate and configure the worker pool
>>> from pathos.pp import ParallelPythonPool
>>> pool = ParallelPythonPool(nodes=4)
>>>
>>> # do a blocking map on the chosen function
>>> print pool.map(pow, [1,2,3,4], [5,6,7,8])
[1, 32, 729, 16384]
>>>
>>> # do a non-blocking map, then extract the results from the iterator
>>> results = pool.imap(pow, [1,2,3,4], [5,6,7,8])
>>> print "..."
>>> print list(results)
[1, 32, 729, 16384]
>>>
>>> # do an asynchronous map, then get the results
>>> results = pool.amap(pow, [1,2,3,4], [5,6,7,8])
>>> while not results.ready():
>>>     time.sleep(5); print ".",
>>> print results.get()
[1, 729, 32, 16384]

在此处获取pathos.pphttps://github.com/mmckerns