Thursday, January 7, 2010

Simple python parallelisation example

#!/usr/bin/python

import pp

def add_one(n):
return n+1

job_server = pp.Server()

args1 = (1,)
args2 = (2,)
args3 = (3,)

f1 = job_server.submit(add_one, args1)
f2 = job_server.submit(add_one, args2)
f3 = job_server.submit(add_one, args3)

r1 = f1()
r2 = f2()
r3 = f3()

print "r1 is " + str(r1)
print "r2 is " + str(r2)
print "r3 is " + str(r3)

No comments: