SST  6.1.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  char *namePrefix;
52  size_t namePrefixLen;
53  std::vector<size_t> nameStack;
54  std::map<std::string, ComponentId_t> compNameMap;
55 
56  public:
57  std::vector<std::string> statParamKeyArray;
58  std::vector<std::string> statParamValueArray;
59 
60  public: /* Public, but private. Called only from Python functions */
61  Config* getConfig(void) const { return config; }
62  //ConfigGraph* getConfigGraph(void) const { return graph; }
63  Output* getOutput() const { return output; }
64  ComponentId_t addComponent(const char *name, const char *type) {
65  ComponentId_t id = graph->addComponent(name, type);
66  compNameMap[std::string(name)] = id;
67  return id;
68  }
69  ComponentId_t findComponentByName(const char *name) const {
70  auto itr = compNameMap.find(name);
71  return ( itr != compNameMap.end() ) ? itr->second : UNSET_COMPONENT_ID;
72  }
73  void addParameter(ComponentId_t id, const char *name, const char *value) const { graph->addParameter(id, name, value, true); }
74 
75  void setComponentRank(ComponentId_t id, uint32_t rank, uint32_t thread) const { graph->setComponentRank(id, RankInfo(rank, thread)); }
76  void setComponentWeight(ComponentId_t id, float weight) const { graph->setComponentWeight(id, weight); }
77  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); }
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 char* param, const char* value) { graph->addStatisticOutputParameter(param, value); }
85  void setStatisticLoadLevel(uint8_t loadLevel) { graph->setStatisticLoadLevel(loadLevel); }
86 
87  void enableComponentStatistic(ComponentId_t compid, const char* statname) const { graph->enableComponentStatistic(compid, statname); }
88  void enableStatisticForComponentName(const char* compname, const char* statname) const { graph->enableStatisticForComponentName(compname, statname); }
89  void enableStatisticForComponentType(const char* comptype, const char* statname) const { graph->enableStatisticForComponentType(comptype, statname); }
90 
91  void addComponentStatisticParameter(ComponentId_t compid, const char* statname, const char* param, const char* value) { graph->addComponentStatisticParameter(compid, statname, param, value); }
92  void addStatisticParameterForComponentName(const char* compname, const char* statname, const char* param, const char* value) { graph->addStatisticParameterForComponentName(compname, statname, param, value); }
93  void addStatisticParameterForComponentType(const char* comptype, const char* statname, const char* param, const char* value) { graph->addStatisticParameterForComponentType(comptype, statname, param, value); }
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:312
Class to contain SST Simulation Configuration variables.
Definition: config.h:31
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