/******************************************************************* * Declaration: This class is partially based on Glinsky's version that * can be found in the "oldsource" directory. * * DESCRIPTION: class ParallelFlatCoordinator * * AUTHOR: Qi (Jacky) Liu * * EMAIL: mailto://liuqi@sce.carleton.ca * * DATE: August, 2005 * * NOTE: The flat coordinator will NOT hold the information to determine the type of the next msg. * It will NOT hold an EventList and stopTime. The external events and stopTime are controlled * by the NC! * *******************************************************************/ #ifndef __PFCOORD_H #define __PFCOORD_H #include #include // Template list #include "pfcoordmodel.h" // class FlatCoordinatorModel #include "pprocess.h" // baseclass ParallelProcessor #include "pFCoordState.h" // class ParallelFlatCoordinatorState #include "pprocadm.h" // class ParallelProcessorAdmin #include "pmodeladm.h" // ModelDB #include "JackyDebugStream.h" //jacky-debug-mode /** forward declarations **/ class Coupled ; class ParallelMainSimulator ; class Port ; class VTime ; class ParallelFlatCoordinator : public ParallelProcessor { public: //Functions that are required by Warped void initialize(); BasicState* allocateState(); /*Six receive functions*/ //The following message is not used in the PCD++ //ParallelProcessor &receive( const OutputSyncMessage &); //this function checks the X msg to see whether the destination model is a local simulator, if so, the FC //puts the msg in the MessageBag; otherwise, the FC will raise error (it got a wrong msg!) //Note (Nov. 23, 2005) : // We will set skipStateSaving = true in this function to skip the state saving after processing // this (X) message. ParallelProcessor &receive( const BasicExternalMessage * ) ; //this function forwards the I msg to all local simulators, and sets doneCount ParallelProcessor &receive( const InitMessage & ) ; //this function decreases the doneCount, updates dependants' absoluteNext() time, and sends a D msg to the NC ParallelProcessor &receive( const DoneMessage & ) ; //this function processes the * msg received from the NC, it calls sortExternalMessage() to send X msg in the //FC's MessageBag to local simulators, and sends * msg to those local simulators that are either imminent or //have just received X msgs to trigger the Internal/External/Confluence function in the atomic model ParallelProcessor &receive( const InternalMessage & ) ; //this function processes the @ msg received from the NC, it finds out the imminent local simulators, and forwards //the @ msg to them, sets the synchronizeList and doneCount accordingly ParallelProcessor &receive( const CollectMessage & ); //this function processes the Y msg received from local dependants. It finds out whether the Y msg should be //output to the environment, if so, the Y msg is forwarded to the NC; it also finds out whether the Y msg is //sending to a local simulator, in this case, it simply translates the Y msg to an X msg and sends it to the //destination local simulator; If the Y msg is sending to a remote simulator, the FC translates it to an X msg //and forwards the X msg to the NC ParallelProcessor &receive( const BasicOutputMessage *); const string description() const ; //shortcut to access the dependants defined in the ParallelFlatCoordinatorState ParallelFlatCoordinatorState::DependantList &dependants() const; #if defined(JACKY_INFREQ_STATEMANAGER) && defined(INFREQSTATEMANAGER) //[2006-03-15] ---------------------------- ParallelFlatCoordinatorState::FCBagReference &getFCBagRef(); //get the fcbagref multimap in the state void printFCBagRef( ostream &out ); //print out the fcbagref in the state //function to recover the FC's MessageBag based on fcbagref just before coast forward operations virtual void recoverProcessorVariables(); #endif //[2006-03-15] ------------------------------------------------------------------------------------------- protected: //Note: this variable is moved into the ParallelFlatCoordinatorState, Oct. 19, 2005 //the set is used to record the procId of local simulators that need to do an Internal/External/Confluence transition //typedef set ProcSet; //ProcSet synchronizeList; //function to retrieve the synchronizeList defined in the state, Oct. 19, 2005 ParallelFlatCoordinatorState::ProcSet &getSynchronizeList() const; ProcId parentNCId; // the procId of the local NC //function to manipulate the doneCount const int doneCount() const; ParallelFlatCoordinator &doneCount( int ); //function to calculate the new nextChange() time for this FC VTime calculateNextChange(const VTime& time) const; //function to analyze the X msg in the bag. Used by receive(const InternalMessage &) ParallelFlatCoordinator& sortExternalMessage( const BasicExternalMessage & ); //function to analyze the Y msgs. Used by receive(const BasicOutputMessage *) ParallelFlatCoordinator& sortOutputMessage( const BasicOutputMessage & ); //Checks if a rollback has taken place and cleans local variables. //This is a virtual function defined in ParallelProcessor, we override it //here to clean our specific local variables //bool rollbackCheck(const VTime& currentTime); //Oct. 19, 2005 private: friend class ParallelProcessorAdmin ; ParallelFlatCoordinator( FlatCoordinatorModel*) ; // Default constructor //function to add local simulators as dependants of this FC ParallelFlatCoordinator &addLocalDependants() ; //Note: this variable is moved into the ParallelFlatCoordinatorState, Oct. 19, 2005 //this is the local InfluenceList holding ports on Local atomic models (the corresponding simulators are dependants //of this FC). This will be filled by function findLocalInfluenceList(const Port&), and Must be cleared in function //sortExternalMessage() //InfluenceList localInfluList; //list //function to retrieve the localInfluList defined in the state, Oct. 19, 2005 InfluenceList &getLocalInfluList() const; //function to find all receiving port on models that have local simulators ParallelFlatCoordinator& findLocalInfluenceList(const Port&); //function to test whether the specified port will eventually connect to an output port of the TOP model bool isSendingToEnvironment(const Port&); //function to test whether the specified port will eventually connect to remote simulators on other machine bool isSendingToRemoteSimulator(const Port&); //int donecount; //moved into the ParallelFlatCoordinatorState, Oct. 19, 2005 #ifdef JACKY_DEBUG void printLocalDependants(ostream& out); //print the local dependants for debugging #endif }; // class ParallelFlatCoordinator inline const string ParallelFlatCoordinator::description() const { return "ParallelFlatCoordinator" ; } inline const int ParallelFlatCoordinator::doneCount() const{ //return donecount; // Oct. 19, 2005 //Jacky: new version (puting donecount into the state) return ((ParallelFlatCoordinatorState *)state->current)->donecount; } inline ParallelFlatCoordinator &ParallelFlatCoordinator::doneCount( int d ){ //donecount = d; // Oct. 19, 2005 //Jacky: new version (puting donecount into the state) ((ParallelFlatCoordinatorState *)state->current)->donecount = d; return *this; } inline ParallelFlatCoordinatorState::DependantList& ParallelFlatCoordinator::dependants() const { return *((ParallelFlatCoordinatorState *)state->current)->dependants; } //function to retrieve the localInfluList defined in the state, Oct. 19, 2005 inline InfluenceList& ParallelFlatCoordinator::getLocalInfluList() const { return ((ParallelFlatCoordinatorState *)state->current)->localInfluList; } //function to retrieve the synchronizeList defined in the state, Oct. 19, 2005 inline ParallelFlatCoordinatorState::ProcSet& ParallelFlatCoordinator::getSynchronizeList() const { return ((ParallelFlatCoordinatorState *)state->current)->synchronizeList; } #if defined(JACKY_INFREQ_STATEMANAGER) && defined(INFREQSTATEMANAGER) //[2006-03-15] ---------------------------- inline ParallelFlatCoordinatorState::FCBagReference& ParallelFlatCoordinator::getFCBagRef(){ return ((ParallelFlatCoordinatorState *)state->current)->fcbagref; } #endif //end JACKY_INFREQ_STATEMANAGER && INFREQSTATEMANAGER //[2006-03-15] ------------------------------------- #endif //__FLATCOORDINATOR_H