我是python和Parallel Python的新手。问题是我要完成4个工作:生成4个掩码,将它们与输入图像相乘,然后进行进一步处理。以下是为并行处理而编写的代码片段。
inputs = range(4)
jobs = [(inpt, job_server.submit(PP, (inpt,input_data,size,(imageMultiply,blockCounter,imageQuantizer ), ("numpy","Image"))) for inpt in inputs]
job_server.print_stats()
for inpt, job in jobs:
print "No of blocks in ", inpt, "is", job() ## accessing the result of pp
我得到的输出是:
Starting pp with 4 workers
Job execution statistics:
job count | % of all jobs | job time sum | time per job | job server
4 | 100.00 | 0.0000 | 0.000000 | local
Time elapsed since server creation 0.0219678878784
4 active tasks, 4 cores
No of blocks in 0 is 52
No of blocks in 1 is 61
No of blocks in 2 is 104
No of blocks in 3 is 48
我无法理解如果它不能同时处理,我仍然可以获得所需的输出,但所用的时间太长,这就是我想使用pp的原因。 请帮我这个,这样我就可以成功减少时间。 提前谢谢......
答案 0 :(得分:0)
从print_stats()
输出(此处重新格式化)
Job execution statistics:
job count | % of all jobs | job time sum | time per job | job server
4 | 100.00 | 16.0401 | 4.010028 | local
Time elapsed since server creation 4.04183793068
0 active tasks, 4 cores
一切似乎都很好。你有4个CPU核心;您可以在创建作业服务器后的4秒内完成4个作业;系统总共消耗了16个CPU秒来完成所有工作。
您可能需要尝试top -H
,htop
或Windows Sysinternals Process Monitor
来实时观察CPU消耗。