I'm working on a sample coding but just couldn't get send and receive the same value.
the datatype i create is
typedef struct customData{
double iv;
double dv[5];
char cv[10];
} customData;
I create datatype here
MPI_Datatype type;
MPI_Datatype ctype[3] = {MPI_DOUBLE, MPI_DOUBLE, MPI_CHAR};
int blocklen[3] = {1, 5, 10};
MPI_Aint disp[3] = { 0, sizeof(double), sizeof(double)*6 };
MPI_Type_create_struct(1, blocklen, disp, ctype, &type);
MPI_Type_commit(&type);
send and receive
if(rank == 0){
customData data = {5,
{1,2,3,4,5},
{'h','d','h','a','q','w','e','s','l','z'}};
printf("%f %.2f %c\n", data.iv, data.dv[0], data.cv[0]);
MPI_Send(&data, 1, type, 1, 0, MPI_COMM_WORLD);
} else {
customData recv;
MPI_Status status;
MPI_Recv(&recv, 1, type, 0, 0, MPI_COMM_WORLD, &status);
printf("%f %.2f %c\n", recv.iv, recv.dv[0], recv.cv[0]);
}
The output is
5.000000 1.00 h
5.000000 0.00 �