Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |  

This web mail archive is frozen.

This page is part of a frozen web archive of this mailing list.

You can still navigate around this archive, but know that no new mails have been added to it since July of 2016.

Click here to be taken to the new web archives of this list; it includes all the mails that are in this frozen archive plus all new mails that have been sent to the list since it was migrated to the new archives.

Subject: [OMPI users] Send a struct with Vector or dynamics arrays
From: Jeferson Fs (duk_mad_at_[hidden])
Date: 2013-10-17 11:37:05

Hello,I am using OpenMPI v1.6.1 on Windows 7, and some time i am looking for any solution to send a struct with vector or using dynamics arrays.I know send structs with differents datatypes, like int, double, struct. But i have some problem sending vector or dynamics arrays.
Using MPI_Type_vector, MPI_Type_continuous or MPI_Type_extend i dont resolve....
#include "mpi.h"#include <iostream>#include <time.h> #include <vector>
using namespace std;
struct Teste6{ vector<int> t6;};
int main(int argc, char** argv){ MPI_Datatype struTeste6, oldTTeste6[1], newTTeste6; int blcklensTeste6[1]; MPI_Aint offsTeste6[1], extTeste6;
        Teste6 tst6; int max; int myRank; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myRank); MPI_Comm_size(MPI_COMM_WORLD, &max); // Teste6 //MPI_Type_vector(2,1,1,MPI_INT, &newTTeste6); MPI_Type_contiguous(2, MPI_INT, &newTTeste6); offsTeste6[0] = 0; oldTTeste6[0] = newTTeste6; blcklensTeste6[0] = 1; MPI_Type_struct(1, blcklensTeste6, offsTeste6, oldTTeste6, &struTeste6); MPI_Type_commit(&struTeste6); // if(myRank == 0) { //Add element 5 and element 10 to vector on struct tst6.t6.push_back(5); tst6.t6.push_back(10); //Print elements to look before send printf("\n myRank: %d - tst6.t6[0]: %d - tst6.t6[1]: %d", myRank, tst6.t6[0], tst6.t6[1]); //Send to Process 1 MPI_Send(&tst6, 1, struTeste6, 1, 1, MPI_COMM_WORLD); } else { // Receive from Process 0 MPI_Recv(&tst6, 1, struTeste6, 0, 1, MPI_COMM_WORLD, &status); //This code dont print received struct, some problem here, process die. printf("\n Slave 1 - myRank: %d - tst6.t6[0]: %d - tst6.t6[1]: %d", myRank, tst6.t6[0], tst6.t6[1]); }
        MPI_Finalize(); return 0;}
Atenciosamente,Jéferson Fernandes da Silva