Created
September 12, 2014 15:55
-
-
Save brantfaircloth/73bbad82a89ccfe98dd7 to your computer and use it in GitHub Desktop.
A numpy/multiprocessing surprise
This file contains hidden or 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 numpy as np | |
from multiprocessing import Pool | |
def test(top): | |
return np.random.random_integers(0,100,5) | |
def main(): | |
# set this to a large CPU number | |
pool = Pool(4) | |
results = pool.map(test, [1,1,1,1,1,1]) | |
print results | |
if __name__ == '__main__': | |
main() |
This file contains hidden or 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
from numpy.random import RandomState | |
from multiprocessing import Pool | |
def test(top): | |
prng = RandomState() | |
nums = prng.randint(0, 100, size=5) | |
return nums | |
def main(): | |
pool = Pool(4) | |
results = pool.map(test, [1,1,1,1,1,1]) | |
print results | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output from
bad.py
:Output from
good.py
: