Commit 6b0de4bc authored by POLCHER Jan's avatar POLCHER Jan 🚴🏾
Browse files

Adds a function to gather and merge lists onto roo proc. It works based on a...

Adds a function to gather and merge lists onto roo proc. It works based on a list of indicis already assembled on the root proc and then add to this list other information which is distributed over other procs.
parent a6511876
......@@ -731,3 +731,31 @@ class partition :
self.comm.send(np.pad(x, [0,maxlen-len(x)], mode='constant', constant_values=np.nan), dest=0)
#
return xout
#
# Function to gather a list (x) given an index list (ix) onto the root proc and its index list (iout)
#
def gathermergelist(self, ix, x, iout) :
if isinstance(ix,list) and isinstance(x,list) :
if self.rank == 0 :
xout=['']*len(iout)
# Receive from all procs
for lr in range(self.size) :
if lr == 0 :
for ie,xe in zip(ix,x) :
# If in the target order we have the index then we fill the value.
if iout.count(ie) > 0 :
xout[iout.index(ie)] = xe
else :
tmp = self.comm.recv(source=lr)
for ie,xe in zip(tmp[0],tmp[1]) :
# If in the target order we have the index then we fill the value.
if iout.count(ie) > 0 :
xout[iout.index(ie)] = xe
else :
xout = None
self.comm.send([ix,x], dest=0)
else :
ERROR("Argument to gatherlist is not a python list")
sys.exit()
#
return xout
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment