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

Vineet Pratap (Vampaier) pratap.vineet at gmail.com
Sun Aug 16 23:51:25 CDT 2009


PLZ help to solve this problem, i m new in parallel
programming...............


#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
type[6]={MPI_CHAR,MPI_CHAR,MPI_CHAR,MPI_CHAR,MPI_CHAR,MPI_CHAR};
        MPI_Datatype strtype;
        int blocklen[6]={1,1,1,1,1,1};
        MPI_Aint disp[6]={0,1,2,3,4,5};
        MPI_Type_struct(6,blocklen,disp,type,&strtype);
        MPI_Type_commit(&strtype);
        vector<string> SS;
         if(myrank == 0){
   SS.push_back("The10");
   SS.push_back("The20");
   SS.push_back("The30");

        cout << "At root Node: "<< endl;

   int ii;
   for(ii=0; ii < SS.size(); ii++)
   {
      cout << SS[ii] << endl;
   }

        MPI::COMM_WORLD.Send(&SS[0][0],1,strtype, 1, 1);
        MPI::COMM_WORLD.Send(&SS[1][0],1,strtype, 1, 1);
        MPI::COMM_WORLD.Send(&SS[2][0],1,strtype, 1, 1);
 }
else{
        SS.resize(6);
        MPI::COMM_WORLD.Recv(&SS[0][0],1,strtype,0,1);
        MPI::COMM_WORLD.Recv(&SS[1][0],1,strtype,0,1);
        MPI::COMM_WORLD.Recv(&SS[2][0],1,strtype,0,1);
   int i,j;
         cout << "At worker Node: " << endl;
   for(i=0; i < 3; i++){
    for(j=0;j<6;j++){
     cout << SS[i][j];
    }cout<<endl;
  }
 }
        MPI::Finalize();
}




My O/P is :

mpirun -np 2 ./vDemo.out
At root Node:
The10
The20
The30
At worker Node:
The30
The30
The30

But I want my O/P like:
 mpirun -np 2 ./vDemo.out
At root Node:
The10
The20
The30
At worker Node:
The10
The20
The30
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20090817/1ba4eafe/attachment.htm>


More information about the mpich-discuss mailing list