"""Parallel Python Example""" import pp import time def is_prime(n): time.sleep(0.1) for j in range(2,n-1): if (n % j) == 0: return False return True start = time.time() primes100 = map(is_prime, xrange(2,101)) print "Serial time: %f" % (time.time() - start) start = time.time() #Setup job server job_server = pp.Server() #4 arguments: function, arguments, function dependencies, module dependencies job1 = job_server.submit(is_prime, (100,), (), ("time",)) # Retrieves the result calculated by job1 # The value of job1() is the same as sum_primes(100) # If the job has not been finished yet, execution will wait here until result is available result = job1() print "Is 100 a prime number? ", result # The following submits all 99 jobs and then retrieves the results inputs = range(2, 101) jobs = [(value, job_server.submit(is_prime, (value,), (), ("time",))) for value in inputs] completedjobs = [[value, job()] for value, job in jobs] print job_server.get_ncpus() print completedjobs # Print execution statistics print job_server.print_stats()