/******************************************************************* * * DESCRIPTION: class ParallelSimulator * * AUTHOR: Alejandro Troccoli * * EMAIL: mailto://atroccol@dc.uba.ar * * DATE: 07/11/2000 * *******************************************************************/ /** include files **/ #include "psimulat.h" // header #include "atomic.h" // class Atomic #include "pmessage.h" // class InitMessage #include "parsimu.h" #include "JackyDebugStream.h" //jacky-debug-mode /** public functions **/ /******************************************************************* * Function Name: Simulator * Description: constructor ********************************************************************/ ParallelSimulator::ParallelSimulator( Atomic *atomic ) : ParallelProcessor( atomic ) {} void ParallelSimulator::initialize(){ ParallelProcessor::initialize(); ParallelMainSimulator::Instance().debugStream() << "OK" << endl << flush; } /******************************************************************* * Function Name: receive * Description: set the time for the first internal event ********************************************************************/ ParallelProcessor & ParallelSimulator::receive( const InitMessage &msg ) { Atomic &at( static_cast( model() ) ) ; // Redefine the parent of the atomic as the corresponding flat coordinator parentFCId = ParallelMainSimulator::Instance().flatCoordinatorsList[ParallelMainSimulator::Instance().getMachineID()]; nextChange( VTime::Inf ) ; at.initFunction() ; DoneMessage done( msg.time(), ParallelProcessor::id(), nextChange(), false ) ; send( done, parentFCId ) ; lastChange( msg.time() ) ; #ifdef JACKY_MSG_TYPE_BASED_STATE_SAVING //[2006-02-23] skipStateSaving = true; //this causes the TimeWarp to skip state saving after processing this event #ifdef JACKY_DEBUG ostream& jacky_os = JackyDebugStream::Instance().Stream(); jacky_os << "##### Simulator::skipStateSaving = TRUE #####" << endl << flush; #endif //end JACKY_DEBUG #endif //end JACKY_MSG_TYPE_BASED_STATE_SAVING [2006-02-23] return *this ; } /******************************************************************* * Function Name: receive * Description: call the externalFunction and send done message ********************************************************************/ ParallelProcessor & ParallelSimulator::receive( const CollectMessage &msg ) { //CollectMessage does not have to change //next change or last change!!! MASSERT( absoluteNext() == msg.time() ); Atomic &at( static_cast( model() ) ); #ifdef JACKY_DEBUG ostream& jacky_os = JackyDebugStream::Instance().Stream(); jacky_os << "\t [" << ParallelMainSimulator::Instance().getMachineID() << "] Executing OUTPUT function for atomic " << at.description() << " at time " << msg.time() << endl ; #endif at.outputFunction( msg ) ; DoneMessage done( msg.time(), id(), VTime::Zero, false ) ; send( done, parentFCId ) ; #ifdef JACKY_MSG_TYPE_BASED_STATE_SAVING //[2006-02-23] skipStateSaving = true; //this causes the TimeWarp to skip state saving after processing this event #ifdef JACKY_DEBUG jacky_os << "##### Simulator::skipStateSaving = TRUE #####" << endl << flush; #endif //end JACKY_DEBUG #endif //end JACKY_MSG_TYPE_BASED_STATE_SAVING [2006-02-23] return *this ; } /******************************************************************* * Function Name: receive * Description: call the Internal or Confluent function ********************************************************************/ ParallelProcessor & ParallelSimulator::receive( const InternalMessage &msg ) { MASSERT( msg.time() >= lastChange() && msg.time() <= absoluteNext() ); Atomic &at( static_cast( model() ) ) ; if ( msg.time() < absoluteNext() ) { nextChange(absoluteNext() - msg.time()); at.externalFunction( externalMsgs ); externalMsgs.eraseAll(); } else if ( msg.time() == absoluteNext() && externalMsgs.size() == 0 ) { nextChange( VTime::Zero ); at.internalFunction( msg ); } else if ( msg.time() == absoluteNext() && externalMsgs.size() != 0 ) { nextChange( VTime::Zero ); at.confluentFunction( msg, externalMsgs ); externalMsgs.eraseAll(); } lastChange( msg.time() ); DoneMessage done(msg.time(), id(), nextChange(), false); send( done, parentFCId ) ; return *this ; } /******************************************************************* * Function Name: allocateState ********************************************************************/ BasicState* ParallelSimulator::allocateState() { ParallelSimulatorState *state = new ParallelSimulatorState(); state->modelState = (AtomicState*) model().allocateState(); return state; } #if defined(JACKY_INFREQ_STATEMANAGER) && defined(INFREQSTATEMANAGER) //[2006-03-15] inline void ParallelSimulator::recoverProcessorVariables( ){ #ifdef JACKY_DEBUG ostream& jacky_os = JackyDebugStream::Instance().Stream(); jacky_os << endl << "[InfreqStateManager] Simulator::recoverProcessorVariables( ) called *************" << endl << flush; jacky_os << "\tcurrent Bag is: " << endl << flush; jacky_os << externalMsgs << endl << flush; #endif if( externalMsgs.size() > 0 ){ externalMsgs.eraseAll(); //clean the messageBag #ifdef JACKY_DEBUG //cerr << "CF: Cell " << this->id() << " clean Bag!" << endl; jacky_os << endl << "[InfreqStateManager] Bag cleaned!!! ************************************" << endl << flush; #endif } } #endif //end JACKY_INFREQ_STATEMANAGER && INFREQSTATEMANAGER [2006-03-15]