SST  7.0.0
StructuralSimulationToolkit
elementinfo.h
1 // Copyright 2009-2017 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2017, Sandia Corporation
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_ELEMENTINFO_H
13 #define SST_CORE_ELEMENTINFO_H
14 
15 #include <sst/core/sst_types.h>
16 #include <sst/core/warnmacros.h>
17 #include <sst/core/params.h>
18 
19 #include <string>
20 #include <vector>
21 
22 #include <sst/core/elibase.h>
23 
24 namespace SST {
25 class Component;
26 class Module;
27 class SubComponent;
28 namespace Partition {
29  class SSTPartitioner;
30 }
31 class RankInfo;
32 class SSTElementPythonModule;
33 
34 /****************************************************
35  Base classes for templated documentation classes
36 *****************************************************/
37 
38 const std::vector<int> SST_ELI_VERSION = {0, 9, 0};
39 
41 
42 public:
43  virtual const std::string getLibrary() = 0;
44  virtual const std::string getDescription() = 0;
45  virtual const std::string getName() = 0;
46  virtual const std::vector<int>& getVersion() = 0;
47  virtual const std::string getCompileFile() = 0;
48  virtual const std::string getCompileDate() = 0;
49 
50  virtual const std::vector<int>& getELICompiledVersion() = 0;
51 
52  std::string getELIVersionString();
53 };
54 
56 
57 protected:
58  Params::KeySet_t allowedKeys;
59 
60  void initialize_allowedKeys();
61 
62 public:
63 
64  virtual const std::vector<ElementInfoParam>& getValidParams() = 0;
65 
66  const Params::KeySet_t& getParamNames() { return allowedKeys; }
67 
68  std::string getParametersString();
69 
70 };
71 
73 
74 protected:
75  std::vector<std::string> portnames;
76  std::vector<std::string> statnames;
77 
78  void initialize_portnames();
79  void initialize_statnames();
80 
81 public:
82 
83  virtual const std::vector<ElementInfoPort2>& getValidPorts() = 0;
84  virtual const std::vector<ElementInfoStatistic>& getValidStats() = 0;
85  virtual const std::vector<ElementInfoSubComponentSlot>& getSubComponentSlots() = 0;
86 
87  const std::vector<std::string>& getPortnames() { return portnames; }
88  const std::vector<std::string>& getStatnames() { return statnames; }
89 
90  std::string getStatisticsString();
91  std::string getPortsString();
92  std::string getSubComponentSlotString();
93 
94 };
95 
96 
98 
99 public:
100 
102 
103  virtual Component* create(ComponentId_t id, Params& params) = 0;
104  virtual uint32_t getCategory() = 0;
105 
106  std::string toString();
107 };
108 
110 
111 public:
112 
113  virtual SubComponent* create(Component* comp, Params& params) = 0;
114  virtual const std::string getInterface() = 0;
115 
116  std::string toString();
117 };
118 
119 
121 
122 protected:
123 
124 public:
125  virtual Module* create(Component* UNUSED(comp), Params& UNUSED(params)) { /* Need to print error */ return NULL; }
126  virtual Module* create(Params& UNUSED(params)) { /* Need to print error */ return NULL; }
127  virtual const std::string getInterface() = 0;
128 
129  std::string toString();
130 };
131 
132 
134 public:
135  virtual Partition::SSTPartitioner* create(RankInfo total_ranks, RankInfo my_rank, int verbosity) = 0;
136 
137  std::string toString();
138 };
139 
141 public:
142  virtual SSTElementPythonModule* create() = 0;
143  const std::string getDescription() { return getLibrary() + " python module"; };
144  const std::string getName() { return getLibrary(); }
145 };
146 
147 
148 class LibraryInfo {
149 public:
150  std::map<std::string,ComponentElementInfo*> components;
151  std::map<std::string,SubComponentElementInfo*> subcomponents;
152  std::map<std::string,ModuleElementInfo*> modules;
153  std::map<std::string,PartitionerElementInfo*> partitioners;
154  PythonModuleElementInfo* python_module;
155 
156  LibraryInfo() :
157  python_module(NULL) {}
158 
159 
160  BaseComponentElementInfo* getComponentOrSubComponent(const std::string &name) {
161  BaseComponentElementInfo *bcei = getComponent(name);
162  if ( !bcei )
163  bcei = getSubComponent(name);
164  return bcei;
165  }
166 
167  ComponentElementInfo* getComponent(const std::string &name) {
168  if ( components.count(name) == 0 ) return NULL;
169  return components[name];
170  }
171 
172  SubComponentElementInfo* getSubComponent(const std::string &name) {
173  if ( subcomponents.count(name) == 0 ) return NULL;
174  return subcomponents[name];
175  }
176 
177  ModuleElementInfo* getModule(const std::string &name) {
178  if ( modules.count(name) == 0 ) return NULL;
179  return modules[name];
180  }
181 
182  PartitionerElementInfo* getPartitioner(const std::string &name) {
183  if ( partitioners.count(name) == 0 ) return NULL;
184  return partitioners[name];
185  }
186 
187  PythonModuleElementInfo* getPythonModule() {
188  return python_module;
189  }
190 
191  std::string toString();
192 };
193 
194 
196 private:
197  // Database
198  static std::map<std::string,LibraryInfo*> libraries;
199 
200  static LibraryInfo* getLibrary(const std::string &library) {
201  if ( libraries.count(library) == 0 ) {
202  libraries[library] = new LibraryInfo;
203  }
204  return libraries[library];
205  }
206 
207 public:
208  static bool addComponent(ComponentElementInfo* comp) {
209  LibraryInfo* library = getLibrary(comp->getLibrary());
210  library->components[comp->getName()] = comp;
211  return true;
212  }
213 
214  static bool addSubComponent(SubComponentElementInfo* comp) {
215  LibraryInfo* library = getLibrary(comp->getLibrary());
216  library->subcomponents[comp->getName()] = comp;
217  return true;
218  }
219 
220  static bool addModule(ModuleElementInfo* comp) {
221  LibraryInfo* library = getLibrary(comp->getLibrary());
222  library->modules[comp->getName()] = comp;
223  return true;
224  }
225 
226  static bool addPartitioner(PartitionerElementInfo* part) {
227  LibraryInfo* library = getLibrary(part->getLibrary());
228  library->partitioners[part->getName()] = part;
229  return true;
230  }
231 
232  static bool addPythonModule(PythonModuleElementInfo* pymod) {
233  LibraryInfo* library = getLibrary(pymod->getLibrary());
234  if ( library->python_module == NULL ) {
235  library->python_module = pymod;
236  }
237  else {
238  // need to fatal
239  }
240  return true;
241  }
242 
243  static std::string toString();
244 
245  static LibraryInfo* getLibraryInfo(const std::string &library) {
246  if ( libraries.count(library) == 0 ) return NULL;
247  return libraries[library];
248  }
249 };
250 
251 
252 
253 /**************************************************************************
254  Templated classes that are used to actually implement the element info
255  documenation in the database.
256 **************************************************************************/
257 
258 
259 /**************************************************************************
260  Classes to support Components
261 **************************************************************************/
262 
263 
264 template <class T>
266 private:
267  static const bool loaded;
268 
269 public:
270 
272  initialize_allowedKeys();
273  initialize_portnames();
274  initialize_statnames();
275  }
276 
277  Component* create(ComponentId_t id, Params& params) {
278  // return new T(id, params);
279  return T::ELI_create(id,params);
280  }
281 
282  static bool isLoaded() { return loaded; }
283  const std::string getLibrary() { return T::ELI_getLibrary(); }
284  const std::string getName() { return T::ELI_getName(); }
285  const std::string getDescription() { return T::ELI_getDescription(); }
286  const std::vector<ElementInfoParam>& getValidParams() { return T::ELI_getParams(); }
287  const std::vector<ElementInfoStatistic>& getValidStats() { return T::ELI_getStatistics(); }
288  const std::vector<ElementInfoPort2>& getValidPorts() { return T::ELI_getPorts(); }
289  const std::vector<ElementInfoSubComponentSlot>& getSubComponentSlots() { return T::ELI_getSubComponentSlots(); }
290  uint32_t getCategory() { return T::ELI_getCategory(); };
291  const std::vector<int>& getELICompiledVersion() { return T::ELI_getELICompiledVersion(); }
292  const std::vector<int>& getVersion() { return T::ELI_getVersion(); }
293  const std::string getCompileFile() { return T::ELI_getCompileFile(); }
294  const std::string getCompileDate() { return T::ELI_getCompileDate(); }
295 };
296 
297 
298 template<class T> const bool ComponentDoc<T>::loaded = ElementLibraryDatabase::addComponent(new ComponentDoc<T>());
299 
300 
301 /**************************************************************************
302  Classes to support SubComponents
303 **************************************************************************/
304 
305 template <class T>
307 private:
308  static const bool loaded;
309 
310 public:
311 
313  initialize_allowedKeys();
314  initialize_portnames();
315  initialize_statnames();
316  }
317 
318  SubComponent* create(Component* comp, Params& params) {
319  // return new T(comp,params);
320  return T::ELI_create(comp,params);
321  }
322 
323  static bool isLoaded() { return loaded; }
324  const std::string getLibrary() { return T::ELI_getLibrary(); }
325  const std::string getName() { return T::ELI_getName(); }
326  const std::string getDescription() { return T::ELI_getDescription(); }
327  const std::vector<ElementInfoParam>& getValidParams() { return T::ELI_getParams(); }
328  const std::vector<ElementInfoStatistic>& getValidStats() { return T::ELI_getStatistics(); }
329  const std::vector<ElementInfoPort2>& getValidPorts() { return T::ELI_getPorts(); }
330  const std::vector<ElementInfoSubComponentSlot>& getSubComponentSlots() { return T::ELI_getSubComponentSlots(); }
331  const std::string getInterface() { return T::ELI_getInterface(); }
332  const std::vector<int>& getELICompiledVersion() { return T::ELI_getELICompiledVersion(); }
333  const std::vector<int>& getVersion() { return T::ELI_getVersion(); }
334  const std::string getCompileFile() { return T::ELI_getCompileFile(); }
335  const std::string getCompileDate() { return T::ELI_getCompileDate(); }
336 };
337 
338 template<class T> const bool SubComponentDoc<T>::loaded = ElementLibraryDatabase::addSubComponent(new SubComponentDoc<T>());
339 
340 
341 /**************************************************************************
342  Classes to support Modules
343  There's some template metaprogramming to check for the two different
344  versions of constructors that can exist.
345 **************************************************************************/
346 
347 template <class T>
348 class ModuleDoc : public ModuleElementInfo {
349 private:
350  static const bool loaded;
351 
352 public:
353 
355  initialize_allowedKeys();
356  }
357 
358  Module* create(Component* comp, Params& params) {
359  return new T(comp,params);
360  }
361 
362  Module* create(Params& params) {
363  return new T(params);
364  }
365 
366  static bool isLoaded() { return loaded; }
367  const std::string getLibrary() { return T::ELI_getLibrary(); }
368  const std::string getName() { return T::ELI_getName(); }
369  const std::string getDescription() { return T::ELI_getDescription(); }
370  const std::vector<ElementInfoParam>& getValidParams() { return T::ELI_getParams(); }
371  const std::string getInterface() { return T::ELI_getInterface(); }
372  const std::vector<int>& getELICompiledVersion() { return T::ELI_getELICompiledVersion(); }
373  const std::vector<int>& getVersion() { return T::ELI_getVersion(); }
374  const std::string getCompileFile() { return T::ELI_getCompileFile(); }
375  const std::string getCompileDate() { return T::ELI_getCompileDate(); }
376 };
377 
378 template <class T>
380 private:
381  static const bool loaded;
382 
383 public:
384 
386  initialize_allowedKeys();
387  }
388 
389  Module* create(Component* comp, Params& params) {
390  return new T(comp,params);
391  }
392 
393  static bool isLoaded() { return loaded; }
394  const std::string getLibrary() { return T::ELI_getLibrary(); }
395  const std::string getName() { return T::ELI_getName(); }
396  const std::string getDescription() { return T::ELI_getDescription(); }
397  const std::vector<ElementInfoParam>& getValidParams() { return T::ELI_getParams(); }
398  const std::string getInterface() { return T::ELI_getInterface(); }
399  const std::vector<int>& getELICompiledVersion() { return T::ELI_getELICompiledVersion(); }
400  const std::vector<int>& getVersion() { return T::ELI_getVersion(); }
401  const std::string getCompileFile() { return T::ELI_getCompileFile(); }
402  const std::string getCompileDate() { return T::ELI_getCompileDate(); }
403 };
404 
405 template <class T>
407 private:
408  static const bool loaded;
409 
410 public:
411 
413  initialize_allowedKeys();
414  }
415 
416  Module* create(Params& params) {
417  return new T(params);
418  }
419 
420  static bool isLoaded() { return loaded; }
421  const std::string getLibrary() { return T::ELI_getLibrary(); }
422  const std::string getName() { return T::ELI_getName(); }
423  const std::string getDescription() { return T::ELI_getDescription(); }
424  const std::vector<ElementInfoParam>& getValidParams() { return T::ELI_getParams(); }
425  const std::string getInterface() { return T::ELI_getInterface(); }
426  const std::vector<int>& getELICompiledVersion() { return T::ELI_getELICompiledVersion(); }
427  const std::vector<int>& getVersion() { return T::ELI_getVersion(); }
428  const std::string getCompileFile() { return T::ELI_getCompileFile(); }
429  const std::string getCompileDate() { return T::ELI_getCompileDate(); }
430 };
431 
432 
433 // These static functions choose between the custom and not custom
434 // create versions by looking for ELI_Custom_Create
435 template<class T>
436 typename std::enable_if<std::is_constructible<T,Component*,Params&>::value &&
437  std::is_constructible<T,Params&>::value, ModuleElementInfo*>::type
438 createModuleDoc() {
439  return new ModuleDoc<T>();
440 }
441 
442 template<class T>
443 typename std::enable_if<std::is_constructible<T,Component*,Params&>::value &&
444  not std::is_constructible<T,Params&>::value, ModuleElementInfo*>::type
445 createModuleDoc() {
446  return new ModuleDocWithComponent<T>();
447 }
448 
449 template<class T>
450 typename std::enable_if<not std::is_constructible<T,Component*,Params&>::value &&
451  std::is_constructible<T,Params&>::value, ModuleElementInfo*>::type
452 createModuleDoc() {
453  return new ModuleDocWithoutComponent<T>();
454 }
455 
456 template<class T> const bool ModuleDoc<T>::loaded = ElementLibraryDatabase::addModule(createModuleDoc<T>());
457 // template<class T> const bool ModuleDoc<T>::loaded = ElementLibraryDatabase::addModule(new ModuleDoc<T>());
458 
459 
460 /**************************************************************************
461  Classes to support partitioners
462 **************************************************************************/
463 
464 template <class T>
466 private:
467  static const bool loaded;
468 
469 public:
470 
471  virtual Partition::SSTPartitioner* create(RankInfo total_ranks, RankInfo my_rank, int verbosity) override {
472  return new T(total_ranks,my_rank,verbosity);
473  }
474 
475  static bool isLoaded() { return loaded; }
476  const std::string getDescription() override { return T::ELI_getDescription(); }
477  const std::string getName() override { return T::ELI_getName(); }
478  const std::string getLibrary() override { return T::ELI_getLibrary(); }
479  const std::vector<int>& getELICompiledVersion() override { return T::ELI_getELICompiledVersion(); }
480  const std::vector<int>& getVersion() override { return T::ELI_getVersion(); }
481  const std::string getCompileFile() override { return T::ELI_getCompileFile(); }
482  const std::string getCompileDate() override { return T::ELI_getCompileDate(); }
483 };
484 
485 template<class T> const bool PartitionerDoc<T>::loaded = ElementLibraryDatabase::addPartitioner(new PartitionerDoc<T>());
486 
487 
488 /**************************************************************************
489  Classes to support element python modules
490 **************************************************************************/
491 template <class T>
493 private:
494  static const bool loaded;
495  // Only need to create one of these
496  static T* instance;
497 
498 public:
499 
500  SSTElementPythonModule* create() {
501  // return new T(getLibrary());
502  if( instance == NULL ) instance = new T(getLibrary());
503  return instance;
504  }
505 
506  static bool isLoaded() { return loaded; }
507  const std::string getLibrary() { return T::ELI_getLibrary(); }
508  const std::vector<int>& getELICompiledVersion() { return T::ELI_getELICompiledVersion(); }
509  const std::vector<int>& getVersion() { return T::ELI_getVersion(); }
510  const std::string getCompileFile() { return T::ELI_getCompileFile(); }
511  const std::string getCompileDate() { return T::ELI_getCompileDate(); }
512 };
513 
514 template<class T> T* PythonModuleDoc<T>::instance = NULL;
515 template<class T> const bool PythonModuleDoc<T>::loaded = ElementLibraryDatabase::addPythonModule(new PythonModuleDoc<T>());
516 
517 /**************************************************************************
518  Macros used by elements to add element documentation
519 **************************************************************************/
520 
521 #define SST_ELI_INSERT_COMPILE_INFO() \
522  static const std::string& ELI_getCompileDate() { \
523  static std::string time = __TIME__; \
524  static std::string date = __DATE__; \
525  static std::string date_time = date + " " + time; \
526  return date_time; \
527  } \
528  static const std::string ELI_getCompileFile() { \
529  return __FILE__; \
530  } \
531  static const std::vector<int>& ELI_getELICompiledVersion() { \
532  static const std::vector<int> var(SST_ELI_VERSION); \
533  return var; \
534  }
535 
536 
537 #define SST_ELI_REGISTER_COMPONENT_CUSTOM_CREATE(cls,lib,name,desc,cat) \
538  friend class ComponentDoc<cls>; \
539  bool ELI_isLoaded() { \
540  return ComponentDoc<cls>::isLoaded(); \
541  } \
542  static const std::string ELI_getLibrary() { \
543  return lib; \
544  } \
545  static const std::string ELI_getName() { \
546  return name; \
547  } \
548  static const std::string ELI_getDescription() { \
549  return desc; \
550  } \
551  static const uint32_t ELI_getCategory() { \
552  return cat; \
553  } \
554  SST_ELI_INSERT_COMPILE_INFO()
555 
556 #define SST_ELI_REGISTER_COMPONENT(cls,lib,name,desc,cat) \
557  static Component* ELI_create(ComponentId_t id, Params& params) { \
558  return new cls(id,params); \
559  } \
560  SST_ELI_REGISTER_COMPONENT_CUSTOM_CREATE(cls,lib,name,desc,cat)
561 
562 
563 #define SST_ELI_DOCUMENT_VERSION(major,minor,tertiary) \
564  static const std::vector<int>& ELI_getVersion() { \
565  static std::vector<int> var = { major, minor, tertiary } ; \
566  return var; \
567  }
568 
569 #define SST_ELI_DOCUMENT_PARAMS(...) \
570  static const std::vector<ElementInfoParam>& ELI_getParams() { \
571  static std::vector<ElementInfoParam> var = { __VA_ARGS__ } ; \
572  return var; \
573  }
574 
575 
576 #define SST_ELI_DOCUMENT_STATISTICS(...) \
577  static const std::vector<ElementInfoStatistic>& ELI_getStatistics() { \
578  static std::vector<ElementInfoStatistic> var = { __VA_ARGS__ } ; \
579  return var; \
580  }
581 
582 
583 #define SST_ELI_DOCUMENT_PORTS(...) \
584  static const std::vector<ElementInfoPort2>& ELI_getPorts() { \
585  static std::vector<ElementInfoPort2> var = { __VA_ARGS__ } ; \
586  return var; \
587  }
588 
589 #define SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(...) \
590  static const std::vector<ElementInfoSubComponentSlot>& ELI_getSubComponentSlots() { \
591  static std::vector<ElementInfoSubComponentSlot> var = { __VA_ARGS__ } ; \
592  return var; \
593  }
594 
595 
596 #define SST_ELI_REGISTER_SUBCOMPONENT_CUSTOM_CREATE(cls,lib,name,desc,interface) \
597  friend class SubComponentDoc<cls>; \
598  bool ELI_isLoaded() { \
599  return SubComponentDoc<cls>::isLoaded(); \
600  } \
601  static const std::string ELI_getLibrary() { \
602  return lib; \
603  } \
604  static const std::string ELI_getName() { \
605  return name; \
606  } \
607  static const std::string ELI_getDescription() { \
608  return desc; \
609  } \
610  static const std::string ELI_getInterface() { \
611  return interface; \
612  } \
613  SST_ELI_INSERT_COMPILE_INFO()
614 
615 #define SST_ELI_REGISTER_SUBCOMPONENT(cls,lib,name,desc,interface) \
616  static SubComponent* ELI_create(Component* comp, Params& params) { \
617  return new cls(comp,params); \
618  } \
619  SST_ELI_REGISTER_SUBCOMPONENT_CUSTOM_CREATE(cls,lib,name,desc,interface)
620 
621 
622 #define SST_ELI_REGISTER_MODULE(cls,lib,name,desc,interface) \
623  friend class ModuleDoc<cls>; \
624  bool ELI_isLoaded() { \
625  return ModuleDoc<cls>::isLoaded(); \
626  } \
627  static const std::string ELI_getLibrary() { \
628  return lib; \
629  } \
630  static const std::string ELI_getName() { \
631  return name; \
632  } \
633  static const std::string ELI_getDescription() { \
634  return desc; \
635  } \
636  static const std::string ELI_getInterface() { \
637  return interface; \
638  } \
639  SST_ELI_INSERT_COMPILE_INFO()
640 
641 
642 
643 #define SST_ELI_REGISTER_PARTITIONER(cls,lib,name,desc) \
644  friend class PartitionerDoc<cls>; \
645  bool ELI_isLoaded() { \
646  return PartitionerDoc<cls>::isLoaded(); \
647  } \
648  static const std::string ELI_getLibrary() { \
649  return lib; \
650  } \
651  static const std::string ELI_getName() { \
652  return name; \
653  } \
654  static const std::string ELI_getDescription() { \
655  return desc; \
656  } \
657  SST_ELI_INSERT_COMPILE_INFO()
658 
659 
660 
661 #define SST_ELI_REGISTER_PYTHON_MODULE(cls,lib) \
662  friend class PythonModuleDoc<cls>; \
663  bool ELI_isLoaded() { \
664  return PythonModuleDoc<cls>::isLoaded(); \
665  } \
666  static const std::string ELI_getLibrary() { \
667  return lib; \
668  } \
669  SST_ELI_INSERT_COMPILE_INFO()
670 
671 
672 } //namespace SST
673 
674 #endif // SST_CORE_ELEMENTINFO_H
Definition: elementinfo.h:148
Definition: elementinfo.h:195
Definition: elementinfo.h:40
Main component object for the simulation.
Definition: component.h:32
Definition: elementinfo.h:120
Definition: action.cc:17
Definition: elementinfo.h:379
Definition: elementinfo.h:465
Definition: elementinfo.h:97
Module is a tag class used with the loadModule function.
Definition: module.h:20
Definition: elementinfo.h:265
Definition: elementinfo.h:140
Definition: elementinfo.h:133
Definition: elementinfo.h:306
Definition: rankInfo.h:21
Definition: elementinfo.h:109
Definition: elementinfo.h:72
Base class for Partitioning graphs.
Definition: sstpart.h:31
Definition: elementinfo.h:55
Parameter store.
Definition: params.h:45
Definition: elementinfo.h:492
Definition: elementinfo.h:348
Base class for python modules in element libraries.
Definition: element_python.h:26
std::set< key_type, KeyCompare > KeySet_t
Definition: params.h:94
Definition: elementinfo.h:406
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition: subcomponent.h:29