[mpich-discuss] mpich-discuss Digest, Vol 11, Issue 8

Dorian Krause ddkrause at uni-bonn.de
Wed Aug 12 08:44:45 CDT 2009


if you create outvector like

vector<int> ourvector(2);

and than push_back "99" the vector will look like

{ 98, (whatever), 99}

Try to do call the constructor

vector<int> ourvector(1);

Then you should (If I understand the stl correctly) end up with

{ 98, 99 }

as you intend.

Hope this helps ...

Regards,
Dorian


Vineet Pratap (Vampaier) wrote:
> 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/>



More information about the mpich-discuss mailing list