SST  9.0.0
StructuralSimulationToolkit
pymodel.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2019 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2019, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 
15 #ifndef SST_CORE_MODEL_PYTHON
16 #define SST_CORE_MODEL_PYTHON
17 
18 // This only works if we have Python defined from configure, otherwise this is
19 // a compile time error.
20 #ifdef SST_CONFIG_HAVE_PYTHON
21 
22 #include <map>
23 #include <string>
24 #include <sstream>
25 #include <vector>
26 
27 #include <sst/core/model/sstmodel.h>
28 #include <sst/core/config.h>
29 #include <sst/core/rankInfo.h>
30 #include <sst/core/output.h>
31 #include <sst/core/configGraph.h>
32 
33 using namespace SST;
34 
35 namespace SST {
36 namespace Core {
37 
38 class SSTPythonModelDefinition : public SSTModelDescription {
39 
40  public:
41  SSTPythonModelDefinition(const std::string script_file, int verbosity, Config* config, int argc, char **argv);
42  SSTPythonModelDefinition(const std::string script_file, int verbosity, Config* config);
43  virtual ~SSTPythonModelDefinition();
44 
45  ConfigGraph* createConfigGraph() override;
46 
47  protected:
48  void initModel(const std::string script_file, int verbosity, Config* config, int argc, char** argv);
49  std::string scriptName;
50  Output* output;
51  Config* config;
52  ConfigGraph *graph;
53  char *namePrefix;
54  size_t namePrefixLen;
55  std::vector<size_t> nameStack;
56  std::map<std::string, ComponentId_t> compNameMap;
57  ComponentId_t nextComponentId;
58 
59 
60  public: /* Public, but private. Called only from Python functions */
61  Config* getConfig(void) const { return config; }
62  ConfigGraph* getGraph(void) const { return graph; }
63  Output* getOutput() const { return output; }
64  ComponentId_t getNextComponentId() { return nextComponentId++; }
65  ComponentId_t addComponent(const char *name, const char *type) {
66  ComponentId_t id = getNextComponentId();
67  graph->addComponent(id, name, type);
68  compNameMap[std::string(name)] = id;
69  return id;
70  }
71  ComponentId_t findComponentByName(const char *name) const {
72  auto itr = compNameMap.find(name);
73  return ( itr != compNameMap.end() ) ? itr->second : UNSET_COMPONENT_ID;
74  }
75 
76  void addLink(ComponentId_t id, const char *link_name, const char *port, const char *latency, bool no_cut) const {graph->addLink(id, link_name, port, latency, no_cut); }
77  void setLinkNoCut(const char *link_name) const {graph->setLinkNoCut(link_name); }
78 
79  void pushNamePrefix(const char *name);
80  void popNamePrefix(void);
81  char* addNamePrefix(const char *name) const;
82 
83  void setStatisticOutput(const char* Name) { graph->setStatisticOutput(Name); }
84  void addStatisticOutputParameter(const std::string &param, const std::string &value) { graph->addStatisticOutputParameter(param, value); }
85  void setStatisticLoadLevel(uint8_t loadLevel) { graph->setStatisticLoadLevel(loadLevel); }
86 
87  void enableStatisticForComponentName(const std::string &compname, const std::string &statname) const { graph->enableStatisticForComponentName(compname, statname); }
88  void enableStatisticForComponentType(const std::string &comptype, const std::string &statname) const { graph->enableStatisticForComponentType(comptype, statname); }
89 
90  void addStatisticParameterForComponentName(const std::string &compname, const std::string &statname, const std::string &param, const std::string &value) { graph->addStatisticParameterForComponentName(compname, statname, param, value); }
91  void addStatisticParameterForComponentType(const std::string &comptype, const std::string &statname, const std::string &param, const std::string &value) { graph->addStatisticParameterForComponentType(comptype, statname, param, value); }
92 };
93 
94 std::map<std::string,std::string> generateStatisticParameters(PyObject* statParamDict);
95 
96 }
97 }
98 
99 #endif
100 
101 #endif
Output object provides consistent method for outputting data to stdout, stderr and/or sst debug file...
Definition: output.h:54
Class to contain SST Simulation Configuration variables.
Definition: config.h:31
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:298
Base class for Model Generation.
Definition: sstmodel.h:22