I have a for loop which calculates a number in each iteration and sets it as a new element in a zeros array. How to parallelize this loop with mpi4py? Help is much appreciated! Code is given below.
b = 1000
R = numpy.linspace(2, 2.5, b)
z = numpy.zeros_like(R)
for i in range(len(z)):
z[i] = calculate(R[i]) #pseudocode
There is some example of parallelizing a for loop which adds numbers on this website ([https://computationalmechanics.in/parallelizing-for-loop-in-python-with-mpi/]), but I don't even know how to begin! (Beside the part on the beggining which I understand, setting the rank, size, etc).
mpi4pyin particular? I'd start with seeing if you cannumba.jitthecalculatefunction, and if it's not fast enough then, try e.g. plain oldmultiprocessing.z = [calculate(x) for x in numpy.linspace(2, 2.5, b)]would be more succinct...