Parallel Python(PP)并行计算测试
2016-03-16 14:44
666 查看
测试环境:i5-2300(4核) + Win7
测试任务还是之前用的takeuptime()函数,串行计算实验的结果可以看这里:http://www.redicecn.com/html/Python/20111223/355.html
使用PP的测试代码如下:
程序运行结果如下:
I:\Webscraping\test>test
Usage: test.py [ncpus]
[ncpus] - the number of workers to run in parallel,
if omitted it will be set to the number of processors in the system
Starting pp with 4 workers
Time elapsed: 20.9220001698 s
Job execution statistics:
job count | % of all jobs | job time sum | time per job | job server
4 | 100.00 | 78.6590 | 19.664750 | local
Time elapsed since server creation 20.9240000248
所需的时间和之前用pprocess模块进行并行运算的结果差不多。
PP与pprocess模块相比优势在哪里?
1)PP不但支持Linux,Windows下也能使用。
2)PP不但支持单机多核(SMP,systems with multiple processors or cores),而且支持多台计算机(clusters,computers connected via network)。
目前只测试了SMP,期待clusters测试。
测试任务还是之前用的takeuptime()函数,串行计算实验的结果可以看这里:http://www.redicecn.com/html/Python/20111223/355.html
使用PP的测试代码如下:
import math, sys, time import pp def takeuptime(n): chars = 'abcdefghijklmnopqrstuvwxyz0123456789' s = chars * 1000 for i in range(10*n): for c in chars: s.count(c) print """Usage: test.py [ncpus] [ncpus] - the number of workers to run in parallel, if omitted it will be set to the number of processors in the system """ # tuple of all parallel python servers to connect with ppservers = () #ppservers = ("10.0.0.1",) if len(sys.argv) > 1: ncpus = int(sys.argv[1]) # Creates jobserver with ncpus workers job_server = pp.Server(ncpus, ppservers=ppservers) else: # Creates jobserver with automatically detected number of workers job_server = pp.Server(ppservers=ppservers) print "Starting pp with", job_server.get_ncpus(), "workers" start_time = time.time() # The following submits 4 jobs inputs = (1000, 1000, 1000, 1000) jobs = [(input, job_server.submit(takeuptime, (input,), (), ())) for input in inputs] #wait for jobs in all groups to finish job_server.wait() print "Time elapsed: ", time.time() - start_time, "s" job_server.print_stats()
程序运行结果如下:
I:\Webscraping\test>test
Usage: test.py [ncpus]
[ncpus] - the number of workers to run in parallel,
if omitted it will be set to the number of processors in the system
Starting pp with 4 workers
Time elapsed: 20.9220001698 s
Job execution statistics:
job count | % of all jobs | job time sum | time per job | job server
4 | 100.00 | 78.6590 | 19.664750 | local
Time elapsed since server creation 20.9240000248
所需的时间和之前用pprocess模块进行并行运算的结果差不多。
PP与pprocess模块相比优势在哪里?
1)PP不但支持Linux,Windows下也能使用。
2)PP不但支持单机多核(SMP,systems with multiple processors or cores),而且支持多台计算机(clusters,computers connected via network)。
目前只测试了SMP,期待clusters测试。
相关文章推荐
- Python串行运算、并行运算、多线程、多进程对比实验
- Python 高级编程笔记之类别
- Python工程师面试题集合
- 探索Python数据分析(一):NLTK库和文本处理
- 【python】编程学习练习题--3
- 10.python之socket和socketserver
- Python 模块学习:os模块
- 大数据处理之道(十分钟学会Python)
- 将Python脚本打包成可执行文件
- python超大数计算
- python学习5 常用三方模块
- Python 断言assert的使用
- Python学习笔记——数字
- python获取及时可用国外高匿名代理
- Python学习笔记——对象
- 【转】获取新闻和链接
- python @property
- 理解Python的With语句
- python异常处理
- python中使用中文