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