Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge_subgroup_data #1192

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ PyObject *_get_array_slice_dimensions(meep::fields *f, const meep::volume &where
in_point,
in_volume,
interpolate,
merge_subgroup_data,
output_epsilon,
output_mu,
output_hpwr,
Expand Down
49 changes: 49 additions & 0 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3169,3 +3169,52 @@ def quiet(quietval=True):

def verbosity(verbose_val):
mp.cvar.verbosity = verbose_val

def merge_subgroup_data(data,num_groups):
smartalecH marked this conversation as resolved.
Show resolved Hide resolved
# Lazy import
from mpi4py import MPI

# Pull required parameters
comm = MPI.COMM_WORLD
num_workers = comm.Get_size()
shape=data.shape
size = data.size
out_shape = shape + (num_groups,)
dtype=data.dtype.char

# Initialize new input and output datasets
input=np.zeros(shape,dtype,order='F')
input[:]=data
smartalecH marked this conversation as resolved.
Show resolved Hide resolved
output=np.zeros(out_shape,dtype,order='F')

# Specify how much talking each proc will do
count_in = np.array([size] * num_workers)
count_out = np.array([size] * num_workers)
stevengj marked this conversation as resolved.
Show resolved Hide resolved

# Specify MPI datatype from numpy array
TypeMap = dict(
b=MPI.SIGNED_CHAR,
h=MPI.SHORT,
i=MPI.INT,
l=MPI.LONG,
q=MPI.LONG_LONG,
f=MPI.FLOAT,
d=MPI.DOUBLE,
F=MPI.C_COMPLEX,
D=MPI.C_DOUBLE_COMPLEX)
mpi_dtype = TypeMap[dtype]
sdt = [mpi_dtype] *num_workers
rdt = [mpi_dtype] *num_workers
stevengj marked this conversation as resolved.
Show resolved Hide resolved

# Specify array mapping
sdsp = [0] * num_workers
rdsp = [i for i in range(0, size*num_groups,size) for _ in range(int(num_workers/num_groups))]

# Formulate send and receive packets
smsg = [input, (count_in, sdsp), mpi_dtype]
rmsg = [output, (count_out, rdsp), mpi_dtype]

# Send and receive
comm.Alltoallv(smsg, rmsg)

return output
smartalecH marked this conversation as resolved.
Show resolved Hide resolved