[mpich-discuss] Problem in sending vector <string> by MPI c++
Vineet Pratap (Vampaier)
pratap.vineet at gmail.com
Thu Aug 13 03:15:02 CDT 2009
Hello can somebody help me to sending it................
#include <iostream>
#include <vector>
#include <string>
#include"mpi.h"
using namespace std;
main(int argc, char *argv[])
{
MPI::Status status;
MPI::Init(argc,argv);
int myrank = MPI::COMM_WORLD.Get_rank();
int numprocs = MPI::COMM_WORLD.Get_size();
MPI_Datatype strtype;
//int blocklen=16;
//MPI_Aint disp[3]={0,16,32};
MPI_Type_contiguous(16,MPI::CHAR,&strtype);
MPI_Type_commit(&strtype);
vector<string> SS;
if(myrank == 0){
SS.push_back("The number is 10");
SS.push_back("The number is 20");
SS.push_back("The number is 30");
cout << "At root Node: " << endl;
int ii;
for(ii=0; ii < SS.size(); ii++)
{
cout << SS[ii] << endl;
}
//MPI_Type_contiguous(16,MPI::CHAR,strtype);
MPI::COMM_WORLD.Send(&SS[0],3,strtype, 1, 1);
}
else{
SS.reserve(3);
MPI::COMM_WORLD.Recv(&SS[0],3,strtype,0,1);
int ii;
cout << "At worker Node: " << endl;
for(ii=0; ii < SS.size(); ii++)
{
cout << SS[ii] << endl;
}
}
MPI::Finalize();
}
Now My O/P is:
$ mpicxx vecDemo.cpp -o vDemo.out -DMPICH_IGNORE_CXX_SEEK
$ mpirun -np 2 ./vDemo.out
At root Node:
The number is 10
The number is 20
The number is 30
At worker Node:
$
BUT i want O/P like.......
$ mpirun -np 2 ./vDemo.out
At root Node:
The number is 10
The number is 20
The number is 30
At worker Node:
The number is 10
The number is 20
The number is 30
$
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20090813/744aaa60/attachment.htm>
More information about the mpich-discuss
mailing list