I have defined a custom struct
which I need to send over to another
MPI process using the MPI_Bsend
(or MPI_Send
).
Here is the struct:
struct car{
int shifts;
int topSpeed;
}myCar;
The issue is that apart from primitive types MPI doesn't seem to support direct "transmission" of complex data types like the struct shown above. I've heard that I might have to use "serialization".
How should I approach this and successfully send over myCar
to process 5?
Best Solution
Jeremiah is right - MPI_Type_create_struct is the way to go here.
It's important to remember that MPI is a library, not built into the language; so it can't "see" what a structure looks like to serialize it by itself. So to send complex data types, you have to explicitly define its layout. In a language that does have native support for serialization, a set of MPI wrappers can concievably make use of that; mpi4py for instance makes use of python's pickle to transparently send complex data types; but in C, you have to roll up your sleeves and do it yourself.
For your structure, it looks like this: