SST  7.0.0
StructuralSimulationToolkit
pymodel.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2017 Sandia Corporation. Under the terms
4 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2017, Sandia Corporation
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 *name, const char *port, const char *latency, bool no_cut) const {graph->addLink(id, name, port, latency, no_cut); }
77 
78  void pushNamePrefix(const char *name);
79  void popNamePrefix(void);
80  char* addNamePrefix(const char *name) const;
81 
82  void setStatisticOutput(const char* Name) { graph->setStatisticOutput(Name); }
83  void addStatisticOutputParameter(const std::string &param, const std::string &value) { graph->addStatisticOutputParameter(param, value); }
84  void setStatisticLoadLevel(uint8_t loadLevel) { graph->setStatisticLoadLevel(loadLevel); }
85 
86  void enableStatisticForComponentName(const std::string &compname, const std::string &statname) const { graph->enableStatisticForComponentName(compname, statname); }
87  void enableStatisticForComponentType(const std::string &comptype, const std::string &statname) const { graph->enableStatisticForComponentType(comptype, statname); }
88 
89  void addStatisticParameterForComponentName(const std::string &compname, const std::string &statname, const std::string &param, const std::string &value) { graph->addStatisticParameterForComponentName(compname, statname, param, value); }
90  void addStatisticParameterForComponentType(const std::string &comptype, const std::string &statname, const std::string &param, const std::string &value) { graph->addStatisticParameterForComponentType(comptype, statname, param, value); }
91 };
92 
93 std::map<std::string,std::string> generateStatisticParameters(PyObject* statParamDict);
94 
95 }
96 }
97 
98 #endif
99 
100 #endif
Output object provides consistant method for outputing data to stdout, stderr and/or sst debug file...
Definition: output.h:54
void setStatisticLoadLevel(uint8_t loadLevel)
Set the statistic system load level.
Definition: configGraph.cc:497
Class to contain SST Simulation Configuration variables.
Definition: config.h:31
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:337
Definition: action.cc:17
void enableStatisticForComponentName(std::string ComponentName, std::string statisticName)
Enable a Statistics assigned to a component.
Definition: configGraph.cc:504
void addStatisticOutputParameter(const std::string &param, const std::string &value)
Add parameter to the statistic output module.
Definition: configGraph.cc:491
void addLink(ComponentId_t comp_id, std::string link_name, std::string port, std::string latency_str, bool no_cut=false)
Add a Link to a Component on a given Port.
Definition: configGraph.cc:564
ComponentId_t addComponent(ComponentId_t id, std::string name, std::string type, float weight, RankInfo rank)
Create a new component with weight and rank.
Definition: configGraph.cc:462
Base class for Model Generation.
Definition: sstmodel.h:22
void setStatisticOutput(const std::string &name)
Set the statistic ouput module.
Definition: configGraph.cc:479
void addStatisticParameterForComponentName(const std::string &ComponentName, const std::string &statisticName, const std::string &param, const std::string &value)
Add Parameters for a Statistic.
Definition: configGraph.cc:534