/******************************************************************* * * DESCRIPTION: class Simulator * * AUTHOR: Amir Barylko & Jorge Beyoglonian * * EMAIL: mailto://amir@dc.uba.ar * mailto://jbeyoglo@dc.uba.ar * * DATE: 27/6/1998 * *******************************************************************/ /** include files **/ #include "simulat.h" // header #include "atomic.h" // class Atomic #include "message.h" // class InitMessage #include "msgadm.h" // SingleMsgAdmin /** public functions **/ /******************************************************************* * Function Name: Simulator * Description: constructor ********************************************************************/ Simulator::Simulator( Atomic *atomic ) : Processor( atomic ), procType("SIMULATOR") {} /******************************************************************* * Function Name: receive * Description: set the time for the first internal event ********************************************************************/ Processor &Simulator::receive( const InitMessage &msg ) { Atomic &at( static_cast( model() ) ) ; //Rami : setting the model'sparent id to the id of the flat coordinator who sent // the ini message #ifdef WITH_PCDPP at.parentId( msg.procId() ); #endif // nextChange( Time::Inf ) ; at.initFunction() ; DoneMessage done( msg.time(), Processor::id(), nextChange() , false) ; SingleMsgAdm::Instance().send( done, at.parentId() ) ; lastChange( msg.time() ) ; return *this ; } /******************************************************************* * Function Name: receive * Description: call the externalFunction and send done message ********************************************************************/ /* Processor &Simulator::receive( const ExternalMessage &msg ) { cout << "Simulator::receive(external message) is executing @ " << msg.time() << endl; Atomic &at( static_cast( model() ) ); MASSERT( at.absoluteNext() >= msg.time() ) ; nextChange( at.absoluteNext() - msg.time() ) ; at.externalFunction( msg ) ; DoneMessage done( msg.time(), this->Processor::id(), nextChange() ) ; SingleMsgAdm::Instance().send( done, at.parentId() ) ; lastChange( msg.time() ) ; return *this ; } */ Processor &Simulator::receive(const CollectMessage &msg) { if (SingleCPPWrapper::Instance().getCPPTransferDelays().size() < LOCAL_MESSAGE_COUNT ) { gettimeofday(&SingleCPPWrapper::Instance().getMessageReceiveTime() , (struct timezone*) 0 ) ; SingleCPPWrapper::Instance().addCPPTransferDelay(); } Atomic &at( static_cast( model() ) ); MASSERT(at.absoluteNext() == msg.time() ); at.outputFunction(msg); DoneMessage done( msg.time(), this->Processor::id() , Time::Zero , false); SingleMsgAdm::Instance().send(done , at.parentId()); return *this; } /******************************************************************* * Function Name: receive * Description: call to the OutputFunction and InternalFunction ********************************************************************/ Processor &Simulator::receive( const InternalMessage &msg ) { if (SingleCPPWrapper::Instance().getCPPTransferDelays().size() < LOCAL_MESSAGE_COUNT ) { gettimeofday(&SingleCPPWrapper::Instance().getMessageReceiveTime() , (struct timezone*) 0 ) ; SingleCPPWrapper::Instance().addCPPTransferDelay(); } Atomic &at( static_cast( model() ) ) ; MASSERT (msg.time() >= at.lastChange() && msg.time() <= at.absoluteNext()); if( msg.time() < at.absoluteNext()) { // cerr << "Simulator: going to execute the externalFunction for " // << this->model().description() << " at " << msg.time() << endl; nextChange(at.absoluteNext() - msg.time()); at.externalFunction(externalMsgs); externalMsgs.eraseAll(); } else if (msg.time() == at.absoluteNext() && externalMsgs.size() == 0) { // cerr << "Simulator: going to execute the internalFunction for " // << this->model().description() << " at " << msg.time() << endl; nextChange(Time::Zero); at.internalFunction(msg); } else if (msg.time() == at.absoluteNext() && externalMsgs.size() != 0) { // cerr << "Simulator : going to execute the confluentFunction for " // << this->model().description() << " at " << msg.time() << endl; nextChange(Time::Zero); at.confluentFunction(msg , externalMsgs); externalMsgs.eraseAll(); } lastChange( msg.time() ); DoneMessage done(msg.time() , this->Processor::id(), nextChange() , false) ; SingleMsgAdm::Instance().send( done, at.parentId() ); return *this; /* MASSERT( at.absoluteNext() == msg.time() ) ; nextChange( Time::Zero ) ; at.outputFunction( msg ) ; at.internalFunction( msg ) ; DoneMessage done( msg.time(), this->Processor::id(), nextChange() ) ; SingleMsgAdm::Instance().send( done, at.parentId() ) ; lastChange( msg.time() ) ; return *this ; */ } /******************************************************************* * Function Name: id ********************************************************************/ /* * Processor &Simulator::id( const ProcId &pid ) { this->Processor::id( pid ) ; MASSERT( pmodel() ) ; // pmodel()->id( pid ) ; return *this ; } */