-
Notifications
You must be signed in to change notification settings - Fork 33
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
python multiprocessing start_method #679
Comments
Here is a notebook I use to measure the performance of multiprocessing. Can you tell how it behaves for you (with the error message if any)? It works normally on all my macOS machines, I'll try it on linux. Do you have more details about the "many users": location, platform, versions… Just to try and find some common properties. |
I do not have details, but the PR originates from complaints from CERN... @simoneliuzzo may know more about it. @carmignani , @simoneliuzzo I think you are the only extensive MAC users here. Could you test it on your side as well? |
I repeated my test on linux ("grappa" machine), and I found indeed strange results: for tracking 100 particles over 1000 turns on the On my Mac (4 cores):use_mp=False: 4.25 s On linux ("grappa" machine):use_mp=False: 4.75 s (slightly slower than my old Mac) So I agree that there is a problem, but it seems to be linked to the operating system… |
@swhite2401: does anyone get errors, or just performance problems? |
On grappa, running a script in the terminal I get the usual error:
Could you try running in the terminal instead of using jupyter? |
This error by the way does not make sense because on unix |
In fact, I could not use Jupyter (new problem…), so I copied line by line my notebook into a terminal.
and I installed AT exactly as documented: cd <my working copy of AT>
pip install -e . |
So I run the exact same commands in a python prompt (just like you did) it works. |
Very strange. I get exactly the same problem. But a very simple modification of the script works: import sys
import at
import numpy as np
if sys.version_info.minor < 9:
from importlib_resources import files, as_file
else:
from importlib.resources import files, as_file
from time import time
def main():
np.set_printoptions(linewidth=120)
np.set_printoptions(precision=12)
fname = 'hmba.mat'
with as_file(files('machine_data') / fname) as path:
ring = at.load_lattice(path)
ring.disable_6d()
sigm = at.sigma_matrix(ring.enable_6d(copy=True))
npart = 100
nturns = 1000
pin = at.beam(npart, sigm)
print(pin.shape)
print("Tracking starts")
t0 = time()
pout1, _, td1 = ring.track(pin, nturns=nturns, losses=True, use_mp=True, start_method="spawn")
print(time() - t0)
print("Tracking starts")
t0 = time()
pout2, _, td2 = ring.track(pin, nturns=nturns, losses=True)
print(time() - t0)
np.testing.assert_equal(td1['loss_map'], td2['loss_map'])
np.testing.assert_equal(pout1, pout2)
if __name__ == '__main__':
main() With this, it works normally both on macOS and linux.
So there is a solution, but I do not understand why encapsulating the code in a function solves the problem. |
The script of @lfarv for me works and gives this output |
Probably we cannot do much more than improving the documentation, we could possibly catch the RuntimeError and also give an error message with some instructions. |
3 methods are available for the python python multiprocessing:
The default for unix will also be set to spawn starting at python 3.13.
Many users have reported errors using the spawn method on MAC and unix systems. This problem is not understood and could become a severe issue if the fork method is deprecated in the future.
The text was updated successfully, but these errors were encountered: