SST  6.0.0
StructuralSimulationToolkit
config.h
1 // Copyright 2009-2016 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-2016, 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_CONFIG_H
13 #define SST_CORE_CONFIG_H
14 
15 #include <sst/core/sst_types.h>
16 #include <sst/core/simulation.h>
17 #include <sst/core/rankInfo.h>
18 #include <sst/core/env/envquery.h>
19 #include <sst/core/env/envconfig.h>
20 
21 #include <sst/core/serialization/serializable.h>
22 
23 #include <string>
24 
25 namespace boost {
26  namespace program_options {
27 
28  class options_description;
29  class positional_options_description;
30  class variables_map;
31  }
32 }
33 
34 namespace SST {
35 
36 /**
37  * Class to contain SST Simulation Configuration variables
38  */
40 public:
41 
42  /** Create a new Config object.
43  * @param my_rank - parallel rank of this instance
44  * @param world_size - number of parallel ranks in the simulation
45  */
47  Config () {} // For serialization
48  ~Config();
49 
50  /** Parse command-line arguments to update configuration values */
51  int parseCmdLine( int argc, char* argv[] );
52  /** Parse a configuration string to update configuration values */
53  int parseConfigFile( std::string config_string );
54  /** Return the current Verbosity level */
55  uint32_t getVerboseLevel();
56 
57  /** Print the SST core timing information */
58  bool printTimingInfo();
59 
60  /** Set the cycle at which to stop the simulation */
61  void setStopAt(std::string stopAtStr);
62  /** Sets the default timebase of the simulation */
63  void setTimeBase(std::string timeBase);
64  /** Print the current configuration to stdout */
65  void Print();
66 
67  std::string debugFile; /*!< File to which debug information should be written */
68  Simulation::Mode_t runMode; /*!< Run Mode (Init, Both, Run-only) */
69  std::string sdlfile; /*!< Graph generation file */
70  std::string stopAtCycle; /*!< When to stop the simulation */
71  std::string heartbeatPeriod; /*!< Sets the heartbeat period for the simulation */
72  std::string timeBase; /*!< Timebase of simulation */
73  std::string partitioner; /*!< Partitioner to use */
74  std::string generator; /*!< Generator to use */
75  std::string generator_options; /*!< Options to pass to the generator */
76  std::string output_config_graph; /*!< File to dump configuration graph */
77  std::string output_dot; /*!< File to dump dot output */
78  std::string output_xml; /*!< File to dump XML output */
79  std::string output_json; /*!< File to dump JSON output */
80  std::string output_directory; /*!< Output directory to dump all files to */
81  std::string model_options; /*!< Options to pass to Python Model generator */
82  std::string dump_component_graph_file; /*!< File to dump component graph */
83  std::string output_core_prefix; /*!< Set the SST::Output prefix for the core */
84 
85  RankInfo world_size; /*!< Number of ranks, threads which should be invoked per rank */
86  uint32_t verbose; /*!< Verbosity */
87  bool no_env_config; /*!< Bypass compile-time environmental configuration */
88  bool enable_sig_handling; /*!< Enable signal handling */
89  bool print_timing; /*!< Print SST timing information */
90 
91 #ifdef USE_MEMPOOL
92  std::string event_dump_file; /*!< File to dump undeleted events to */
93 #endif
94  /** Set the run-mode
95  * @param mode - string "init" "run" "both"
96  * @return the Mode_t corresponding
97  */
98  inline Simulation::Mode_t setRunMode( std::string mode )
99  {
100  if( ! mode.compare( "init" ) ) return Simulation::INIT;
101  if( ! mode.compare( "run" ) ) return Simulation::RUN;
102  if( ! mode.compare( "both" ) ) return Simulation::BOTH;
103  return Simulation::UNKNOWN;
104  }
105 
106  Simulation::Mode_t getRunMode() {
107  return runMode;
108  }
109 
110  /** Print to stdout the current configuration */
111  void print() {
112  std::cout << "debugFile = " << debugFile << std::endl;
113  std::cout << "runMode = " << runMode << std::endl;
114  std::cout << "libpath = " << getLibPath() << std::endl;
115  std::cout << "sdlfile = " << sdlfile << std::endl;
116  std::cout << "stopAtCycle = " << stopAtCycle << std::endl;
117  std::cout << "timeBase = " << timeBase << std::endl;
118  std::cout << "partitioner = " << partitioner << std::endl;
119  std::cout << "generator = " << generator << std::endl;
120  std::cout << "gen_options = " << generator_options << std::endl;
121  std::cout << "output_config_graph = " << output_config_graph << std::endl;
122  std::cout << "output_xml = " << output_xml << std::endl;
123  std::cout << "no_env_config = " << no_env_config << std::endl;
124  std::cout << "output_directory = " << output_directory << std::endl;
125  std::cout << "output_json = " << output_json << std::endl;
126  std::cout << "model_options = " << model_options << std::endl;
127  std::cout << "num_threads = " << world_size.thread << std::endl;
128  std::cout << "enable_sig_handling = " << enable_sig_handling << std::endl;
129  std::cout << "output_core_prefix = " << output_core_prefix << std::endl;
130  std::cout << "print_timing=" << print_timing << std::endl;
131  }
132 
133  /** Return the library search path */
134  std::string getLibPath(void) const {
135  char *envpath = getenv("SST_LIB_PATH");
136 
137  // Get configuration options from the user config
138  std::vector<std::string> overrideConfigPaths;
140  SST::Core::Environment::getSSTEnvironmentConfiguration(overrideConfigPaths);
141 
142  std::string fullLibPath = libpath;
143  std::set<std::string> configGroups = envConfig->getGroupNames();
144 
145  // iterate over groups of settings
146  for(auto groupItr = configGroups.begin(); groupItr != configGroups.end(); groupItr++) {
148  envConfig->getGroupByName(*groupItr);
149  std::set<std::string> groupKeys = currentGroup->getKeys();
150 
151  // find which keys have a LIBDIR at the END of the key
152  // we recognize these may house elements
153  for(auto keyItr = groupKeys.begin(); keyItr != groupKeys.end(); keyItr++) {
154  const std::string key = *keyItr;
155  const std::string value = currentGroup->getValue(key);
156 
157  if("BOOST_LIBDIR" != key) {
158  if(key.size() > 6) {
159  if("LIBDIR" == key.substr(key.size() - 6)) {
160  fullLibPath.append(":");
161  fullLibPath.append(value);
162  }
163  }
164  }
165  }
166  }
167 
168  // Clean up and delete the configuration we just loaded up
169  delete envConfig;
170 
171  if(NULL != envpath) {
172  fullLibPath.clear();
173  fullLibPath.append(envpath);
174  }
175 
176  if ( !addlLibPath.empty() ) {
177  fullLibPath.append(":");
178  fullLibPath.append(addlLibPath);
179  }
180 
181  if(verbose) {
182  std::cout << "SST-Core: Configuration Library Path will read from: " << fullLibPath << std::endl;
183  }
184 
185  return fullLibPath;
186  }
187 
188  uint32_t getNumRanks() { return world_size.rank; }
189  uint32_t getNumThreads() { return world_size.thread; }
190  uint32_t setNumThreads(uint32_t nthr) {
191  uint32_t old = world_size.thread;
192  world_size.thread = nthr;
193  return old;
194  }
195 
196  void serialize_order(SST::Core::Serialization::serializer &ser)
197  {
198  ser & debugFile;
199  ser & runMode;
200  ser & libpath;
201  ser & addlLibPath;
202  ser & sdlfile;
203  ser & stopAtCycle;
204  ser & timeBase;
205  ser & partitioner;
206  ser & generator;
207  ser & generator_options;
209  ser & output_config_graph;
210  ser & output_xml;
211  ser & output_json;
212  ser & no_env_config;
213  ser & model_options;
214  ser & world_size;
215  ser & enable_sig_handling;
216  ser & output_core_prefix;
217  ser & print_timing;
218  }
219 
220 private:
221  boost::program_options::options_description* visNoConfigDesc;
222  boost::program_options::options_description* hiddenNoConfigDesc;
223  boost::program_options::options_description* legacyDesc;
224  boost::program_options::options_description* mainDesc;
225  boost::program_options::positional_options_description* posDesc;
226  boost::program_options::variables_map* var_map;
227  std::string run_name;
228  std::string libpath;
229  std::string addlLibPath;
230 
231  int rank;
232  int numRanks;
233 
234  ImplementSerializable(SST::Config)
235 };
236 
237 } // namespace SST
238 
239 #endif // SST_CORE_CONFIG_H
RankInfo world_size
Definition: config.h:85
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
std::string generator_options
Definition: config.h:75
std::string sdlfile
Definition: config.h:69
Definition: config.h:25
std::string partitioner
Definition: config.h:73
Class to contain SST Simulation Configuration variables.
Definition: config.h:39
std::string heartbeatPeriod
Definition: config.h:71
std::string output_core_prefix
Definition: config.h:83
int parseCmdLine(int argc, char *argv[])
Parse command-line arguments to update configuration values.
Definition: config.cc:193
Simulation::Mode_t runMode
Definition: config.h:68
Definition: action.cc:17
Definition: simulation.h:80
int parseConfigFile(std::string config_string)
Parse a configuration string to update configuration values.
Definition: config.cc:277
Definition: simulation.h:79
std::string output_config_graph
Definition: config.h:76
uint32_t getVerboseLevel()
Return the current Verbosity level.
Definition: config.cc:180
std::string output_dot
Definition: config.h:77
Definition: serializable.h:108
void setTimeBase(std::string timeBase)
Sets the default timebase of the simulation.
Definition: config.cc:184
uint32_t verbose
Definition: config.h:86
std::string timeBase
Definition: config.h:72
bool no_env_config
Definition: config.h:87
Simulation::Mode_t setRunMode(std::string mode)
Set the run-mode.
Definition: config.h:98
std::string model_options
Definition: config.h:81
std::string output_xml
Definition: config.h:78
std::string output_directory
Definition: config.h:80
Definition: rankInfo.h:21
std::string output_json
Definition: config.h:79
void print()
Print to stdout the current configuration.
Definition: config.h:111
bool printTimingInfo()
Print the SST core timing information.
Definition: config.cc:176
std::string debugFile
Definition: config.h:67
std::string generator
Definition: config.h:74
std::string getLibPath(void) const
Return the library search path.
Definition: config.h:134
std::string dump_component_graph_file
Definition: config.h:82
Definition: simulation.h:81
void setStopAt(std::string stopAtStr)
Set the cycle at which to stop the simulation.
Definition: config.cc:188
std::string stopAtCycle
Definition: config.h:70
Definition: simulation.h:82
bool enable_sig_handling
Definition: config.h:88
Mode_t
Type of Run Modes.
Definition: simulation.h:78
void Print()
Print the current configuration to stdout.
bool print_timing
Definition: config.h:89