-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provides optional parallel running of repetitions #116
Conversation
On my laptop, running all tournaments serially takes approx. 90s. Running with -p 0 takes this down to approx. 75 seconds |
I'm finished with this one. It's ready to roll. |
@JasYoung314 can you also throw your eyes at this one. |
According to various online sources (e.g. http://stackoverflow.com/questions/10037319/how-do-i-tell-if-pythons-multiprocessing-module-is-using-all-of-my-cores-for-ca) python's multiprocessing.cpu_count will return double the actual number of cores for Intel CPUs with hyper threading. On my Macbook Air, 'About my Mac' shows it has an Intel I7 with 2 cores. cpu_count returns 4. Running run_tournament with -p 0 launches 4 processes and completes in approx. 75 seconds (as quoted previously). Running with -p 2 reduces this further to 70 seconds. |
I've just taken a look over it: Looks great! It's very similar to a way I had previously implemented parallel processing. Looking through the code, should line 74 in the tournament.py file be if self.processes < 2 or self.processes > multiprocessing.cpu_count(): I've left a comment in the commit itself. |
work_queue = multiprocessing.Queue() | ||
done_queue = multiprocessing.Queue() | ||
|
||
if self.processes < 2 or self.processes > multiprocessing.cpu_count: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
if self.processes < 2 or self.processes > multiprocessing.cpu_count():
Yep -that's a typo! Presumably I got away with it simply because it was treated as a property accessor. |
It's actually because in python, certain types have a notion of ordering. It's arbitrary but consistent, so you could compare the function >>> multiprocessing.cpu_count()
4
>>> 5 < multiprocessing.cpu_count
True
>>> 5 > multiprocessing.cpu_count
False because the type integer is always considered to be less than the type function. More information (and a much more informed explanation can be found here) Pull request seems awesome! |
Thank you @JasYoung314 for both the explanation and the compliment!! (Is now a good time to own up to the fact that I'm only really doing this because I've not used Python before and fancied an excuse to learn)? |
(I think the time to own up was before you started messing with multiprocessing! Now you're one of us I'm afraid) |
I added something to the README also. Thanks for this @meatballs : huge contribution. |
Thanks a lot @JasYoung314 for reviewing this. |
And possibly other things I've forgotten.
And possibly not some things I've overlooked!