How to run nested, hierarchical pathos multiprocessing maps?

前端 未结 1 612
清歌不尽
清歌不尽 2020-12-21 08:46

Having build a significant part of my code on dill serialization/pickling, I\'m also trying to use pathos multiprocessing to parallelize my calculations. Pathos it is a natu

相关标签:
1条回答
  • 2020-12-21 09:19

    I encountered exactly the same issue. In my case, The inner operation was the one that needed parallelism so I did a ThreadingPool of a ProcessingPool. Here it is with your example:

    from pathos.multiprocessing import ProcessingPool, ThreadingPool
    
    def triple(x):
        return 3*x
    
    def refork(x):
        from pathos.multiprocessing import ProcessingPool
        return ProcessingPool().map(triple, xrange(5))
    
    ThreadingPool().map(refork, xrange(3))
    

    You can even have another layer with another outer threading pool. Depending on your case, you can invert the order of these pools. However, you cannot have processes of processes. If really needed, see: https://stackoverflow.com/a/8963618/6522112. I haven't try it yet myself so I can't elaborate on this.

    0 讨论(0)
提交回复
热议问题