On 14 January 2015 at 13:55, <ble...@karlin.mff.cuni.cz> wrote:
> Hi,
>
> is there a simple way to get mpi4py.MPI.Datatype object from numpy.dtype?
>
Well, it is not "simple" in the sense that there is no public API for it.
In [1]: import numpy as np
In [2]: from mpi4py import MPI
In [3]: nt = np.dtype('float32')
In [4]: datatype = MPI._typedict[nt.char]
def define_mpi_type(stc_array):
field_dtypes = []
field_shapes = []
for field in stc_array.dtype.fields:
myarfield = np.ascontiguousarray(stc_array[field])
field_dtypes.append(myarfield.dtype)
field_shapes.append(myarfield.shape)
blens = ()
disps = (0, )
types=()
i=-1
for dtype in field_dtypes:
i=i+1
shape = field_shapes[i]
blens = blens + (shape[1], )
ar_datatype = MPI._typedict[dtype.char]
disps = disps +(dtype.itemsize*shape[1],)
types = types + (ar_datatype,)
disps1 = (0,)
for d in range (1,len(disps)-1):
disps1 = disps1 + (disps1[d-1] + disps[d],)
type1 = MPI.Datatype.Create_struct(blens, disps1, types)
type1.Commit()
return type1
def define_mpi_type2_test():
dtype_char = ['B', 'B', 'I', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'f']
blens = (16, 16, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27840)
disps1 = (0, 16, 32, 36, 44, 52, 60, 68, 76, 84, 92, 100)
types=()
for i in range (len(dtype_char)):
ar_datatype = MPI._typedict[dtype_char[i]]
types = types + (ar_datatype,)
type1 = MPI.Datatype.Create_struct(blens,disps1,types)
type1.Commit()
return type1
Hi,
I kind of implemented my own mpi datatype creation from nump dtype (similar to the last post). Now I am getting a problem with a new test case, see below. The output "type1" has the following:
type1.ub = 111464
type1.extent = 111464
type1.size = 111460
The problem is once I try to use type1 to transfer some numpy array, it says: "message: cannot infer count, buffer length 499898100 is not a multiple of datatype extent 111464 (lb:0, ub:111464) " apparently because the size is different to the extent. Any idea what is the problem?