SST  6.0.0
StructuralSimulationToolkit
pymodel.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2016 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-2016, 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 
32 using namespace SST;
33 
34 namespace SST {
35 
36 class SSTPythonModelDefinition : public SSTModelDescription {
37 
38  public:
39  SSTPythonModelDefinition(const std::string script_file, int verbosity, Config* config, int argc, char **argv);
40  SSTPythonModelDefinition(const std::string script_file, int verbosity, Config* config);
41  virtual ~SSTPythonModelDefinition();
42 
43  ConfigGraph* createConfigGraph();
44 
45  protected:
46  void initModel(const std::string script_file, int verbosity, Config* config, int argc, char** argv);
47  std::string scriptName;
48  Output* output;
49  Config* config;
50  ConfigGraph *graph;
51  std::map<std::string, std::string> cfgParams;
52  char *namePrefix;
53  size_t namePrefixLen;
54  std::vector<size_t> nameStack;
55  std::map<std::string, ComponentId_t> compNameMap;
56 
57  public:
58  std::vector<std::string> statParamKeyArray;
59  std::vector<std::string> statParamValueArray;
60 
61  public: /* Public, but private. Called only from Python functions */
62  Config* getConfig(void) const { return config; }
63  std::map<std::string, std::string>& getParams(void) { return cfgParams; }
64  //ConfigGraph* getConfigGraph(void) const { return graph; }
65  std::string getConfigString(void) const;
66  Output* getOutput() const { return output; }
67  ComponentId_t addComponent(const char *name, const char *type) {
68  ComponentId_t id = graph->addComponent(name, type);
69  compNameMap[std::string(name)] = id;
70  return id;
71  }
72  ComponentId_t findComponentByName(const char *name) const {
73  auto itr = compNameMap.find(name);
74  return ( itr != compNameMap.end() ) ? itr->second : UNSET_COMPONENT_ID;
75  }
76  void addParameter(ComponentId_t id, const char *name, const char *value) const { graph->addParameter(id, name, value, true); }
77 
78  void setComponentRank(ComponentId_t id, uint32_t rank, uint32_t thread) const { graph->setComponentRank(id, RankInfo(rank, thread)); }
79  void setComponentWeight(ComponentId_t id, float weight) const { graph->setComponentWeight(id, weight); }
80  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); }
81 
82  void pushNamePrefix(const char *name);
83  void popNamePrefix(void);
84  char* addNamePrefix(const char *name) const;
85 
86  void setStatisticOutput(const char* Name) { graph->setStatisticOutput(Name); }
87  void addStatisticOutputParameter(const char* param, const char* value) { graph->addStatisticOutputParameter(param, value); }
88  void setStatisticLoadLevel(uint8_t loadLevel) { graph->setStatisticLoadLevel(loadLevel); }
89 
90  void enableComponentStatistic(ComponentId_t compid, const char* statname) const { graph->enableComponentStatistic(compid, statname); }
91  void enableStatisticForComponentName(const char* compname, const char* statname) const { graph->enableStatisticForComponentName(compname, statname); }
92  void enableStatisticForComponentType(const char* comptype, const char* statname) const { graph->enableStatisticForComponentType(comptype, statname); }
93 
94  void addComponentStatisticParameter(ComponentId_t compid, const char* statname, const char* param, const char* value) { graph->addComponentStatisticParameter(compid, statname, param, value); }
95  void addStatisticParameterForComponentName(const char* compname, const char* statname, const char* param, const char* value) { graph->addStatisticParameterForComponentName(compname, statname, param, value); }
96  void addStatisticParameterForComponentType(const char* comptype, const char* statname, const char* param, const char* value) { graph->addStatisticParameterForComponentType(comptype, statname, param, value); }
97 };
98 
99 }
100 
101 #endif
102 
103 #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:312
Class to contain SST Simulation Configuration variables.
Definition: config.h:39
A Configuration Graph A graph representing Components and Links.
Definition: configGraph.h:202
Definition: action.cc:17
void setStatisticOutput(const char *name)
Set the statistic ouput module.
Definition: configGraph.cc:293
void addParameter(ComponentId_t comp_id, std::string key, std::string value, bool overwrite=false)
Add a single parameter to a component.
Definition: configGraph.cc:279
void addComponentStatisticParameter(ComponentId_t comp_id, std::string statisticName, const char *param, const char *value)
Add Parameters for a Statistic.
Definition: configGraph.cc:388
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:436
ComponentId_t addComponent(std::string name, std::string type, float weight, RankInfo rank)
Create a new component with weight and rank.
Definition: configGraph.cc:244
Definition: rankInfo.h:21
void setComponentWeight(ComponentId_t comp_id, float weight)
Set the weight of a Component (partitioning)
Definition: configGraph.cc:264
void addStatisticOutputParameter(const char *param, const char *value)
Add parameter to the statistic output module.
Definition: configGraph.cc:305
void enableComponentStatistic(ComponentId_t comp_id, std::string statisticName)
Enable a Statistics assigned to a component.
Definition: configGraph.cc:318
Base class for Model Generation.
Definition: sstmodel.h:22
void setComponentRank(ComponentId_t comp_id, RankInfo rank)
Set on which rank a Component will exist (partitioning)
Definition: configGraph.cc:258