00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef SST_CORE_SIMULATION_H
00015 #define SST_CORE_SIMULATION_H
00016
00017 #include "sst/core/sst_types.h"
00018 #include <sst/core/serialization.h>
00019
00020 #include <signal.h>
00021 #include <iostream>
00022
00023 #include "sst/core/output.h"
00024 #include "sst/core/clock.h"
00025 #include "sst/core/oneshot.h"
00026 #include "sst/core/unitAlgebra.h"
00027 #include "sst/core/config.h"
00028 #include <sst/core/statapi/statengine.h>
00029 #include <sst/core/statapi/statoutput.h>
00030 #include <sst/core/statapi/statbase.h>
00031 #include <sst/core/statapi/statnull.h>
00032 #include <sst/core/statapi/stataccumulator.h>
00033 #include <sst/core/statapi/stathistogram.h>
00034 #include <sst/core/statapi/statuniquecount.h>
00035
00036 #include <sst/core/componentInfo.h>
00037
00038
00039
00040
00041
00042 using namespace SST::Statistics;
00043
00044 namespace SST {
00045
00046 #define _SIM_DBG( fmt, args...) __DBG( DBG_SIM, Sim, fmt, ## args )
00047 #define STATALLFLAG "--ALLSTATS--"
00048
00049 class Activity;
00050 class Component;
00051
00052 class ConfigGraph;
00053 class Exit;
00054 class Factory;
00055 class SimulatorHeartbeat;
00056
00057 class Introspector;
00058 class LinkMap;
00059 class Params;
00060 class SyncBase;
00061 class TimeConverter;
00062 class TimeLord;
00063 class TimeVortex;
00064 class UnitAlgebra;
00065 class SharedRegionManager;
00066
00067
00068 typedef std::map<std::string, Introspector* > IntroMap_t;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 class SimulationBase {
00080 public:
00081
00082 Factory* getFactory(void) const { return factory; }
00083
00084 TimeLord* getTimeLord(void) const { return timeLord; }
00085
00086 StatisticOutput* getStatisticsOutput(void) const { return statisticsOutput; }
00087
00088 StatisticProcessingEngine* getStatisticsProcessingEngine(void) const { return statisticsEngine; }
00089
00090 protected:
00091
00092
00093
00094 SimulationBase(Config* config);
00095 SimulationBase() { }
00096 virtual ~SimulationBase();
00097
00098
00099
00100
00101 TimeConverter* minPartToTC(SimTime_t cycles) const;
00102
00103
00104 Factory *factory;
00105
00106 TimeLord *timeLord;
00107
00108 StatisticOutput* statisticsOutput;
00109
00110 StatisticProcessingEngine* statisticsEngine;
00111
00112 private:
00113 SimulationBase(SimulationBase const&);
00114 void operator=(SimulationBase const&);
00115
00116 friend class boost::serialization::access;
00117 template<class Archive>
00118 void serialize(Archive & ar, const unsigned int version);
00119 };
00120
00121
00122
00123
00124
00125 class Simulation : public SimulationBase {
00126 public:
00127 typedef std::map<SimTime_t, Clock*> clockMap_t;
00128 typedef std::map<SimTime_t, OneShot*> oneShotMap_t;
00129 typedef std::vector<std::string> statEnableList_t;
00130 typedef std::vector<Params> statParamsList_t;
00131 typedef std::map<ComponentId_t, statEnableList_t*> statEnableMap_t;
00132 typedef std::map<ComponentId_t, statParamsList_t*> statParamsMap_t;
00133
00134
00135 ~Simulation();
00136
00137
00138
00139
00140
00141
00142 static Simulation *createSimulation(Config *config, int my_rank, int num_ranks);
00143
00144 static Simulation *getSimulation() { return instance; }
00145
00146 static void setSignal(int signal);
00147
00148
00149
00150
00151 void printStatus(bool fullStatus);
00152
00153
00154 int performWireUp( ConfigGraph& graph, int myRank, SimTime_t min_part );
00155
00156
00157 void setStopAtCycle( Config* cfg );
00158
00159 void initialize();
00160
00161 void run();
00162
00163 Output& getSimulationOutput() { return sim_output; };
00164
00165
00166 Config::Mode_t getSimulationMode() const { return runMode; };
00167
00168 SimTime_t getCurrentSimCycle() const;
00169
00170 SimTime_t getEndSimCycle() const;
00171
00172 int getCurrentPriority() const;
00173
00174 UnitAlgebra getElapsedSimTime() const;
00175
00176 UnitAlgebra getFinalSimTime() const;
00177
00178 int getRank() const {return my_rank;}
00179
00180 int getNumRanks() const {return num_ranks;}
00181
00182 TimeConverter* registerClock(std::string freq, Clock::HandlerBase* handler);
00183 TimeConverter* registerClock(const UnitAlgebra& freq, Clock::HandlerBase* handler);
00184
00185 void unregisterClock(TimeConverter *tc, Clock::HandlerBase* handler);
00186
00187
00188
00189 Cycle_t reregisterClock(TimeConverter *tc, Clock::HandlerBase* handler);
00190
00191 Cycle_t getNextClockCycle(TimeConverter* tc);
00192
00193
00194
00195
00196
00197 TimeConverter* registerOneShot(std::string timeDelay, OneShot::HandlerBase* handler);
00198 TimeConverter* registerOneShot(const UnitAlgebra& timeDelay, OneShot::HandlerBase* handler);
00199
00200
00201 void insertActivity(SimTime_t time, Activity* ev);
00202
00203
00204 Exit* getExit() const { return m_exit; }
00205
00206 uint64_t getTimeVortexMaxDepth() const;
00207 uint64_t getTimeVortexCurrentDepth() const;
00208 uint64_t getSyncQueueDataSize() const;
00209
00210
00211 LinkMap* getComponentLinkMap(ComponentId_t id) const {
00212 ComponentInfo* info = compInfoMap.getByID(id);
00213 if ( NULL == info ) {
00214 return NULL;
00215 } else {
00216 return info->getLinkMap();
00217 }
00218 }
00219
00220
00221
00222
00223
00224 const std::vector<std::string>* getComponentAllowedPorts(std::string type);
00225
00226
00227
00228
00229
00230 const ComponentInfoMap& getComponentInfoMap(void) { return compInfoMap; }
00231
00232
00233
00234 Component* getComponent(const std::string &name) const
00235 {
00236 ComponentInfo* i = compInfoMap.getByName(name);
00237 if (NULL != i) {
00238 return i->getComponent();
00239 } else {
00240 printf("Simulation::getComponent() couldn't find component with name = %s\n",
00241 name.c_str());
00242 exit(1);
00243 }
00244 }
00245
00246
00247 Component* getComponent(const ComponentId_t &id) const
00248 {
00249 ComponentInfo* i = compInfoMap.getByID(id);
00250
00251 if ( NULL != i ) {
00252 return i->getComponent();
00253 } else {
00254 printf("Simulation::getComponent() couldn't find component with id = %lu\n", id);
00255 exit(1);
00256 }
00257 }
00258
00259 ComponentInfo* getComponentInfo(const std::string& name) const
00260 {
00261 ComponentInfo* i = compInfoMap.getByName(name);
00262 if (NULL != i) {
00263 return i;
00264 } else {
00265 printf("Simulation::getComponentInfo() couldn't find component with name = %s\n",
00266 name.c_str());
00267 exit(1);
00268 }
00269 }
00270
00271 ComponentInfo* getComponentInfo(const ComponentId_t &id) const
00272 {
00273 ComponentInfo* i = compInfoMap.getByID(id);
00274
00275 if ( NULL != i ) {
00276 return i;
00277 } else {
00278 printf("Simulation::getComponentInfo() couldn't find component with id = %lu\n", id);
00279 exit(1);
00280 }
00281 }
00282
00283 statEnableList_t* getComponentStatisticEnableList(const ComponentId_t &id) const
00284 {
00285 statEnableMap_t::const_iterator i = statisticEnableMap.find(id);
00286 if (i != statisticEnableMap.end()) {
00287 return i->second;
00288 } else {
00289 printf("Simulation::getComponentStatisticEnableList() couldn't find component with id = %lu\n", id);
00290 exit(1);
00291 }
00292 return NULL;
00293 }
00294
00295 statParamsList_t* getComponentStatisticParamsList(const ComponentId_t &id) const
00296 {
00297 statParamsMap_t::const_iterator i = statisticParamsMap.find(id);
00298 if (i != statisticParamsMap.end()) {
00299 return i->second;
00300 } else {
00301 printf("Simulation::getComponentStatisticParamsList() couldn't find component with id = %lu\n", id);
00302 exit(1);
00303 }
00304 return NULL;
00305 }
00306
00307 template <typename T>
00308 Statistic<T>* CreateStatistic(Component* comp, std::string& type, std::string& statName, std::string& statSubId, Params& params)
00309 {
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 if (0 == strcasecmp("sst.nullstatistic", type.c_str())) {
00320 return new NullStatistic<T>(comp, statName, statSubId, params);
00321 }
00322
00323 if (0 == strcasecmp("sst.accumulatorstatistic", type.c_str())) {
00324 return new AccumulatorStatistic<T>(comp, statName, statSubId, params);
00325 }
00326
00327 if (0 == strcasecmp("sst.histogramstatistic", type.c_str())) {
00328 return new HistogramStatistic<T>(comp, statName, statSubId, params);
00329 }
00330
00331 if(0 == strcasecmp("sst.uniquecountstatistic", type.c_str())) {
00332 return new UniqueCountStatistic<T>(comp, statName, statSubId, params);
00333 }
00334
00335
00336 printf("ERROR: Statistic %s is not supported by the SST Core...\n", type.c_str());
00337
00338 return NULL;
00339 }
00340
00341
00342 Introspector* getIntrospector(const std::string &name) const
00343 {
00344 IntroMap_t::const_iterator i = introMap.find(name);
00345 if (i != introMap.end()) {
00346 return i->second;
00347 } else {
00348 printf("Simulation::getIntrospector() couldn't find introspector with name = %s\n",
00349 name.c_str());
00350 exit(1);
00351 }
00352 }
00353
00354
00355
00356
00357
00358 void setOutputDirectory(std::string& outDir) {
00359 output_directory = outDir;
00360 }
00361
00362
00363
00364
00365
00366 std::string& getOutputDirectory() {
00367 return output_directory;
00368 }
00369
00370
00371
00372
00373
00374 void requireEvent(std::string name);
00375
00376
00377
00378
00379
00380 SimTime_t getNextActivityTime();
00381
00382
00383
00384
00385 static SharedRegionManager* getSharedRegionManager() { return sharedRegionManager; }
00386
00387
00388
00389
00390 bool isWireUpFinished() {return wireUpFinished; }
00391
00392 private:
00393 friend class Link;
00394 friend class Action;
00395 friend class Output;
00396
00397 Simulation();
00398 Simulation(Config* config, int my_rank, int num_ranks);
00399 Simulation(Simulation const&);
00400 void operator=(Simulation const&);
00401
00402
00403
00404
00405 void emergencyShutdown(int signal);
00406
00407 Component* createComponent(ComponentId_t id, std::string name,
00408 Params params);
00409 Introspector* createIntrospector(std::string name,
00410 Params params );
00411
00412 TimeVortex* getTimeVortex() const { return timeVortex; }
00413 void endSimulation(void) { endSimCycle = currentSimCycle; endSim = true; }
00414 void endSimulation(SimTime_t end) { endSimCycle = end; endSim = true; }
00415
00416
00417 Config::Mode_t runMode;
00418 TimeVortex* timeVortex;
00419 TimeConverter* minPartTC;
00420 Activity* current_activity;
00421 SyncBase* sync;
00422 ComponentInfoMap compInfoMap;
00423 IntroMap_t introMap;
00424 clockMap_t clockMap;
00425 statEnableMap_t statisticEnableMap;
00426 statParamsMap_t statisticParamsMap;
00427 oneShotMap_t oneShotMap;
00428 SimTime_t currentSimCycle;
00429 SimTime_t endSimCycle;
00430 int currentPriority;
00431 Exit* m_exit;
00432 SimulatorHeartbeat* m_heartbeat;
00433 bool endSim;
00434 int my_rank;
00435 int num_ranks;
00436 int init_msg_count;
00437 unsigned int init_phase;
00438 volatile sig_atomic_t lastRecvdSignal;
00439
00440 Output sim_output;
00441 std::string output_directory;
00442 static SharedRegionManager* sharedRegionManager;
00443 bool wireUpFinished;
00444
00445 static Simulation *instance;
00446
00447 friend class boost::serialization::access;
00448 template<class Archive>
00449 void serialize(Archive & ar, const unsigned int version);
00450
00451 template<class Archive>
00452 friend void save_construct_data(Archive & ar,
00453 const Simulation * t,
00454 const unsigned int file_version)
00455 {
00456 }
00457
00458 template<class Archive>
00459 friend void load_construct_data(Archive & ar,
00460 Simulation * t,
00461 const unsigned int file_version)
00462 {
00463 ::new(t)Simulation();
00464 Simulation::instance = t;
00465 }
00466 };
00467
00468 }
00469
00470 BOOST_CLASS_EXPORT_KEY(SST::SimulationBase)
00471 BOOST_CLASS_EXPORT_KEY(SST::Simulation)
00472
00473 #endif //SST_CORE_SIMULATION_H