我如何實現對我的函數的多處理。我嘗試這樣做,但沒有奏效。對python函數進行多處理
def steric_clashes_parallel(system):
rna_st = system[MolWithResID("G")].molecule()
for i in system.molNums():
peg_st = system[i].molecule()
if rna_st != peg_st:
print(peg_st)
for i in rna_st.atoms(AtomIdx()):
for j in peg_st.atoms(AtomIdx()):
# print(Vector.distance(i.evaluate().center(), j.evaluate().center()))
dist = Vector.distance(i.evaluate().center(), j.evaluate().center())
if dist<2:
return print("there is a steric clash")
return print("there is no steric clashes")
mix = PDB().read("clash_1.pdb")
system = System()
system.add(mix)
from multiprocessing import Pool
p = Pool(4)
p.map(steric_clashes_parallel,system)
我有一千個pdb或系統文件來測試通過這個函數。在沒有多處理模塊的情況下,單個內核上的一個文件需要2小時。任何建議都會有很大的幫助。
我回溯看起來是這樣的:
self.run()
File "/home/sajid/sire.app/bundled/lib/python3.3/threading.py", line 858,
in run self._target(*self._args, **self._kwargs)
File "/home/sajid/sire.app/bundled/lib/python3.3/multiprocessing/pool.py", line 351,
in _handle_tasks put(task)
File "/home/sajid/sire.app/bundled/lib/python3.3/multiprocessing/connection.py", line 206,
in send ForkingPickler(buf, pickle.HIGHEST_PROTOCOL).dump(obj)
RuntimeError: Pickling of "Sire.System._System.System" instances is not enabled
(boost.org/libs/python/doc/v2/pickle.html)
「沒有工作」是不夠的...你得到什麼錯誤?什麼是「PDB」和「System()」?我們並不都是空談的人。 – tdelaney
對不起,我在多處理模塊上沒有足夠的背景。在運行腳本我得到了以下輸出; –
self.run() 文件「/home/sajid/sire.app/bundled/lib/python3.3/threading.py」,行858,運行 self._target(* self._args,** self。 _kwargs) 文件「/home/sajid/sire.app/bundled/lib/python3.3/multiprocessing/pool.py」,第351行,在_handle_tasks put(任務) 文件「/home/sajid/sire.app /bundled/lib/python3.3/multiprocessing/connection.py「,行206,發送 ForkingPickler(buf,pickle.HIGHEST_PROTOCOL).dump(obj) RuntimeError:酸洗」Sire.System._System.System「實例沒有啓用(http://www.boost.org/libs/python/doc/v2/pickle.html) –