[MPICH] help self-defined datatype

llwaeva at 21cn.com llwaeva at 21cn.com
Thu Sep 29 00:57:54 CDT 2005


on 2005-9-29 6:35:09, Syed Irfan <irfan at itee.uq.edu.au> wrote:
> Hi,
> 
> Could you post the updated code that works?
> 
> cheers
> 
As some many people mentioned before, the problem is come from how to
correct the definition of displacement and they have show me two ways,
so I just change/add the code as follow

1)
    #ifndef FIVE
      int S=4;
      MPI_Datatype type[4] = { MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE};
      int blocklen[4] = { 1, 1, 1, 1 };
      /* here is modified */
      MPI_Aint disp[4] = {0, sizeof(double), 2*sizeof(double), 3*sizeof(double)};
    #else
      int S=5;
      MPI_Datatype type[5] = { MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE};
      int blocklen[5] = { 1, 1, 1, 1, 1 };
      /* here is modified */
      MPI_Aint disp[5]={0, sizeof(double), 2*sizeof(double), 3*sizeof(double), 4*sizeof(double)};
    #endif


2) another way is to calculate the displacement by MPI_Address
    MPI_Aint baseaddress;  /* added code */
    #ifndef FIVE
      int S=4;
      MPI_Datatype type[4] = { MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE};
      int blocklen[4] = { 1, 1, 1, 1 };
      MPI_Aint disp[4];    /* being calculated later */
    #else
      int S=5;
      MPI_Datatype type[5] = { MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE};
      int blocklen[5] = { 1, 1, 1, 1, 1 };
      MPI_Aint disp[5];    /* being calculated later */
    #endif

      ...
      MPI_Address( &data[0][0], &baseaddress );
      MPI_Address( &data[0][0].r, &disp[0]); disp[0] -= baseaddress;
      MPI_Address( &data[0][0].c, &disp[1]); disp[1] -= baseaddress;
      MPI_Address( &data[0][0].d, &disp[2]); disp[2] -= baseaddress;
      MPI_Address( &data[0][0].v, &disp[3]); disp[3] -= baseaddress;
      #ifdef FIVE
        MPI_Address( &data[0][0].f, &disp[4]); disp[4] -= baseaddress;
      #endif


That's all.




More information about the mpich-discuss mailing list