1. 程式人生 > >python平行計算(持續更新)

python平行計算(持續更新)

工作中需要對tensorflow 的一個predict結果加速,利用python中的執行緒池

 def getPPLs(tester,datas):

  for line in datas:
tester(line)

tester = run_epoch.rescore(session, test_lm, data, test_data, eval_op=None, test=True)
listDatas=splitList(test_data,16)#16 是執行緒的數量
threadsPool=[]
for sub_test_data in listDatas:
threadsPool.append(Thread(target=getPPLs, args=(tester, sub_test_data)))

for thread in threadsPool:
thread.start()

for thread in threadsPool:
thread.join()
tmd2=time()
print("tmd2-tmd1 ",tmd2-tmd1)