LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Marc Sauget (marc.sauget_at_[hidden])
Date: 2007-09-26 15:02:00


Alysson Nunes Diógenes a écrit :
> Hi all.
>
> I have a c++ application using stl vectors. Actually, vectors of
> vectors, like the one below.
>
> using namespace std;
> typedef vector <int> iVec;
> typedef vector <iVec> image;
> typedef vector <image> image3D;
>
> int tam=10;
> image3D test (tam) ;
> iVec b ( 10 );
>
> for ( int i=0; i<tam; i++ ) {
> test[i].resize( tam );
> b[i] = i;
> for ( int j=0; j<tam; j++ ) {
> test[i][j].resize( tam );
> for ( int k=0; k<tam; k++ ) {
> test[i][j][k] = i*j*k;
> }
> }
> }
>
> I would like to send that to other processor. I read some other emails
> which said things about resizing vectors and that really did work for
> one dimension vectors, but it doesn't work for 2D or 3D vectors.
>
> MPI_Send(&tam, sizeof( tam ), MPI_INT, 1, 17, MPI_COMM_WORLD);
> MPI_Send(&b[0], b.size(), MPI_INT, 1, 17, MPI_COMM_WORLD); /*this
> work for 1D*/
>
> Receiving
>
> int tam;
> MPI_Recv( &tam, sizeof( tam ), MPI_INT, 0, 17, MPI_COMM_WORLD, &status
> );
>
> b.resize( tam );
> MPI_Recv( &b[0], b.size(), MPI_INT, 0, 17, MPI_COMM_WORLD, &status );
>
> I'd like to do the same, but for 2D and 3D vectors. Has anyone ever
> tried anything like that?
>
> Thanks in advance

Hi,

noting ensure that all the data are continious for a multi-dimention vector.
The most simple in your case is to build a new "one-dimension" vector
before send your data.

In other way, you can use the function mpipack mpi un_pack

like that: MPI_Pack(&ta,1, MPI_INT, buff, taille,&p,canal);
    for (i=0; i< nbElems; i++){
      MPI_Pack(&entrees[i][0],ta,MPI_DOUBLE, buff, taille, &p,canal);
    }

After, you can send you data with

" MPI_Send(buff, taille, MPI_PACKED,0, 0,canal);"

Hope this can help you

++ Marc