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){
int lena[count];
MPI_Aint loca[count];
MPI_Datatype typa[count];
for (int i=0; i<count; ++i) {
lena[i] = d;
MPI_Address(&Points[displ+i][0], &loca[i]);
typa[i] = MPI_INT;
}
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){
MPI_Datatype MY_MPI_TYPE_R;
buildDerivedDataType(Points, d, receiveCount[k]/d, disp[k]/d,
&MY_MPI_TYPE_R);
MPI_Recv(MPI_BOTTOM, 1, MY_MPI_TYPE_R, k, 111, MPI_COMM_WORLD,
&Stat);
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".
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);
MPI_Type_free(&MY_MPI_TYPE);
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
|