Hi All,
I am trying to create a derived datatype and have not had any luck getting it to work. When the the program gets to MPI_Type_struct() call inside of the function DerivedTypeMPIDummyStruct(), it returns, "MPI_Type_create_struct: invalid argument: Invalid argument (rank 0, MPI_COMM_WORLD)". Can anyone point me to the mistake I am making?
Here is the portion of the code that deals with the derived datatype:
typedef struct{
int c;
double d;
} dummyStruct
dummyStruct *dummy = NULL;
MPI_Datatype *mpiDummy = NULL;
dummy = (dummyStruct *) malloc(sizeof(dummyStruct));
if (dummy == NULL) {
goto end;
}
dummy->c = 5;
dummy->d = 12.5;
DerivedTypeMPIDummyStruct(dummy, mpiDummy);
MPI_Send(dummy, 1, mpiDummy, SLAVE,
22, MPI_COMM_WORLD);
MPI_Type_free(mpiDummy);
free(dummy);
dummy = NULL;
void DerivedTypeMPIDummyStruct(dummyStruct *dummy,
MPI_Datatype *mpiDummy)
{
int blockLengths[2];
MPI_Aint displacements[3];
MPI_Aint addresses[2];
MPI_Datatype typeList[2];
typeList[0] = MPI_INT; //c
typeList[1] = MPI_DOUBLE; //d
blockLengths[0] = 1;
blockLengths[1] = 1;
MPI_Address(dummy, &addresses[0]);
MPI_Address(&(dummy->c), &addresses[1]);
MPI_Address(&(dummy->d), &addresses[2]);
displacements[0] = addresses[1] - addresses[0];
displacements[1] = addresses[2] - addresses[0];
MPI_Type_struct(2, blockLengths, displacements, typeList, mpiDummy);
MPI_Type_commit(mpiDummy);
}
Thanks in advance for the help,
Jeremy
|