From: Michael Starkie Newsgroups: comp.parallel.mpi Subject: Re: Confused about Request::Wait(status) and tag = -1 !! Date: Mon, 28 Dec 1998 12:05:50 -0500 Organization: MIT Lincoln Laboratory Message-Id: <3687BA6D.27E1BE89@LL.MIT.EDU> References: <3682A45B.442E2F76@LL.MIT.EDU> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Michael Starkie wrote: The problem is with my usage of MPI::Request and the receive buffer. Polling on RTImpiManager::receive( char* message ) is confusing MPI because for every entry into receive a new req handle is being allocated inside MPI. Furthermore this handle is being associated with a dynamic buffer whose life only exists inside the receive method. The solution is to call req = comm.Irecv( ... ) only once with a persistant req variable and buffer. Then poll on the req variable with req.Test( status ). This solved the problem. Here is how I broke it up. main ( ... ) { ... char* msg = new char[256]; mpiMsgEnvelope env; env.type = MPI::CHAR; env.source = MPI::ANY_SOURCE; env.tag = MPI::ANY_TAG; int tag; MPI::Request req = RTIstreamManagerMpi::mpiMgr.reqIReceive( msg, 256, env ); while ( _done == RTI::RTI_FALSE ) { if( RTIstreamManagerMpi::mpiMgr.iReceive( req, tag ) ) if( tag == RTI_MPI_EXIT ) _done == RTI::RTI_TRUE } MPI::Finalize() } /* main */ MPI::Request RTImpiManager::reqIReceive( char* buf, int buf_size, mpiMsgEnvelope env ) { MPI::Request req; req = comm.Irecv( buf, buf_size, env.type, env.source, env.tag ); return req; } int RTImpiManager::iReceive( MPI::Request _req, int& _tag ) { MPI::Status status; if( _req.Test( status ) ) { _tag = status.Get_tag(); cout << "rank " << getRank() << " received tag " << _tag << endl; return 1; } else return 0; } > If I comment out req.Wait() then req.Test(status) always fails!!! > Why? > Do I really have to wait here? What is the purpose of a non blocking > receive then? > I would like to poll on RTImpiManager::receive without having to wait. > > req is a public member of RTImpiManager and is defined in the > constructor. > > Also when I do get a message, status.Get_tag() is always = -1. Why? > The send method is defined at the bottom of this text in > terminateProcesses. > > int > RTImpiManager::receive( char* message ) > { > char* buf = new char( STD_BUFFER_SIZE ); > > req = comm.Irecv( buf, STD_BUFFER_SIZE, MPI::CHAR, > MPI::ANY_SOURCE, MPI::ANY_TAG ); > > req.Wait(); > if( req.Test( status ) ) > { > cout << "rank " << getRank() << " received tag " << > status.Get_tag() << endl; > if( status.Get_tag() == RTI_MPI_EXIT ) > { > cout << "rank " << getRank() << " received terminate." << endl; > terminate(); > return 1; > } > else > { > int len = strlen( buf ) + 1; > message = new char( len ); > strcpy( message, buf ); > delete buf; > return 1; > } > } > else > return 0; > } > > ---------- > void > RTImpiManager::terminateProcesses() > { > char* none = 0; > for( int i = 1; i < getSize(); i++ ) > { > cout << "rank " << getRank() << " is sending to " << i << endl; > comm.Send( none, 0, MPI::CHAR, i, RTI_MPI_EXIT ); > } > MPI::Finalize(); > exit(0); > } > > -- > Cordially, > Michael Starkie > > -- Cordially, Michael Starkie