00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef SST_CORE_SIMULATION_H
00014 #define SST_CORE_SIMULATION_H
00015
00016 #include <iostream>
00017
00018 #include "sst/core/sst_types.h"
00019 #include "sst/core/sdl.h"
00020 #include "sst/core/component.h"
00021
00022
00023 namespace SST {
00024
00025 #define _SIM_DBG( fmt, args...) __DBG( DBG_SIM, Sim, fmt, ## args )
00026
00027 class Activity;
00028 class Clock;
00029 class Clock::HandlerBase;
00030 class Config;
00031 class Exit;
00032 class Factory;
00033 class Graph;
00034 class Introspector;
00035 class LinkMap;
00036 class SDL_CompMap;
00037 class Sync;
00038 class TimeConverter;
00039 class TimeLord;
00040 class TimeVortex;
00041
00042 typedef std::map<std::string, Introspector* > IntroMap_t;
00043 typedef std::map<std::string, Component* > CompMap_t;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class SimulationBase {
00054 public:
00055 Factory* getFactory(void) const { return factory; }
00056 TimeLord* getTimeLord(void) const { return timeLord; }
00057
00058 protected:
00059 SimulationBase(Config* config);
00060 SimulationBase() { }
00061 virtual ~SimulationBase();
00062
00063 TimeConverter* minPartToTC(SimTime_t cycles) const;
00064
00065 Factory *factory;
00066 TimeLord *timeLord;
00067
00068 private:
00069 SimulationBase(SimulationBase const&);
00070 void operator=(SimulationBase const&);
00071
00072 friend class boost::serialization::access;
00073 template<class Archive>
00074 void serialize(Archive & ar, const unsigned int version);
00075 };
00076
00077 class Simulation : public SimulationBase {
00078 public:
00079 typedef std::map<SimTime_t, Clock*> clockMap_t;
00080 typedef std::map< unsigned int, Sync* > SyncMap_t;
00081
00082 static Simulation *createSimulation(Config *config, int my_rank, int num_ranks);
00083 static Simulation *getSimulation() { return instance; }
00084 static void printStatus(void);
00085
00086 int WireUp(Graph& graph, SDL_CompMap_t& sdlMap,
00087 int minPart, int myRank);
00088 int performWireUp( Graph& graph, SDL_CompMap_t& sdlMap,
00089 int minPart, int myRank );
00090 void Run();
00091 SimTime_t getCurrentSimCycle() const;
00092 int getRank() const {return my_rank;}
00093 int getNumRanks() const {return num_ranks;}
00094 TimeConverter* registerClock(std::string freq, Clock::HandlerBase* handler);
00095 void unregisterClock(TimeConverter *tc, Clock::HandlerBase* handler);
00096 void insertActivity(SimTime_t time, Activity* ev);
00097 Exit* getExit() const { return m_exit; }
00098
00099 LinkMap* getComponentLinkMap(ComponentId_t id) const {
00100 std::map<ComponentId_t,LinkMap*>::const_iterator i = component_links.find(id);
00101 if (i == component_links.end()) {
00102 return NULL;
00103 } else {
00104 return i->second;
00105 }
00106 }
00107
00108 const CompMap_t& getComponentMap(void) const { return compMap; }
00109
00110 Component*
00111 getComponent(const std::string &name) const
00112 {
00113 CompMap_t::const_iterator i = compMap.find(name);
00114 if (i != compMap.end()) {
00115 return i->second;
00116 } else {
00117 printf("Simulation::getComponent() couldn't find component with name = %s\n",
00118 name.c_str());
00119 exit(1);
00120 }
00121 }
00122
00123 Introspector*
00124 getIntrospector(const std::string &name) const
00125 {
00126 IntroMap_t::const_iterator i = introMap.find(name);
00127 if (i != introMap.end()) {
00128 return i->second;
00129 } else {
00130 printf("Simulation::getIntrospector() couldn't find introspector with name = %s\n",
00131 name.c_str());
00132 exit(1);
00133 }
00134 }
00135
00136 private:
00137 friend class Link;
00138 friend class Action;
00139
00140 Simulation();
00141 Simulation(Config* config, int my_rank, int num_ranks);
00142 Simulation(Simulation const&);
00143 void operator=(Simulation const&);
00144
00145 Component* createComponent(ComponentId_t id, std::string name,
00146 Component::Params_t params);
00147 Introspector* createIntrospector(std::string name,
00148 Component::Params_t params );
00149
00150 TimeVortex* getTimeVortex() const { return timeVortex; }
00151
00152 void endSimulation(void) { endSim = true; }
00153
00154 TimeVortex* timeVortex;
00155 Sync* sync;
00156 CompMap_t compMap;
00157 IntroMap_t introMap;
00158 clockMap_t clockMap;
00159 SimTime_t currentSimCycle;
00160 Exit* m_exit;
00161 bool endSim;
00162 int my_rank;
00163 int num_ranks;
00164
00165 std::map<ComponentId_t,LinkMap*> component_links;
00166
00167 static Simulation *instance;
00168
00169 friend class boost::serialization::access;
00170 template<class Archive>
00171 void serialize(Archive & ar, const unsigned int version);
00172
00173 template<class Archive>
00174 friend void save_construct_data(Archive & ar,
00175 const Simulation * t,
00176 const unsigned int file_version)
00177 {
00178 }
00179
00180 template<class Archive>
00181 friend void load_construct_data(Archive & ar,
00182 Simulation * t,
00183 const unsigned int file_version)
00184 {
00185 ::new(t)Simulation();
00186 Simulation::instance = t;
00187 }
00188 };
00189
00190 }
00191
00192 BOOST_CLASS_EXPORT_KEY(SST::SimulationBase)
00193 BOOST_CLASS_EXPORT_KEY(SST::Simulation)
00194
00195 #endif