Hello,
I am just now starting to work with mpi4py and I am running into the following error:
mpi4py.MPI.Exception: Invalid communicator, error stack:
PMPI_Comm_rank(109): MPI_Comm_rank(MPI_COMM_NULL, rank=0x7fffffff5d5c) failed
PMPI_Comm_rank(66).: Null communicator
I have a python function defined in a file that is spawning worker processes:
---------------------------------
def search_direction(f, graph, g, od):
x = np.power(f.reshape((f.shape[0],1)), np.array([0,1,2,3,4]))
grad = np.einsum('ij,ij->i', x, graph[:,3:])
g.es["weight"] = grad.tolist()
L = np.zeros(len(
g.es),dtype='float64')
#The following code is for MPI
comm = MPI.COMM_SELF.Spawn(sys.executable,
args=['AoN_igraph_MPI.py'],
maxprocs=2)
comm.bcast(od, root=MPI.ROOT)
comm.bcast(g, root =MPI.ROOT)
comm.Reduce(none, L, op=MPI.SUM, root= MPI.ROOT)
return L, grad
------------------------------------
The work/child code is as follows (saved in AoN_igraph_MPI.py):
--------------------------------------------------
from mpi4py import MPI
from mpi4py.MPI import ANY_SOURCE
comm = MPI.Comm.Get_parent()
rank = comm.Get_rank() #Rank of the particular process
size = comm.Get_size() #number of processes
.....
---------------------------------------
Now, the code executes past the "comm = MPI.Comm.Get_parent()" command, but then stops with error whenever I try to get the rank or size in the work process. Is this a problem with the fact that it's a function that is spawning the worker processes? The search_direction function is called by another function solver_3, residing in the same file, which in turn is called by the main function in the file. Does mpi4py allow for function definition?
I should also mention that I have successfully ran the "Compute Pi" example provided in the tutorial, so I don't think it it a problem with the mpi4py installation on my machine. Also, this all running on a Linux machine.
Help with this would be greatly appreciated.
Juliette