SST  13.1.0
Structural Simulation Toolkit
config.h
1 // Copyright 2009-2023 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2023, NTESS
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/configShared.h"
16 #include "sst/core/serialization/serializable.h"
17 #include "sst/core/sst_types.h"
18 
19 #include <string>
20 
21 /* Forward declare for Friendship */
22 extern int main(int argc, char** argv);
23 
24 namespace SST {
25 class Config;
26 
27 class ConfigHelper;
28 class SSTModelDescription;
29 /**
30  * Class to contain SST Simulation Configuration variables.
31  *
32  * NOTE: This class needs to be serialized for the sst.x executable,
33  * but not for the sst (wrapper compiled from the boot*.{h,cc} files)
34  * executable. To avoid having to compile all the serialization code
35  * into the bootstrap executable, the Config class is the first level
36  * of class hierarchy to inherit from serializable.
37  */
39 {
40 
41 private:
42  // Main creates the config object
43  friend int ::main(int argc, char** argv);
44  friend class ConfigHelper;
45  friend class SSTModelDescription;
46 
47  /**
48  Config constructor. Meant to only be created by main function
49  */
50  Config(uint32_t num_ranks, bool first_rank);
51 
52  /**
53  Default constructor used for serialization. At this point,
54  first_rank_ is no longer needed, so just initialize to false.
55  */
56  Config() : ConfigShared(true, {}), first_rank_(false) {}
57 
58  //// Functions for use in main
59 
60  /**
61  Checks for the existance of the config file. This needs to be
62  called after adding any rank numbers to the file in the case of
63  parallel loading.
64  */
65  bool checkConfigFile();
66 
67  // Function to be called from ModelDescriptions
68 
69  /** Set a configuration string to update configuration values */
70  bool setOptionFromModel(const std::string& entryName, const std::string& value);
71 
72 
73 public:
74  ~Config() {}
75 
76  // Functions to access config options. Declared in order they show
77  // up in the options array
78 
79  // Information options
80  // No variable associated with help
81  // No variable associated with version
82 
83  // Basic options
84 
85  /**
86  Level of verbosity to use in the core prints using
87  Output.verbose or Output.debug.
88 
89  ** Included in ConfigShared
90  uint32_t verbose() const { return verbose_; }
91  */
92 
93 
94  /**
95  Number of threads requested
96  */
97  uint32_t num_threads() const { return num_threads_; }
98 
99  /**
100  Number of ranks in the simulation
101  */
102  uint32_t num_ranks() const { return num_ranks_; }
103 
104  /**
105  Name of the SDL file to use to genearte the simulation
106  */
107  const std::string& configFile() const { return configFile_; }
108 
109  /**
110  Model options to pass to the SDL file
111  */
112  const std::string& model_options() const { return model_options_; }
113 
114  /**
115  Print SST timing information after the run
116  */
117  bool print_timing() const { return print_timing_; }
118 
119  /**
120  Simulated cycle to stop the simulation at
121  */
122  const std::string& stop_at() const { return stop_at_; }
123 
124  /**
125  Wall clock time (approximiate) in seconds to stop the simulation at
126  */
127  uint32_t exit_after() const { return exit_after_; }
128 
129  /**
130  Partitioner to use for parallel simualations
131  */
132  const std::string& partitioner() const { return partitioner_; }
133 
134  /**
135  Simulation period at which to print out a "heartbeat" message
136  */
137  const std::string& heartbeatPeriod() const { return heartbeatPeriod_; }
138 
139  /**
140  The directory to be used for writting output files
141  */
142  const std::string& output_directory() const { return output_directory_; }
143 
144  /**
145  Prefix to use for the default SST::Output object in core
146  */
147  const std::string output_core_prefix() const { return output_core_prefix_; }
148 
149  // Configuration output
150 
151  /**
152  File to output python formatted config graph to (empty string means no
153  output)
154  */
155  const std::string& output_config_graph() const { return output_config_graph_; }
156 
157  /**
158  File to output json formatted config graph to (empty string means no
159  output)
160  */
161  const std::string& output_json() const { return output_json_; }
162 
163  /**
164  If true, and a config graph output option is specified, write
165  each ranks graph separately
166  */
167  bool parallel_output() const { return parallel_output_; }
168 
169 
170  // Graph output
171 
172  /**
173  File to output dot formatted config graph to (empty string means no
174  output). Note, this is not a format that can be used as input for simulation
175 
176  */
177  const std::string& output_dot() const { return output_dot_; }
178 
179  /**
180  Level of verbosity to use for the dot output.
181  */
182  uint32_t dot_verbosity() const { return dot_verbosity_; }
183 
184  /**
185  File to output component partition info to (empty string means no output)
186  */
187  const std::string& component_partition_file() const { return component_partition_file_; }
188 
189  /**
190  Controls whether partition info is output as part of configuration output
191  */
192  bool output_partition() const { return output_partition_; }
193 
194  // Advanced options
195 
196  /**
197  Core timebase to use as the atomic time unit for the
198  simulation. It is usually best to just leave this at the
199  default (1ps)
200  */
201  const std::string& timeBase() const { return timeBase_; }
202 
203  /**
204  Controls whether graph constuction will be done in parallel.
205  If it is, then the SDL file name is modified to add the rank
206  number to the file name right before the file extension, if
207  parallel_load_mode_multi is true.
208  */
209  bool parallel_load() const { return parallel_load_; }
210 
211  /**
212  If graph constuction will be done in parallel, will use a
213  file per rank if true, and the same file for each rank if
214  false.
215  */
216  bool parallel_load_mode_multi() const { return parallel_load_mode_multi_; }
217 
218  /**
219  Retruns the string equivalent for parallel-load: NONE (if
220  parallel load is off), SINGLE or MULTI.
221  */
222  std::string parallel_load_str() const
223  {
224  if ( !parallel_load_ ) return "NONE";
225  if ( parallel_load_mode_multi_ ) return "MULTI";
226  return "SINGLE";
227  }
228 
229  /**
230  TimeVortex implementation to use
231  */
232  const std::string& timeVortex() const { return timeVortex_; }
233 
234  /**
235  Use links that connect directly to ActivityQueue in receiving thread
236  */
237  bool interthread_links() const { return interthread_links_; }
238 
239 #ifdef USE_MEMPOOL
240  /**
241  Controls whether mempool items are cache-aligned
242 
243  */
244  bool cache_align_mempools() const { return cache_align_mempools_; }
245 #endif
246  /**
247  File to which core debug information should be written
248  */
249  const std::string& debugFile() const { return debugFile_; }
250 
251  /**
252  Library path to use for finding element libraries (will replace
253  the libpath in the sstsimulator.conf file)
254 
255  ** Included in ConfigShared
256  const std::string& libpath() const { return libpath_; }
257  */
258 
259  /**
260  Paths to add to library search (adds to libpath found in
261  sstsimulator.conf file)
262 
263  ** Included in ConfigShared
264  const std::string& addLibPath() const { return addLibPath_; }
265  */
266 
267  // Advanced options - Profiling
268 
269  /**
270  Profiling points to turn on
271  */
272  const std::string& enabledProfiling() const { return enabled_profiling_; }
273 
274  /**
275  Profiling points to turn on
276  */
277  const std::string& profilingOutput() const { return profiling_output_; }
278 
279  // Advanced options - Debug
280 
281  /**
282  Run mode to use (Init, Both, Run-only). Note that Run-only is
283  not currently supported because there is not component level
284  checkpointing.
285  */
286  SimulationRunMode runMode() const { return runMode_; }
287 
288  /**
289  Get string version of runmode.
290  */
291  std::string runMode_str() const
292  {
293  switch ( runMode_ ) {
294  case SimulationRunMode::INIT:
295  return "INIT";
296  case SimulationRunMode::RUN:
297  return "RUN";
298  case SimulationRunMode::BOTH:
299  return "BOTH";
300  case SimulationRunMode::UNKNOWN:
301  return "UNKNOWN";
302  }
303  return "UNKNOWN";
304  }
305 
306 
307 #ifdef USE_MEMPOOL
308  /**
309  File to output list of events that remain undeleted at the end
310  of the simulation.
311 
312  If no mempools, just reutrn empty string. This avoids a check
313  for mempools in main.cc
314  */
315  const std::string& event_dump_file() const { return event_dump_file_; }
316 #endif
317 
318  /**
319  Run simulation initialization stages one rank at a time for
320  debug purposes
321  */
322  bool rank_seq_startup() const { return rank_seq_startup_; }
323 
324  // Advanced options - envrionment
325 
326  /**
327  Controls whether the environment variables that SST sees are
328  printed out
329 
330  ** Included in ConfigShared
331  bool print_env() const { return print_env_; }
332  */
333 
334  /**
335  ** Included in ConfigShared
336  bool no_env_config() const { return no_env_config_; }
337  */
338 
339  /**
340  Controls whether signal handlers are enable or not. NOTE: the
341  sense of this variable is opposite of the command1 line option
342  (--disable-signal-handlers)
343  */
344  bool enable_sig_handling() const { return enable_sig_handling_; }
345 
346  // This option is used by the SST wrapper found in
347  // bootshare.{h,cc} and is never actually accessed once sst.x
348  // executes.
349 
350 
351  /** Print to stdout the current configuration */
352  void print();
353 
354  void serialize_order(SST::Core::Serialization::serializer& ser) override
355  {
356  ser& verbose_;
357  ser& configFile_;
358  ser& model_options_;
359  ser& print_timing_;
360  ser& stop_at_;
361  ser& exit_after_;
362  ser& partitioner_;
363  ser& heartbeatPeriod_;
364  ser& output_directory_;
365  ser& output_core_prefix_;
366 
367  ser& output_config_graph_;
368  ser& output_json_;
369  ser& parallel_output_;
370 
371  ser& output_dot_;
372  ser& dot_verbosity_;
373  ser& component_partition_file_;
374  ser& output_partition_;
375 
376  ser& timeBase_;
377  ser& parallel_load_;
378  ser& parallel_load_mode_multi_;
379  ser& timeVortex_;
380  ser& interthread_links_;
381 #ifdef USE_MEMPOOL
382  ser& cache_align_mempools_;
383 #endif
384  ser& debugFile_;
385  ser& libpath_;
386  ser& addlibpath_;
387  ser& enabled_profiling_;
388  ser& profiling_output_;
389  ser& runMode_;
390 #ifdef USE_MEMPOOL
391  ser& event_dump_file_;
392 #endif
393 
394  ser& print_env_;
395  ser& enable_sig_handling_;
396  ser& no_env_config_;
397  }
398  ImplementSerializable(SST::Config);
399 
400 protected:
401  std::string getUsagePrelude() override;
402  int checkArgsAfterParsing() override;
403  int positionalCallback(int num, const std::string& arg);
404 
405 private:
406  //// Items private to Config
407 
408  std::string run_name;
409  bool first_rank_;
410 
411  // Inserts all the command line options into the underlying data
412  // structures
413  void insertOptions();
414 
415  bool isFileNameOnly(const std::string& name)
416  {
417  bool nameOnly = true;
418 
419  for ( size_t i = 0; i < name.size(); ++i ) {
420  if ( '/' == name[i] ) {
421  nameOnly = false;
422  break;
423  }
424  }
425 
426  return nameOnly;
427  }
428 
429  // Variables to hold the options. Declared in order they show up
430  // in the options array
431 
432  // Information options
433  // No variable associated with help
434  // No variable associated with version
435 
436  // Basic options
437  // uint32_t verbose_; ** in ConfigShared
438  // Num threads held in RankInfo.thread
439  uint32_t num_ranks_; /*!< Number of ranks in the simulation */
440  uint32_t num_threads_; /*!< Number of threads requested */
441  std::string configFile_; /*!< Graph generation file */
442  std::string model_options_; /*!< Options to pass to Python Model generator */
443  bool print_timing_; /*!< Print SST timing information */
444  std::string stop_at_; /*!< When to stop the simulation */
445  uint32_t exit_after_; /*!< When (wall-time) to stop the simulation */
446  std::string partitioner_; /*!< Partitioner to use */
447  std::string heartbeatPeriod_; /*!< Sets the heartbeat period for the simulation */
448  std::string output_directory_; /*!< Output directory to dump all files to */
449  std::string output_core_prefix_; /*!< Set the SST::Output prefix for the core */
450 
451  // Configuration output
452  std::string output_config_graph_; /*!< File to dump configuration graph */
453  std::string output_json_; /*!< File to dump JSON output */
454  bool parallel_output_; /*!< Output simulation graph in parallel */
455 
456  // Graph output
457  std::string output_dot_; /*!< File to dump dot output */
458  uint32_t dot_verbosity_; /*!< Amount of detail to include in the dot graph output */
459  std::string component_partition_file_; /*!< File to dump component graph */
460  bool output_partition_; /*!< Output paritition info when writing config output */
461 
462  // Advanced options
463  std::string timeBase_; /*!< Timebase of simulation */
464  bool parallel_load_; /*!< Load simulation graph in parallel */
465  bool parallel_load_mode_multi_; /*!< If true, load using multiple files */
466  std::string timeVortex_; /*!< TimeVortex implementation to use */
467  bool interthread_links_; /*!< Use interthread links */
468 #ifdef USE_MEMPOOL
469  bool cache_align_mempools_; /*!< Cache align allocations from mempools */
470 #endif
471  std::string debugFile_; /*!< File to which debug information should be written */
472  // std::string libpath_; ** in ConfigShared
473  // std::string addLibPath_; ** in ConfigShared
474 
475  // Advanced options - profiling
476  std::string enabled_profiling_; /*!< Enabled default profiling points */
477  std::string profiling_output_; /*!< Location to write profiling data */
478 
479  // Advanced options - debug
480  SimulationRunMode runMode_; /*!< Run Mode (Init, Both, Run-only) */
481 #ifdef USE_MEMPOOL
482  std::string event_dump_file_; /*!< File to dump undeleted events to */
483 #endif
484  bool rank_seq_startup_; /*!< Run simulation initialization phases one rank at a time */
485 
486  // Advanced options - envrionment
487  bool enable_sig_handling_; /*!< Enable signal handling */
488  // bool print_env_; ** in ConfigShared
489  // bool no_env_config_; ** in ConfigShared
490 };
491 
492 } // namespace SST
493 
494 #endif // SST_CORE_CONFIG_H
Definition: config.cc:34
Class to contain SST Simulation Configuration variables.
Definition: configShared.h:34
ConfigShared()
Default constructor used for serialization.
Definition: configShared.h:59
Class to contain SST Simulation Configuration variables.
Definition: config.h:39
const std::string & stop_at() const
Simulated cycle to stop the simulation at.
Definition: config.h:122
const std::string & output_config_graph() const
File to output python formatted config graph to (empty string means no output)
Definition: config.h:155
const std::string & output_directory() const
The directory to be used for writting output files.
Definition: config.h:142
const std::string & configFile() const
Name of the SDL file to use to genearte the simulation.
Definition: config.h:107
uint32_t dot_verbosity() const
Level of verbosity to use for the dot output.
Definition: config.h:182
const std::string & timeVortex() const
TimeVortex implementation to use.
Definition: config.h:232
bool rank_seq_startup() const
Run simulation initialization stages one rank at a time for debug purposes.
Definition: config.h:322
bool print_timing() const
Print SST timing information after the run.
Definition: config.h:117
bool interthread_links() const
Use links that connect directly to ActivityQueue in receiving thread.
Definition: config.h:237
const std::string & partitioner() const
Partitioner to use for parallel simualations.
Definition: config.h:132
bool output_partition() const
Controls whether partition info is output as part of configuration output.
Definition: config.h:192
uint32_t exit_after() const
Wall clock time (approximiate) in seconds to stop the simulation at.
Definition: config.h:127
const std::string & component_partition_file() const
File to output component partition info to (empty string means no output)
Definition: config.h:187
const std::string & timeBase() const
Core timebase to use as the atomic time unit for the simulation.
Definition: config.h:201
uint32_t num_threads() const
Level of verbosity to use in the core prints using Output.verbose or Output.debug.
Definition: config.h:97
SimulationRunMode runMode() const
Run mode to use (Init, Both, Run-only).
Definition: config.h:286
const std::string & model_options() const
Model options to pass to the SDL file.
Definition: config.h:112
const std::string & output_dot() const
File to output dot formatted config graph to (empty string means no output).
Definition: config.h:177
bool enable_sig_handling() const
Controls whether the environment variables that SST sees are printed out.
Definition: config.h:344
uint32_t num_ranks() const
Number of ranks in the simulation.
Definition: config.h:102
std::string parallel_load_str() const
Retruns the string equivalent for parallel-load: NONE (if parallel load is off), SINGLE or MULTI.
Definition: config.h:222
bool parallel_output() const
If true, and a config graph output option is specified, write each ranks graph separately.
Definition: config.h:167
std::string runMode_str() const
Get string version of runmode.
Definition: config.h:291
void print()
Print to stdout the current configuration.
Definition: config.cc:449
bool parallel_load() const
Controls whether graph constuction will be done in parallel.
Definition: config.h:209
const std::string & enabledProfiling() const
Library path to use for finding element libraries (will replace the libpath in the sstsimulator....
Definition: config.h:272
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition: config.cc:768
bool parallel_load_mode_multi() const
If graph constuction will be done in parallel, will use a file per rank if true, and the same file fo...
Definition: config.h:216
const std::string & heartbeatPeriod() const
Simulation period at which to print out a "heartbeat" message.
Definition: config.h:137
const std::string & profilingOutput() const
Profiling points to turn on.
Definition: config.h:277
const std::string output_core_prefix() const
Prefix to use for the default SST::Output object in core.
Definition: config.h:147
const std::string & output_json() const
File to output json formatted config graph to (empty string means no output)
Definition: config.h:161
const std::string & debugFile() const
File to which core debug information should be written.
Definition: config.h:249
Definition: serializable.h:119
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
Base class for Model Generation.
Definition: sstmodel.h:26