I want to implement a simple computation task in parallel. Lets say I have two arrays including 2 components in each and I want to sum the components of these array one by one and store them in a new array. There are 4 combinations of the components (2x2). A simple code could be written in serial that uses only 1 core and the summing operation is implemented 4 times on that core. Here is the code:
a = [1 , 5]
b = [10 , 20]
d = []
for i in range(2):
for j in range(2):
c = a[i] + b[j]
d.append(c)
print (d)
Now I want to use MPI to run the above code in parallel to use 4 different cores on my PC to make it faster. With that being said I want each combination to be implemented on the assigned core (e.g. 4 summing operations on 4 different cores). Here is how I can import MPI:
from mpi4py import MPI
mpi_comm = MPI.COMM_WORLD
rank_process = mpi_comm.rank
I have never used parallel computations so it looks a bit confusing to me. I was wondering if someone could help me with this. Thanks in advance for your time.