Created
September 11, 2013 17:00
-
-
Save jarobins/6526580 to your computer and use it in GitHub Desktop.
Some testing of the multiprocessing module in python. Trying to learn.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
from multiprocessing import Pool | |
def say_hello(nums): | |
return sum([x**x for x in xrange(nums[0], nums[1])]) | |
if __name__ == '__main__': | |
num_processors = multiprocessing.cpu_count() | |
print 'You have {0:1d} CPUs'.format(num_processors) | |
nums = [(0, 1000), (1000, 2000), (2000, 3000), (3000, 4000)] | |
pool = Pool(processes=num_processors) | |
count = pool.map(say_hello, nums) | |
print sum(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment