|
Boost Users : |
Subject: Re: [Boost-users] [mpi] - why this code hangs on gather?
From: tomasz jankowski (tomasz_jacek_at_[hidden])
Date: 2009-10-28 06:04:15
Dnia 27-10-2009 o godz. 13:49 Matthieu Brucher napisa³(a):
> Hi,
>
> If I understood your code correctly, you are sending every piece of
> data through rank 0 and then it waits for the completion of the
> operations. Then, every rank receives data, as well as the first rank.
> But the first rank is waiting for ots own receive to finish, which can
> never happen. You should put the wait all after the receptions.
at last I have found:
code done by rest of ranks (non 0) should be closed in brace parenthesis
> > if( world.rank() == 0 ){
> >
> > mpi::request reqs[nProcs-1];
> >
> > for(unsigned int i=1;i<nProcs;++i){
> > std::vector<molecule> sendmol;
> > unsigned int pos=extraBits+i*chunkSize;
> >
> > for(unsigned int j=0;j<chunkSize;++j){
> > sendmol.push_back(data[pos]);
> > pos++;
> > }
> >
> > reqs[i-1] = world.isend(i, 0, sendmol);
> > std::cout<<"msg sended to "<< i <<std::endl;std::cout.flush();
> > }
> >
> > for(unsigned int i=0;i<chunkSize + extraBits;++i){
> > molecule tmp = data[i];
> > tmp.x_ *= uni_real();
> > tmp.y_ *= uni_real();
> > tmp.z_ *= uni_real();
> > tmp.message_ = "from process: " +
> > boost::lexical_cast<std::string>(world.rank());
> > res.push_back(tmp);
> > }
> >
> > mpi::wait_all(reqs, reqs + nProcs - 1);
> > std::cout<<"calculation finished in 0 "<<std::endl;std::cout.flush();
> >
> > }
//here should be
else{
> >
> >
> >
> >
> > std::vector<molecule> recvmol;
> > mpi::request recv;
> > recv = world.irecv(0, 0, recvmol);
> > recv.wait();
> > std::cout<<"receiving finished
> > "<<world.rank()<<std::endl;std::cout.flush();
> >
> >
> > for(unsigned int i=0;i<recvmol.size();++i){
> > molecule tmp = recvmol[i];
> > tmp.x_ *= uni_real();
> > tmp.y_ *= uni_real();
> > tmp.z_ *= uni_real();
> > tmp.print();
> > tmp.message_ = "from process: " +
> > boost::lexical_cast<std::string>(world.rank());
> > res.push_back(tmp);
> > }
> > std::cout<<"calculation finished in
> > "<<world.rank()<<std::endl;std::cout.flush();
//here block should be closed
}
> > //wysylanie wynikow ze wszystkich procesow mpi do procesu 0
> > if( world.rank() == 0 ){
> > gather(world,res,allRes,0);
> > std::cout<<"gather finished "<<world.rank()<<std::endl;std::cout.flush();
> >
> > } else {
> > gather(world,res,0);
> > std::cout<<"gather finished"<<world.rank()<<std::endl;std::cout.flush();
> >
> > }
> >
> > // output
> > if(world.rank()==0){
> > for(unsigned int i=0;i<static_cast<unsigned int>(world.size());++i){
> > std::cout<<"results from process "<<i<<": "<<std::endl;
> >
> > for(int k=0; k<allRes[i].size();k++){
> > allRes[i][k].print();
> > }
> > std::cout<<std::endl;
> >
> > }
> > std::cout<<"making output finished
> > "<<world.rank()<<std::endl;std::cout.flush();
> >
> > }
> >
> > return 0;
> > }
----------------------------------------------------
Film Solista: 9/10 Jak dla mnie rewelacyjny!
Piêkny wzruszaj±cy g³êboki!
Trudna tematyka, ale pokazana w mistrzowski sposób.
http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fsolista.html&sid=900
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net