Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] data types and alignment to word boundary
From: Dave Goodell (goodell_at_[hidden])
Date: 2011-06-29 12:16:51

On Jun 29, 2011, at 10:56 AM CDT, Jeff Squyres wrote:

> 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);

There's a C-standard "offsetof" macro for this calculation. Using it instead of the pointer math above greatly improves readability:

So the second line becomes:

aiDispsT5[1] = offsetof(tVStruct, sCapacityFile);