Proper way to use multiprocessor.Pool in a nested loop

后端 未结 3 1931
礼貌的吻别
礼貌的吻别 2020-12-05 10:40

I am using the multiprocessor.Pool() module to speed up an \"embarrassingly parallel\" loop. I actually have a nested loop, and am using multiprocessor.Pool to speed up the

3条回答
  •  天涯浪人
    2020-12-05 11:18

    import time
    from pathos.parallel import stats
    from pathos.parallel import ParallelPool as Pool
    
    
    def work(x, y):
        return x * y
    
    
    pool = Pool(5)
    pool.ncpus = 4
    pool.servers = ('localhost:5654',)
    t1 = time.time()
    results = pool.imap(work, range(1, 2), range(1, 11))
    print("INFO: List is: %s" % list(results))
    print(stats())
    t2 = time.time()
    print("TIMER: Function completed time is: %.5f" % (t2 - t1))
    

提交回复
热议问题