LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Brian Barrett (brbarret_at_[hidden])
Date: 2005-10-28 09:43:19


On Oct 28, 2005, at 8:54 AM, wgl wrote:

> 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

<snip>

> *********************************************************
> 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????

Looking only quickly at your code, I think the problem is the
information you are feeding MPI_Allgatherv doesn't match the memory
layout you actually have. It works in the first case (matrix[Nrow]
[Ncols]) because the memory will be laid out with one column
immediately after the other. However, when you use dynamically
allocated memory, that is no longer the case. Each row is going to
be in a different location in memory, and they are not necessarily
contiguous. There are a number of solutions to this, many of which I
believe have been discussed on this list. Or, of course, in any
reasonable textbook on scientific computing with MPI.

Brian

-- 
   Brian Barrett
   LAM/MPI developer and all around nice guy
   Have a LAM/MPI day: http://www.lam-mpi.org/