LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Joel Eaves (joel_at_[hidden])
Date: 2005-06-22 13:47:46


Hi group,

I'm trying to do gathers and scatters on the columns of a matrix using
derived datatypes. I can think of a few workarounds, but this should
work. The derived datatypes behave just fine for sends and receives,
but the scatters and gathers are really unreliable and unpredictable.
I've been unable to discern patterns in their failures. Here is a
piece of code that does not gather or scatter a derived datatype
correctly:

#include <mpi.h>
#include <iostream>

using namespace std;
int main(){
MPI::Init();
int size = MPI::COMM_WORLD.Get_size(),my_rank =
MPI::COMM_WORLD.Get_rank(),i,k,n_global = 10,d=3,n_local =
nglobal/size;
double A_local[n_local][d],A_global[n_global][d];
for(i=0;i<n_local;i++)
for(k=0;k<d;k++)
A_local[i][k] = double(my_rank);
MPI_Datatype column;
MPI_Type_vector(n_local,1,d,MPI_DOUBLE,&column);
MPI_Type_commit(&column);

//Now, if i do this I get the data no problem
/*
for(k=0;k<d;k++){
if(my_rank==0)
MPI::COMM_WORLD.Recv(&(A_global[n_local][k]),1,column,1,0);
else
MPI::COMM_WORLD.Send(&(A_local[0][k]),1,column,0,0);
}
*/

//But if I instead rely on the derived datatype and the gather function
the data gets all screwed up
for(k=0;k<d;k++)
MPI::
COMM_WORLD.Gather(&(A_local[0][k]),1,column,&(A_global[0][k]),1,column,0
);

if(my_rank==0){
for(i=0;i<n_global;i++){
for(k=0;k<d;k++)
cout << A_global[i][k] << "\t";
cout << endl;
}
}
return 0;
}

Thanks,

Joel