List Info

Thread: LAM: 3D STL Vector




LAM: 3D STL Vector
user name
2007-09-26 13:34:59
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&gt; image;
typedef vector <image&gt; image3D;

int tam=10;
image3D test (tam) ;
iVec b ( 10 );

for ( int i=0; i<tam; i++ ) {
 &nbsp;  test[i].resize( tam );
 &nbsp;  b[i] = i;
 &nbsp;  for ( int j=0; j<tam; j++ ) {
   &nbsp;  &nbsp; test[i][j].resize( tam );
 ;  &nbsp;  &nbsp; for ( int k=0; k<tam; k++ ) {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; test[i][j][k] = i*j*k;
&nbsp; &nbsp; &nbsp;   }
 &nbsp;  }
}

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 ); &nbsp;

b.resize( tam );
MPI_Recv( &b[0], b.size(), MPI_INT, 0, 17, MPI_COMM_WORLD, &status ); &nbsp;

I'd like to do the same, but for 2D and 3D vectors. Has anyone ever tried anything like that?

Thanks in advance

--

Alysson Nunes Diógenes
Mechanical Engineering PhD Student
Laboratório de Meios Porosos e Propriedades Termofísicas
Universidade Federal de Santa Catarina
Re: LAM: 3D STL Vector
country flaguser name
France
2007-09-26 14: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

_______________________________________________
This list is archived at http://www.l
am-mpi.org/MailArchives/lam/

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )