I'm looking to run the bottleneck in my program on multiple processors locally. I've looked into multiprocessing
but it looks a little complicated for my purposes and I'm wondering if there is a simpler way.
I have a loop over 360 angles with a calculation that is independent for each one, so it doesn't matter what order it is done in. I have 8 cores so was hoping I could simply split that loop into 8 chunks of 45 angles and send those to different cores and collect the result at the end. The simplified example looks something like this:
dx = np.zeros(npixels)
for angle in range(360):
dx += calculate_gradient_for_angle(angle, x, y, z, **kwargs)
Here, only the angle
argument is variable. The rest are static.
I've looked into multiprocessing.pool.Pool.map
but I can only find examples that show single-argument functions passed to it. As you can see my function takes multiple arguments. Any pointers would be much appreciated.
I'm using Python 3.7.8 on macOS 10.14.6