It’s all begun when I needed to MPI_Bcast a 64 bit integer. Since MPI does not know how to handle it I did:
template<typename T>
inline int BcastObjects(T* pointer,
int count,
int root,
MPI_Comm comm)
{
return MPI_Bcast(pointer,
count * sizeof(*pointer),
MPI_BYTE,
root,
comm);
}
Now I can do:
int64_t i = 0;
BcastObjects(&i, 1, root_rank, some_communicator);
Then I started to use BcastObjects to send over an array of structures. I wonder if it’s OK to do that?
The manuals about MPI_Datatype focus on how to do it, but not on why would I want to do it.
Why not just use
MPI_INT64_T?You can always mock up your own datatypes with
MPI_Byteor what have you; the datatype stuff is there so that you don’t have to. And in many cases it’s much easier; if you want to send data that has “holes” in it (eg, a slice of a multidimensional array, data in a structure that has gaps), you can map that out fairly straighforwardly with a datatype, whereas you’d have to manually count out byte strings and use something likeMPI_Packotherwise. And of course describing the data at a higher level is certainly less brittle if something in your data structure changes.