List Info

Thread: LAM: gatherv a vector




LAM: gatherv a vector
user name
2006-10-24 20:45:07
hi,

I am able to send/receive an stl vector of vectors  (of integers) using derived datatypes. Now I want to optimize my communicationby using scatterv/gatherv, but I am having problems understanding how to map my send/recv method into a collective communication.
My code is as follows

//function to build a derived datatype:
void buildDerivedDataType(vector< vector <int>; > &Points, int d, int count, int displ, MPI_Datatype *MY_MPI_TYPE){
 ; &nbsp; int lena[count]; &nbsp; 
 &nbsp;  MPI_Aint loca[count];
 &nbsp;  MPI_Datatype typa[count];

 ; &nbsp; for (int i=0; i<count; ++i) {
 &nbsp;   &nbsp;  lena[i] = d;
   ;  &nbsp;  MPI_Address(&Points[displ+i][0], &loca[i]);
 ; &nbsp;  &nbsp;  typa[i] = MPI_INT;
  ;  }
 &nbsp;  MPI_Type_struct(count, lena, loca, typa, MY_MPI_TYPE);
   ; MPI_Type_commit(MY_MPI_TYPE);
}

//everybody sends to ROOT processor
MPI_Datatype MY_MPI_TYPE;
buildDerivedDataType(localSk, d, localSkSize, 0, &MY_MPI_TYPE);
MPI_Send(MPI_BOTTOM, 1, MY_MPI_TYPE, ROOT, 111, MPI_COMM_WORLD);
MPI_Type_free(&MY_MPI_TYPE);

....

//ROOT processor receives the vectors of vectors from each processor
//space for Points is already allocated
if(myID==ROOT){
&nbsp; &nbsp;  MPI_Datatype MY_MPI_TYPE_R; &nbsp; 
 &nbsp; &nbsp; buildDerivedDataType(Points, d, receiveCount[k]/d, disp[k]/d, &MY_MPI_TYPE_R);
 &nbsp; &nbsp; MPI_Recv(MPI_BOTTOM, 1, MY_MPI_TYPE_R, k, 111, MPI_COMM_WORLD, &Stat); &nbsp;   &nbsp; 
 &nbsp; &nbsp; MPI_Type_free(&MY_MPI_TYPE_R);
}

this works just fine, all my data is now at ROOT in the vector of vector Points. But now I want to use mpi_gatherv instead of the above, so I was trying something like this; "disp" has the displacements in units of "int&quot;.
&nbsp; &nbsp; int cnt = 1;
   ; MPI_Gatherv(&localSk[0].front(), 1, MY_MPI_TYPE, &Points[0].front(), &cnt, disp, MY_MPI_TYPE_R, ROOT, MPI_COMM_WORLD); &nbsp; 
 &nbsp;  MPI_Type_free(&MY_MPI_TYPE);  ;  &nbsp; 
 &nbsp;  MPI_Type_free(&MY_MPI_TYPE_R);

Can anyone point me to the right direction as to what would the be the format of scatterv/gatherv in this situation?

thanks
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )