• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/simulation.h

00001 // Copyright 2009-2010 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2009-2010, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
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 //#include "sst/core/clock.h"
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 // The Factory and TimeLord objects both should only be associated
00046 // with a simulation object and never created on their own.  To
00047 // accomplish this, create a base class of Simluation which is
00048 // friended by both Factory and TimeLord.  The friendship is not
00049 // inherited by the Simulation class, limiting the exposure of
00050 // internal information to the 20 line object below and it is
00051 // impossible to create either a Factory or a timeLord without a
00052 // simulation object.
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() { } // Don't call - here for serialization
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&); // Don't Implement
00070     void operator=(SimulationBase const&); // Don't implement
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(); // Don't call.  Only rational way to serialize
00141     Simulation(Config* config, int my_rank, int num_ranks);
00142     Simulation(Simulation const&);     // Don't Implement
00143     void operator=(Simulation const&); // Don't implement
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 } // namespace SST
00191 
00192 BOOST_CLASS_EXPORT_KEY(SST::SimulationBase)
00193 BOOST_CLASS_EXPORT_KEY(SST::Simulation)
00194 
00195 #endif

Generated on Fri Oct 22 2010 11:02:13 for SST by  doxygen 1.7.1