next up previous contents
Next: Internal view of the Up: The Internal View of Previous: Additional data defined in

Additional methods defined in TimeWarp

Here is the interface of the TimeWarp class :

template < class State > 
class TimeWarp : public BasicTimeWarp {
public:
  TimeWarp();
  virtual ~TimeWarp();

  void executeSimulation();
  void simulate();
  void saveState();  // Save our current state.
  int inputGcollect(VTime);
  virtual VTime stateGcollect(VTime);
  void outputGcollect(VTime);
  BasicEvent *getEvent();       // gets an event from the input queue

  void sendEvent(BasicEvent *); // put an event on the output queue
  void recvEvent(BasicEvent *); // how to handle incoming messages

  // this calls the application to execute its code for one simulation cycle
  void executeProcess() = 0;

  // the application overrides these two functions, if desired, to
  // contain code to be executed before and after simulation starts
  // and ends.
  void initialize() {};
  void finalize() {};

  // this method is for the LP to query whether or not we are within
  // our time window...
  bool withinTimeWindow();

  // this method allows our time window to be set.
  void setTimeWindow( VTime newWindow ){
    timeWindow = newWindow;
  };

  // this method returns the time of the earliest unexecuted event.
  VTime calculateMin(); 

  // returns this object's current simulation time
  VTime getLVT() const { return state.current->lVT; };

  // data structures for file access
  int numOutFiles;
  int numInFiles;
  FileQueue *outFileQ;
  FileQueue *inFileQ;

  STATE_MANAGER<State> state;

  enum MSGSUPPRESSION { NONE = 0,          // No Message Supression in effect.
		        LAZYCANCEL = 01,    // Lazy Cancellation Suppression.
		        COASTFORWARD = 02,  // Infrequent State Saving
			 	            // Suppression
		        LAZYAGGRCANCEL = 04 // For dynamic cancellation
  };

protected:
  // rollback to the time specified
  virtual void rollback(VTime);

  // Flag to determine when to suppress a message
  int suppressMessage; 

  // Method to determine whether to suppress the message or not 
  virtual bool suppressMessageTest(BasicEvent*);

  virtual bool suppressLazyMessages(BasicEvent*);

  // Queue used for lazy cancellation.
  OutputQueue lazyCancelQ;

  // Should we dispatch a message during lazy cancellation or not? 
  // basically was the comparision a "hit" or a "miss"
  bool lazyCancel(BasicEvent*);
  // Used to terminate the simulation on error - can pass in a string
  // describing the error

private:
  // this defines how far this object can execute into the future.
  VTime timeWindow;

  // increments each time we send an event to produce a unique id for 
  // events (the id, eventID tuple is unique)
  long long eventCounter;

  // handle to this object's LP, to access terminateSimulation
  LogicalProcess *lpHandle;

  // for statistical use only
  int rollbackCount;

  bool timingsNeeded;
  void coastForward(VTime );

  // Invoked during aggressive cancellation
  void cancelMessagesAggressively(const VTime );

  // Invoked during lazy cancellation
  void moveMessagesToLazyQueue(const VTime );

  // Used only during lazy cancellation
  void fillEventInfo(BasicEvent* );

  // Same as sendEvent() but here the event is sent out without performing
  // any checks.
  void sendEventUnconditionally(BasicEvent* );
};

// Since this is a template class,  we need the actual code everywhere we
// have the definitions...
#include "TimeWarp.cc"


next up previous contents
Next: Internal view of the Up: The Internal View of Previous: Additional data defined in
Philip A. Wilsey
1/26/1998