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: Gus Correa (gus_at_[hidden])
Date: 2011-06-29 15:33:25


Gus Correa wrote:
> 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
>> users_at_[hidden]
>> http://www.open-mpi.org/mailman/listinfo.cgi/users
>
>
> Hi Jody
>
> My naive guesses:
>
> I think when you create the MPI structure you can pass the
> byte displacement of each structure component.
> You would need to modify your aiDispsT5[3], to match the
> actual memory alignment, I guess.
> Yes, indeed portability may be sacrificed.
>
> There is some clarification in "MPI, The Complete Reference, Vol 1,
> 2nd Ed, Marc Snir et al.".
> Section 3.2 and 3.3 (general on type map & type signature).
> Section 3.4.8 MPI_Type_create_struct (examples, specially 3.13).
> Section 3.10, on portability, doesn't seem to guarantee portability of
> MPI_Type_Struct.
>
> I hope this helps,
> Gus Correa
> _______________________________________________
> users mailing list
> users_at_[hidden]
> http://www.open-mpi.org/mailman/listinfo.cgi/users

Hi Jody

How about compiling the program with -fpack-struct ?

This is assuming you're using gcc.
Or use an equivalent flag if using another compiler.
I think in icc it is -noalign,
and pgcc may be -Mnodalign -Mnollalign.
See man gcc/icc/pgcc.
Code won't be optimal, compatible, etc,
which may be a price too high to pay to squeeze a
structure in smallest amount of memory possible.

Also, check if the 8-byte alignment you see
is hidden behind other general optimization flags.

**
How about this 'alignment-aware-memory-wasteful' alternative:

typedef struct {
      short iSpeciesID;
      short[3] dummy; /* just padding */
      char sCapacityFile[SHORT_INPUT];
      double adGParams[NUM_GPARAMS];
  } tVStruct;

      int aiLengthsT5[4] = {1, 3, SHORT_INPUT, NUM_GPARAMS};
      MPI_Aint aiDispsT5[4] = {0, iShortSize, 4*iShortSize,
4*iShortSize+SHORT_INPUT};
      MPI_Datatype aTypesT5[4] = {MPI_UNSIGNED_SHORT,
MPI_UNSIGNED_SHORT, MPI_CHAR, MPI_DOUBLE};
      MPI_Type_create_struct(4, aiLengthsT5, aiDispsT5, aTypesT5,
  &m_dtVegetationData3);
MPI_Type_commit(&m_dtVegetationData3);

Maybe replacing some of the 3s and 4s above by a preprocessor macro,
say PAD_SIZE (=3), and (PAD_SIZE+1), to be able to adjust for other
choices of SHORT_INPUT.

Would it be viable?

My two cents,
Gus Correa