我使用python的“多处理”模块在多个核心上运行单个进程,但我希望并行运行几个独立进程。对于ex Process one解析大文件,Process two在不同的文件中查找模式,Process three进行一些计算;是否可以并行运行具有不同参数集的所有三个不同处理?
def Process1(largefile):
Parse large file
runtime 2hrs
return parsed_file
def Process2(bigfile)
Find pattern in big file
runtime 2.5 hrs
return pattern
def Process3(integer)
Do astronomical calculation
Run time 2.25 hrs
return calculation_results
def FinalProcess(parsed,pattern,calc_results):
Do analysis
Runtime 10 min
return final_results
def main():
parsed = Process1(largefile)
pattern = Process2(bigfile)
calc_res = Process3(integer)
Final = FinalProcess(parsed,pattern,calc_res)
if __name__ == __main__:
main()
sys.exit()
在上述伪代码进程1中,进程2和进程3是单核进程,即它们不能在多个处理器上运行。这些过程按顺序运行,需要2+2.5+2.25小时=6.75小时。这三个进程可以并行运行吗?因此,它们在不同的处理器/内核上同时运行,并且当大多数时间(Process2)结束时,我们将转到最终进程。
我非常感谢你的帮助。
AK公司
来自16.6.1.5. Using a pool of workers:
因此,您可以对池应用异步,并在一切就绪后获取结果。
相关问题 更多 >
编程相关推荐