0
所以這是我的代碼蟒蛇多比正常慢執行
def get_h(tmp):
tmp =[map(float,line.split()[3:6]) for line in tmp[:768]]
return hbond(tmp,side)
def get_sc(tmp):
return popvar(tmp)
def calculate():
hframe=[]
pl=Pool()
s=time()
with open(file) as f:
for _ in xrange(100):
tmp=list(islice(f,9,9+atoms))
if not tmp: break
hframe.append(pl.apply_async(get_h,[tmp]))
hframe=[i.get() for i in hframe]
print time()-s #takes ~ 1 sec
s=time()
ll=[pl.apply_async(get_sc,[tmp]) for tmp in izip(*hframe)]
ll=[i.get() for i in ll]
print time()-s #takes ~23 sec !!!
s=time()
ll=[get_sc(tmp) for tmp in izip(*hframe)]
print time()-s #takes ~ 1 sec
的calculate
是這裏的主要功能。它有2件事。 1st讀取分塊的文件,2nd調用另一個函數(由Fortran程序創建)進行進一步計算。我用Python多處理pool
從文件讀取數據塊。但是當我使用pool
作爲計算部分時,它比正常實施要慢得多(近23倍)。這裏發生了什麼,我該如何解決?