00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef SST_CORE_CONFIGGRAPH_H
00015 #define SST_CORE_CONFIGGRAPH_H
00016
00017 #include "sst/core/sst_types.h"
00018 #include <sst/core/serialization.h>
00019
00020 #include <vector>
00021 #include <map>
00022 #include <set>
00023
00024 #include "sst/core/sparseVectorMap.h"
00025 #include "sst/core/params.h"
00026 #include "sst/core/statapi/statoutput.h"
00027
00028
00029
00030 using namespace SST::Statistics;
00031
00032 namespace SST {
00033
00034 class Simulation;
00035
00036 class Config;
00037
00038 typedef SparseVectorMap<ComponentId_t> ComponentIdMap_t;
00039 typedef std::vector<LinkId_t> LinkIdMap_t;
00040
00041
00042 class ConfigLink {
00043 public:
00044 LinkId_t id;
00045 std::string name;
00046 ComponentId_t component[2];
00047 std::string port[2];
00048 SimTime_t latency[2];
00049 int current_ref;
00050 bool no_cut;
00051
00052
00053 inline LinkId_t key() const { return id; }
00054
00055
00056 SimTime_t getMinLatency() const {
00057 if ( latency[0] < latency[1] ) return latency[0];
00058 return latency[1];
00059 }
00060
00061
00062 void print(std::ostream &os) const {
00063 os << "Link " << name << " (id = " << id << ")" << std::endl;
00064 os << " component[0] = " << component[0] << std::endl;
00065 os << " port[0] = " << port[0] << std::endl;
00066 os << " latency[0] = " << latency[0] << std::endl;
00067 os << " component[1] = " << component[1] << std::endl;
00068 os << " port[1] = " << port[1] << std::endl;
00069 os << " latency[1] = " << latency[1] << std::endl;
00070 }
00071
00072
00073 ConfigLink() {}
00074 private:
00075 friend class ConfigGraph;
00076 ConfigLink(LinkId_t id) :
00077 id(id),
00078 no_cut(false)
00079 {
00080 current_ref = 0;
00081
00082
00083 component[0] = ULONG_MAX;
00084 component[1] = ULONG_MAX;
00085 }
00086
00087 ConfigLink(LinkId_t id, const std::string &n) :
00088 id(id),
00089 no_cut(false)
00090 {
00091 current_ref = 0;
00092 name = n;
00093
00094
00095 component[0] = ULONG_MAX;
00096 component[1] = ULONG_MAX;
00097 }
00098
00099
00100
00101 friend class boost::serialization::access;
00102 template<class Archive>
00103 void
00104 serialize(Archive & ar, const unsigned int version )
00105 {
00106 ar & BOOST_SERIALIZATION_NVP(id);
00107 ar & BOOST_SERIALIZATION_NVP(name);
00108 ar & BOOST_SERIALIZATION_NVP(component);
00109 ar & BOOST_SERIALIZATION_NVP(port);
00110 ar & BOOST_SERIALIZATION_NVP(latency);
00111 ar & BOOST_SERIALIZATION_NVP(current_ref);
00112 }
00113
00114
00115 };
00116
00117 typedef SparseVectorMap<LinkId_t,ConfigLink> ConfigLinkMap_t;
00118
00119
00120 class ConfigComponent {
00121 public:
00122 ComponentId_t id;
00123 std::string name;
00124 std::string type;
00125 float weight;
00126 int rank;
00127 std::vector<LinkId_t> links;
00128 Params params;
00129 bool isIntrospector;
00130 std::vector<std::string> enabledStatistics;
00131 std::vector<Params> enabledStatParams;
00132
00133 inline const ComponentId_t& key()const { return id; }
00134
00135
00136 void print(std::ostream &os) const;
00137
00138 ConfigComponent cloneWithoutLinks() const;
00139 ConfigComponent cloneWithoutLinksOrParams() const;
00140
00141 ~ConfigComponent() {}
00142 private:
00143
00144 friend class ConfigGraph;
00145
00146 ConfigComponent(ComponentId_t id, std::string name, std::string type, float weight, int rank, bool isIntrospector) :
00147 id(id),
00148 name(name),
00149 type(type),
00150 weight(weight),
00151 rank(rank),
00152 isIntrospector(isIntrospector)
00153 { }
00154
00155 ConfigComponent() {}
00156
00157 friend class boost::serialization::access;
00158 template<class Archive>
00159 void
00160 serialize(Archive & ar, const unsigned int version )
00161 {
00162 ar & BOOST_SERIALIZATION_NVP(id);
00163 ar & BOOST_SERIALIZATION_NVP(name);
00164 ar & BOOST_SERIALIZATION_NVP(type);
00165 ar & BOOST_SERIALIZATION_NVP(weight);
00166 ar & BOOST_SERIALIZATION_NVP(rank);
00167 ar & BOOST_SERIALIZATION_NVP(links);
00168 ar & BOOST_SERIALIZATION_NVP(params);
00169 ar & BOOST_SERIALIZATION_NVP(isIntrospector);
00170 ar & BOOST_SERIALIZATION_NVP(enabledStatistics);
00171 ar & BOOST_SERIALIZATION_NVP(enabledStatParams);
00172 }
00173
00174 };
00175
00176
00177
00178
00179
00180
00181 typedef SparseVectorMap<ComponentId_t,ConfigComponent> ConfigComponentMap_t;
00182
00183 typedef std::map<std::string,Params*> ParamsMap_t;
00184
00185 typedef std::map<std::string,std::string> VariableMap_t;
00186
00187 class PartitionGraph;
00188
00189
00190
00191
00192 class ConfigGraph {
00193 public:
00194
00195 void print(std::ostream &os) const {
00196 os << "Printing graph" << std::endl;
00197 for (ConfigComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
00198 i->print(os);
00199 }
00200 }
00201
00202 ConfigGraph() {
00203 links.clear();
00204 comps.clear();
00205 nextCompID = 0;
00206
00207 statOutputName = STATISTICSDEFAULTOUTPUTNAME;
00208 statLoadLevel = STATISTICSDEFAULTLOADLEVEL;
00209 }
00210
00211 size_t getNumComponents() { return comps.data.size(); }
00212
00213
00214 void setComponentRanks(int rank);
00215
00216 bool containsComponentInRank(int rank);
00217
00218 bool checkRanks(int ranks);
00219
00220
00221
00222
00223 ComponentId_t addComponent(std::string name, std::string type, float weight, int rank);
00224
00225 ComponentId_t addComponent(std::string name, std::string type);
00226
00227
00228 void setComponentRank(ComponentId_t comp_id, int rank);
00229
00230 void setComponentWeight(ComponentId_t comp_id, float weight);
00231
00232
00233 void addParams(ComponentId_t comp_id, Params& p);
00234
00235 void addParameter(ComponentId_t comp_id, std::string key, std::string value, bool overwrite = false);
00236
00237
00238 void setStatisticOutput(const char* name);
00239
00240
00241 void addStatisticOutputParameter(const char* param, const char* value);
00242
00243
00244 void setStatisticOutputParams(Params& p);
00245
00246
00247 void setStatisticLoadLevel(uint8_t loadLevel);
00248
00249
00250 void enableComponentStatistic(ComponentId_t comp_id, std::string statisticName);
00251 void enableStatisticForComponentName(std::string ComponentName, std::string statisticName);
00252 void enableStatisticForComponentType(std::string ComponentType, std::string statisticName);
00253
00254
00255 void addComponentStatisticParameter(ComponentId_t comp_id, std::string statisticName, const char* param, const char* value);
00256 void addStatisticParameterForComponentName(std::string ComponentName, std::string statisticName, const char* param, const char* value);
00257 void addStatisticParameterForComponentType(std::string ComponentType, std::string statisticName, const char* param, const char* value);
00258
00259 std::string& getStatOutput() {return statOutputName;}
00260 Params& getStatOutputParams() {return statOutputParams;}
00261 long getStatLoadLevel() {return statLoadLevel;}
00262
00263
00264 void addLink(ComponentId_t comp_id, std::string link_name, std::string port, std::string latency_str, bool no_cut = false);
00265
00266
00267 ComponentId_t addIntrospector(std::string name, std::string type);
00268
00269
00270 bool checkForStructuralErrors();
00271
00272
00273
00274 ConfigComponentMap_t& getComponentMap() {
00275 return comps;
00276 }
00277
00278 ConfigLinkMap_t& getLinkMap() {
00279 return links;
00280 }
00281
00282 ConfigGraph* getSubGraph(int start_rank, int end_rank);
00283 ConfigGraph* getSubGraph(const std::set<int>& rank_set);
00284
00285 PartitionGraph* getPartitionGraph();
00286 PartitionGraph* getCollapsedPartitionGraph();
00287 void annotateRanks(PartitionGraph* graph);
00288 void getConnectedNoCutComps(ComponentId_t start, ComponentIdMap_t& group);
00289
00290 private:
00291 friend class Simulation;
00292 friend class SSTSDLModelDefinition;
00293
00294 ConfigLinkMap_t links;
00295 ConfigComponentMap_t comps;
00296
00297
00298 std::map<std::string,LinkId_t> link_names;
00299
00300 ComponentId_t nextCompID;
00301
00302 std::string statOutputName;
00303 Params statOutputParams;
00304 uint8_t statLoadLevel;
00305
00306 friend class boost::serialization::access;
00307 template<class Archive>
00308 void
00309 serialize(Archive & ar, const unsigned int version )
00310 {
00311
00312 ar & BOOST_SERIALIZATION_NVP(links);
00313
00314 ar & BOOST_SERIALIZATION_NVP(comps);
00315
00316 ar & BOOST_SERIALIZATION_NVP(statOutputName);
00317 ar & BOOST_SERIALIZATION_NVP(statOutputParams);
00318 ar & BOOST_SERIALIZATION_NVP(statLoadLevel);
00319 }
00320
00321
00322 };
00323
00324
00325 class PartitionComponent {
00326 public:
00327 ComponentId_t id;
00328 float weight;
00329 int rank;
00330 LinkIdMap_t links;
00331
00332 ComponentIdMap_t group;
00333
00334 PartitionComponent(const ConfigComponent& cc) {
00335 id = cc.id;
00336 weight = cc.weight;
00337 rank = cc.rank;
00338 }
00339
00340 PartitionComponent(LinkId_t id) :
00341 id(id),
00342 weight(0),
00343 rank(-1)
00344 {}
00345
00346
00347 void print(std::ostream &os, const PartitionGraph* graph) const;
00348
00349 inline const ComponentId_t key() const { return id; }
00350
00351 };
00352
00353 class PartitionLink {
00354 public:
00355 LinkId_t id;
00356 ComponentId_t component[2];
00357 SimTime_t latency[2];
00358 bool no_cut;
00359
00360 PartitionLink(const ConfigLink& cl) {
00361 id = cl.id;
00362 component[0] = cl.component[0];
00363 component[1] = cl.component[1];
00364 latency[0] = cl.latency[0];
00365 latency[1] = cl.latency[1];
00366 no_cut = cl.no_cut;
00367 }
00368
00369 inline const LinkId_t key() const { return id; }
00370
00371
00372 SimTime_t getMinLatency() const {
00373 if ( latency[0] < latency[1] ) return latency[0];
00374 return latency[1]; }
00375
00376
00377 void print(std::ostream &os) const {
00378 os << " Link " << id << std::endl;
00379 os << " component[0] = " << component[0] << std::endl;
00380 os << " latency[0] = " << latency[0] << std::endl;
00381 os << " component[1] = " << component[1] << std::endl;
00382 os << " latency[1] = " << latency[1] << std::endl;
00383 }
00384 };
00385
00386 typedef SparseVectorMap<ComponentId_t,PartitionComponent> PartitionComponentMap_t;
00387 typedef SparseVectorMap<LinkId_t,PartitionLink> PartitionLinkMap_t;
00388
00389 class PartitionGraph {
00390 private:
00391 PartitionComponentMap_t comps;
00392 PartitionLinkMap_t links;
00393
00394 public:
00395
00396 void print(std::ostream &os) const {
00397 os << "Printing graph" << std::endl;
00398 for (PartitionComponentMap_t::const_iterator i = comps.begin() ; i != comps.end() ; ++i) {
00399 i->print(os,this);
00400 }
00401 }
00402
00403 PartitionComponentMap_t& getComponentMap() {
00404 return comps;
00405 }
00406 PartitionLinkMap_t& getLinkMap() {
00407 return links;
00408 }
00409
00410 const PartitionLink& getLink(LinkId_t id) const {
00411 return links[id];
00412 }
00413
00414 size_t getNumComponents() { return comps.size(); }
00415
00416 };
00417
00418 }
00419
00420 #endif // SST_CORE_CONFIGGRAPH_H