There's probably an alignment gap between the short and char array, and possibly an alignment gap between the char array and the double array (depending on the value of SHORT_INPUT and your architecture).
So for your displacements, you should probably actually measure what the displacements are instead of using sizeof(short), for example. tVStruct foo; aiDispsT5[0] = 0; aiDispsT5[0] = ((char*) &(foo.sCapacityFile) - (char*) &foo); (I just typed that in my email client and didn't verify it; pardon typos) On Jun 29, 2011, at 11:42 AM, jody wrote: > Hi > > I have noticed on my machine that a struct which i have defined as > > typedef struct { > short iSpeciesID; > char sCapacityFile[SHORT_INPUT]; > double adGParams[NUM_GPARAMS]; > } tVStruct; > > (where SHORT_INPUT=64 and NUM_GPARAMS=4) > > has size 104 (instead of 98) whereas the corresponding MPI Datatype i created > > int aiLengthsT5[3] = {1, SHORT_INPUT, NUM_GPARAMS}; > MPI_Aint aiDispsT5[3] = {0, iShortSize, iShortSize+SHORT_INPUT}; > MPI_Datatype aTypesT5[3] = {MPI_UNSIGNED_SHORT, MPI_CHAR, MPI_DOUBLE}; > MPI_Type_create_struct(3, aiLengthsT5, aiDispsT5, aTypesT5, > &m_dtVegetationData3); > MPI_Type_commit(&m_dtVegetationData3); > > only has length 98 (as expected). The size differences resulted in an > error when doing > > tVegetationData3 VD; > MPI_Send(&VD, 1, m_dtVegetationData3, 1, TAG_STEP_CMD, MPI_COMM_WORLD); > > and the corresponding > > tVegetationData3 VD; > MPI_Recv(&VD, 1, m_dtVegetationData3, MPI_ANY_SOURCE, > TAG_STEP_CMD, MPI_COMM_WORLD, &st); > > (in fact, the last double in my array was not transmitted correctly) > > It seems that on my machine the struct was padded to a multiple of 8. > By manually adding some padding bytes to my MPI Datatype in order > to fill it up to the next multiple of 8 i could work around this problem. > (not very nice, and very probably not portable) > > > My question: is there a way to tell MPI to automatically use the > required padding? > > > Thank You > Jody > _______________________________________________ > users mailing list > us...@open-mpi.org > http://www.open-mpi.org/mailman/listinfo.cgi/users -- Jeff Squyres jsquy...@cisco.com For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/