[mpich-discuss] MPI_DATATYPE for an array

Sunshine Sunshine sunshine1414 at hotmail.fr
Fri Apr 27 02:23:39 CDT 2012


Hello,

I wonder if i can create a new MPI_DATATYPE for my structure that include an array declared as a pointer: I have the following structures:

struct elt
{ long ind;
  double val;
};
typedef struct elt elt;

struct Fragment
{ 
  int num;
  elt *elt;
};
typedef struct Fragment  Fragment;

elt's size is not the same for all Fragment, and i try to send data using MPI_SCATTER, i tried  the following code:

MPI_Datatype MPI_elt;
MPI_Datatype typeelt[2] = {MPI_LONG,MPI_DOUBLE};
int l_bloc[2]={1,1};
MPI_Aint dispo[2];
elt ELT;
MPI_Address(&ELT.ind, dispo); 
MPI_Address(&ELT.val, dispo+1); 
MPI_Aint base2 = dispo[0]; 
for (j=0; j <2; j++) dispo[j] -= base2;
MPI_Type_struct(2, l_bloc,dispo,typeelt,&MPI_elt);    
MPI_Type_commit(&MPI_elt);

MPI_Datatype MPI_FRAGMENT
MPI_Datatype typeFRAGMENT[2] = {MPI_INT,MPI_AINT};
int l_bloc3[2]={1,1};
MPI_Aint disposition[2];
Fragment FN;
MPI_Address(&FN.num, disposition); 
MPI_Address(&FN.elt, disposition+1);
MPI_Aint base3 = disposition[0]; 
for (j=0; j <2; j++) disposition[j] -= base3;
MPI_Type_struct(2, l_bloc3,disposition, typeFRAGMENT,&MPI_FRAGMENT);    
MPI_Type_commit(&MPI_FRAGMENT);

but i don't receive the whole values of elt, any help please?

Thanks. 

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20120427/4f43ea39/attachment.htm>


More information about the mpich-discuss mailing list