并行pythonpp总是按照我们创建作业的顺序返回作业的结果吗?

2024-05-15 03:13:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我们正在使用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按我们要求的顺序获取结果?你知道吗


Tags: importnumpy服务器server进程顺序mydef
1条回答
网友
1楼 · 发布于 2024-05-15 03:13:40

答案是肯定的。维持秩序。如果您想选择如何使用块映射、迭代映射或异步(无序)映射返回结果,那么可以使用pathos中的pp分叉。pathos.ppfork也适用于python3.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

相关问题 更多 >

    热门问题