1
鑑於我算法的隨機結構,我希望並行運行數百次。參數每次保持不變。具有多個參數的多處理映射
這兩個實現都會引發某種異常(PicklingError或TypeError)。
from multiprocessing import Pool
from itertools import izip, repeat
if __name__ == '__main__':
G = Class1Object()
S = Class2Object()
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
# take 1 tuple input
# parfun = lambda (G,S): fun(G,S)
# T = pool.map(parfun, izip(repeat(G, 2), repeat(S, 2)))
# take 2 arguments
T = pool.map(fun, [G]*2, [S]*2)
什麼是最快和最方便的方式來並行運行多個參數的函數?
這個問題沒有解決這個問題嗎? http://stackoverflow.com/questions/5442910/python-multiprocessing-pool-map-for-multiple-arguments –