当前位置: 主页 > 日志 > Python >

Parallel Python(PP)并行计算测试

Parallel Python(PP)

 

测试环境:i5-2300(4核) + Win7

测试任务还是之前用的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测试。

 

[日志信息]

该日志于 2011-12-26 13:23 由 redice 发表在 redice's Blog ,你除了可以发表评论外,还可以转载 “Parallel Python(PP)并行计算测试” 日志到你的网站或博客,但是请保留源地址及作者信息,谢谢!!    (尊重他人劳动,你我共同努力)
   
验证(必填):   点击我更换验证码

redice's Blog  is powered by DedeCms |  Theme by Monkeii.Lee |  网站地图 |  本服务器由西安鲲之鹏网络信息技术有限公司友情提供

返回顶部