[mpich-discuss] mpich-discuss Digest, Vol 11, Issue 8
Vineet Pratap (Vampaier)
pratap.vineet at gmail.com
Wed Aug 12 04:53:05 CDT 2009
Plz Correct this code................
#include<iostream>
#include<vector>
#include "mpi.h"
using namespace std;
int main(int argc, char *argv[])
{
MPI::Status status;
MPI::Init();
int myrank = MPI::COMM_WORLD.Get_rank();
int numprocs = MPI::COMM_WORLD.Get_size();
vector<int> ourvector(2);
if(myrank == 0){
ourvector[0] = 98;
// cout << "The max number the vector can hold is : " <<
ourvector.max_size();
// cout << "\nourvector has : " << ourvector.capacity() << " elements
in it";
ourvector.push_back(99);
// cout << "\nNow ourvector has : " << ourvector.size() << " elements
in it";
// cout << "\nThe Value of the first vector element is : " <<
ourvector[0];
// cout << "\nThe Value of our second vector element is : " <<
ourvector.at(1) << endl;
MPI::COMM_WORLD.Send(&ourvector[0],2,MPI::INT, 1, 1);
// MPI::COMM_WORLD.Send(&ourvector[1],1,MPI::INT, 1, 1);
}
else{
ourvector.reserve(2);
MPI::COMM_WORLD.Recv(&ourvector[0],2, MPI::INT,0,1);
// MPI::COMM_WORLD.Recv(&ourvector[1],1, MPI::INT,0,1);
//ourvector.pop_back();
cout << "ourvector now has : " << ourvector.capacity() << "
elements" << endl;
cout << "\nNow ourvector has 1st : " << ourvector[0];
cout << "\nNow ourvector has 2nd : " << ourvector[1]<< endl;
// cout << "Our fisrt element in ourvector is : " << ourvector.front()
<< endl;
ourvector.resize(9);
ourvector.at(8) = 99;
// cout << "Our last element in ourvect is : " << ourvector.back() <<
endl;
// cout << "ourvector now holds : " << ourvector.size() << " elements"
<< endl;
}
MPI::Finalize();
return 0;
} <http://trac.guake-terminal.org/files/>
Now MY output is
$ mpirun -np 2 ./vec.out
ourvector now has : 2 elements
Now ourvector has 1st : 98
Now ourvector has 2nd :0
I want output like <http://trac.guake-terminal.org/files/>
$ mpirun -np 2 ./vec.out
ourvector now has : 2 elements
Now ourvector has 1st : 98
Now ourvector has 2nd :99
<http://trac.guake-terminal.org/files/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20090812/5cbe1cb6/attachment.htm>
More information about the mpich-discuss
mailing list