Hi, everyone, I encountered a interesting problem while using
MPI_Allgatherv:
**********************************************************
int myRank, Nprocessors
MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
MPI_Comm_size(MPI_COMM_WORLD, &Nprocessors);
4 int matrix[Nrows][Ncolumns]; // This is the interesting line
int counts[Nprocessors];
int displacements[Nprocessors];
int bin = Nrows/(Nprocessors-1) // assuming Nrows is exact times of
(Nprocessors-1), node0 is server node, no job was assigned to it
counts[0] = 0;
displacements[0] = 0;
displacements[1] = 0;
for( i=1; i<Nprocessors; i++ ) {
displacements[i] = displacements[i - 1] +
counts[i-1];
counts[i] = bin;
}
MPI_Allgather( &counts[myRank], 1, MPI_INT, counts, 1, MPI_INT,
MPI_COMM_WORLD );
my_offset = displacements[myRank];
for(i=0; i<counts[myRank]; i++)
for(j=0; j<Ncolumns; j++) matrix[my_offset+i][j] = (my_offset+i]*1000
+ j;
MPI_Type_contiguous(Ncolumns, MPI_INT, &rowtype);
MPI_Type_commit(&rowtype);
MPI_Allgatherv(&matrix[my_offset], counts[myRank], rowtype, matrix,
counts, displacements, rowtype, MPI_COMM_WORLD);
*********************************************************
Above code works perfectly, but you change line 4 to:
int **matrix;
matrix = new int*[Nrows];
for (i=0; i<Nrows; i++) matrix[i] = new int[Ncolumns];
then MPI_Allgatherv don't work properly, matrix from different nodes
are different !!! Looks like MPI_Allgatherv could not handle address
of dynamically allocated array well. Why? Any suggestions????
Thanks for any helps,
Guoli
Guoli Wang, Ph.D.
Bioinformatics Group
Fox Chase Cancer Center
Phone: (215)-214-4261
|