Closed martinmestre closed 2 months ago
Sorry for the delay @martinmestre!
Can you say a bit more about how you are using the MultiPool
, and what kind of machine you are running on?
When I test this on my MacBook Pro, running a Python script from the command line, it seems to work fine. Here's the script I ran:
import sys
import time
import random
def worker(task):
i, num = task
time.sleep(0.1)
return num ** 2
if __name__ == '__main__':
from schwimmbad import MultiPool
size = None
if len(sys.argv) > 1:
size = int(sys.argv[1])
tasks = [(i, random.random()) for i in range(100)]
with MultiPool(processes=size) as pool:
print(pool)
results = []
for r in pool.map(worker, tasks):
results.append(r)
sys.exit(0)
Some timing:
% time python schwimmbad_test.py 1
<schwimmbad.multiprocessing.MultiPool state=RUN pool_size=1>
python schwimmbad_test.py 1 0.59s user 0.51s system 9% cpu 11.184 total
% time python schwimmbad_test.py 2
<schwimmbad.multiprocessing.MultiPool state=RUN pool_size=2>
python schwimmbad_test.py 2 0.83s user 0.65s system 24% cpu 6.169 total
% time python schwimmbad_test.py 4
<schwimmbad.multiprocessing.MultiPool state=RUN pool_size=4>
python schwimmbad_test.py 4 1.45s user 1.02s system 63% cpu 3.885 total
So, the timings seem to be scaling as I would expect.
Oh, and just in case you are using an interactive interpreter (like an IPython session or notebook), multiprocessing pools do not work in these settings: https://docs.python.org/3.8/library/multiprocessing.html#using-a-pool-of-workers
Happy New Year @adrn !
Thanks for your answer. My computer is Lenovo G50-80 with the following cpu info (Linux: Debian 9):
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 61 Model name: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
I made some tests with your example. First I start giving the output from using your script. Then I will address the original problem I bumped into, which is your example of selecting a pool from the command line argument here: https://schwimmbad.readthedocs.io/en/latest/examples/index.html.
1) Using your original script above (with the worker just peforming a sleep task) I obtain the following outputs:
$ \time python script-adrn.py 1
Sorry we never figured this out! Schwimmbad's MultiPool is basically just a light subclass of multiprocessing.Pool
, so I suspect the issue is not with schwimmbad but something else? Anyways, feel free to open a new issue if you are still having problems with this.
No problem at all! Thanks for the comment. I remember using schwimmbad for MPI, and for shared memory used directly multiprocessing.Pool. Maybe it was a problem in my conda environment. Best!
Hello Adrian,
thank you very much for your code for parallel computing. I would like to use it to change easily between my PC and the server. I must have some local problem in my computer because schwimmbad.MultiPool() doesn't use more than one core. It runs, but using always one core. I have checked that the pool is correctly defined: