SST  14.0.0
StructuralSimulationToolkit
config.h
1 // Copyright 2009-2024 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-2024, 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& heartbeat_period() const { return heartbeat_period_; }
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  Returns 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  Simulation period at which to create a checkpoint
231  */
232  const std::string& checkpoint_period() const { return checkpoint_period_; }
233 
234  /**
235  * Returns whether the simulation will begin from a checkpoint (true) or not (false).
236  */
237  bool load_from_checkpoint() const { return load_from_checkpoint_; }
238 
239  /**
240  Prefix for checkpoint filenames and directory
241  */
242  const std::string& checkpoint_prefix() const { return checkpoint_prefix_; }
243 
244  /**
245  TimeVortex implementation to use
246  */
247  const std::string& timeVortex() const { return timeVortex_; }
248 
249  /**
250  Use links that connect directly to ActivityQueue in receiving thread
251  */
252  bool interthread_links() const { return interthread_links_; }
253 
254 #ifdef USE_MEMPOOL
255  /**
256  Controls whether mempool items are cache-aligned
257 
258  */
259  bool cache_align_mempools() const { return cache_align_mempools_; }
260 #endif
261  /**
262  File to which core debug information should be written
263  */
264  const std::string& debugFile() const { return debugFile_; }
265 
266  /**
267  Library path to use for finding element libraries (will replace
268  the libpath in the sstsimulator.conf file)
269 
270  ** Included in ConfigShared
271  const std::string& libpath() const { return libpath_; }
272  */
273 
274  /**
275  Paths to add to library search (adds to libpath found in
276  sstsimulator.conf file)
277 
278  ** Included in ConfigShared
279  const std::string& addLibPath() const { return addLibPath_; }
280  */
281 
282  // Advanced options - Profiling
283 
284  /**
285  Profiling points to turn on
286  */
287  const std::string& enabledProfiling() const { return enabled_profiling_; }
288 
289  /**
290  Profiling points to turn on
291  */
292  const std::string& profilingOutput() const { return profiling_output_; }
293 
294  // Advanced options - Debug
295 
296  /**
297  Run mode to use (Init, Both, Run-only). Note that Run-only is
298  not currently supported because there is not component level
299  checkpointing.
300  */
301  SimulationRunMode runMode() const { return runMode_; }
302 
303  /**
304  Get string version of runmode.
305  */
306  std::string runMode_str() const
307  {
308  switch ( runMode_ ) {
309  case SimulationRunMode::INIT:
310  return "INIT";
311  case SimulationRunMode::RUN:
312  return "RUN";
313  case SimulationRunMode::BOTH:
314  return "BOTH";
315  case SimulationRunMode::UNKNOWN:
316  return "UNKNOWN";
317  }
318  return "UNKNOWN";
319  }
320 
321 
322 #ifdef USE_MEMPOOL
323  /**
324  File to output list of events that remain undeleted at the end
325  of the simulation.
326 
327  If no mempools, just reutrn empty string. This avoids a check
328  for mempools in main.cc
329  */
330  const std::string& event_dump_file() const { return event_dump_file_; }
331 #endif
332 
333  /**
334  Run simulation initialization stages one rank at a time for
335  debug purposes
336  */
337  bool rank_seq_startup() const { return rank_seq_startup_; }
338 
339  // Advanced options - envrionment
340 
341  /**
342  Controls whether the environment variables that SST sees are
343  printed out
344 
345  ** Included in ConfigShared
346  bool print_env() const { return print_env_; }
347  */
348 
349  /**
350  ** Included in ConfigShared
351  bool no_env_config() const { return no_env_config_; }
352  */
353 
354  /**
355  Controls whether signal handlers are enable or not. NOTE: the
356  sense of this variable is opposite of the command1 line option
357  (--disable-signal-handlers)
358  */
359  bool enable_sig_handling() const { return enable_sig_handling_; }
360 
361  // This option is used by the SST wrapper found in
362  // bootshare.{h,cc} and is never actually accessed once sst.x
363  // executes.
364 
365 
366  /** Print to stdout the current configuration */
367  void print();
368 
369  void serialize_order(SST::Core::Serialization::serializer& ser) override
370  {
371  ser& verbose_;
372  ser& configFile_;
373  ser& model_options_;
374  ser& print_timing_;
375  ser& stop_at_;
376  ser& exit_after_;
377  ser& partitioner_;
378  ser& heartbeat_period_;
379  ser& output_directory_;
380  ser& output_core_prefix_;
381 
382  ser& output_config_graph_;
383  ser& output_json_;
384  ser& parallel_output_;
385 
386  ser& output_dot_;
387  ser& dot_verbosity_;
388  ser& component_partition_file_;
389  ser& output_partition_;
390 
391  ser& timeBase_;
392  ser& parallel_load_;
393  ser& parallel_load_mode_multi_;
394  ser& timeVortex_;
395  ser& interthread_links_;
396 #ifdef USE_MEMPOOL
397  ser& cache_align_mempools_;
398 #endif
399  ser& debugFile_;
400  ser& libpath_;
401  ser& addlibpath_;
402  ser& enabled_profiling_;
403  ser& profiling_output_;
404  ser& runMode_;
405 #ifdef USE_MEMPOOL
406  ser& event_dump_file_;
407 #endif
408  ser& load_from_checkpoint_;
409  ser& checkpoint_period_;
410  ser& checkpoint_prefix_;
411 
412  ser& print_env_;
413  ser& enable_sig_handling_;
414  ser& no_env_config_;
415  }
416  ImplementSerializable(SST::Config);
417 
418 protected:
419  std::string getUsagePrelude() override;
420  int checkArgsAfterParsing() override;
421  int positionalCallback(int num, const std::string& arg);
422 
423 private:
424  //// Items private to Config
425 
426  std::string run_name;
427  bool first_rank_;
428 
429  // Inserts all the command line options into the underlying data
430  // structures
431  void insertOptions();
432 
433  bool isFileNameOnly(const std::string& name)
434  {
435  bool nameOnly = true;
436 
437  for ( size_t i = 0; i < name.size(); ++i ) {
438  if ( '/' == name[i] ) {
439  nameOnly = false;
440  break;
441  }
442  }
443 
444  return nameOnly;
445  }
446 
447  // Variables to hold the options. Declared in order they show up
448  // in the options array
449 
450  // Information options
451  // No variable associated with help
452  // No variable associated with version
453 
454  // Basic options
455  // uint32_t verbose_; ** in ConfigShared
456  // Num threads held in RankInfo.thread
457  uint32_t num_ranks_; /*!< Number of ranks in the simulation */
458  uint32_t num_threads_; /*!< Number of threads requested */
459  std::string configFile_; /*!< Graph generation file */
460  std::string model_options_; /*!< Options to pass to Python Model generator */
461  bool print_timing_; /*!< Print SST timing information */
462  std::string stop_at_; /*!< When to stop the simulation */
463  uint32_t exit_after_; /*!< When (wall-time) to stop the simulation */
464  std::string partitioner_; /*!< Partitioner to use */
465  std::string heartbeat_period_; /*!< Sets the heartbeat period for the simulation */
466  std::string output_directory_; /*!< Output directory to dump all files to */
467  std::string output_core_prefix_; /*!< Set the SST::Output prefix for the core */
468 
469  // Configuration output
470  std::string output_config_graph_; /*!< File to dump configuration graph */
471  std::string output_json_; /*!< File to dump JSON output */
472  bool parallel_output_; /*!< Output simulation graph in parallel */
473 
474  // Graph output
475  std::string output_dot_; /*!< File to dump dot output */
476  uint32_t dot_verbosity_; /*!< Amount of detail to include in the dot graph output */
477  std::string component_partition_file_; /*!< File to dump component graph */
478  bool output_partition_; /*!< Output paritition info when writing config output */
479 
480  // Advanced options
481  std::string timeBase_; /*!< Timebase of simulation */
482  bool parallel_load_; /*!< Load simulation graph in parallel */
483  bool parallel_load_mode_multi_; /*!< If true, load using multiple files */
484  std::string timeVortex_; /*!< TimeVortex implementation to use */
485  bool interthread_links_; /*!< Use interthread links */
486 #ifdef USE_MEMPOOL
487  bool cache_align_mempools_; /*!< Cache align allocations from mempools */
488 #endif
489  std::string debugFile_; /*!< File to which debug information should be written */
490  // std::string libpath_; ** in ConfigShared
491  // std::string addLibPath_; ** in ConfigShared
492 
493  // Advanced options - profiling
494  std::string enabled_profiling_; /*!< Enabled default profiling points */
495  std::string profiling_output_; /*!< Location to write profiling data */
496 
497  // Advanced options - debug
498  SimulationRunMode runMode_; /*!< Run Mode (Init, Both, Run-only) */
499 #ifdef USE_MEMPOOL
500  std::string event_dump_file_; /*!< File to dump undeleted events to */
501 #endif
502  bool rank_seq_startup_; /*!< Run simulation initialization phases one rank at a time */
503 
504  // Advanced options - checkpoint
505  bool load_from_checkpoint_; /*!< If true, load from checkpoint instead of config file */
506  std::string checkpoint_period_; /*!< Simulated time interval to generate checkpoints at */
507  std::string checkpoint_prefix_; /*!< Prefix for checkpoint filename and checkpoint directory */
508  std::string checkpoint_directory_; /*!< Directory to write checkpoints to */
509 
510  // Advanced options - envrionment
511  bool enable_sig_handling_; /*!< Enable signal handling */
512  // bool print_env_; ** in ConfigShared
513  // bool no_env_config_; ** in ConfigShared
514 };
515 
516 } // namespace SST
517 
518 #endif // SST_CORE_CONFIG_H
const std::string & enabledProfiling() const
Library path to use for finding element libraries (will replace the libpath in the sstsimulator...
Definition: config.h:287
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
const std::string & heartbeat_period() const
Simulation period at which to print out a "heartbeat" message.
Definition: config.h:137
bool enable_sig_handling() const
Controls whether the environment variables that SST sees are printed out.
Definition: config.h:359
uint32_t dot_verbosity() const
Level of verbosity to use for the dot output.
Definition: config.h:182
uint32_t exit_after() const
Wall clock time (approximiate) in seconds to stop the simulation at.
Definition: config.h:127
Class to contain SST Simulation Configuration variables.
Definition: config.h:38
const std::string & checkpoint_prefix() const
Prefix for checkpoint filenames and directory.
Definition: config.h:242
const std::string & profilingOutput() const
Profiling points to turn on.
Definition: config.h:292
bool parallel_load() const
Controls whether graph constuction will be done in parallel.
Definition: config.h:209
bool parallel_output() const
If true, and a config graph output option is specified, write each ranks graph separately.
Definition: config.h:167
const std::string output_core_prefix() const
Prefix to use for the default SST::Output object in core.
Definition: config.h:147
Class to contain SST Simulation Configuration variables.
Definition: configShared.h:33
Definition: action.cc:18
const std::string & output_dot() const
File to output dot formatted config graph to (empty string means no output).
Definition: config.h:177
bool output_partition() const
Controls whether partition info is output as part of configuration output.
Definition: config.h:192
const std::string & timeVortex() const
TimeVortex implementation to use.
Definition: config.h:247
const std::string & component_partition_file() const
File to output component partition info to (empty string means no output)
Definition: config.h:187
SimulationRunMode runMode() const
Run mode to use (Init, Both, Run-only).
Definition: config.h:301
Definition: serializable.h:118
const std::string & stop_at() const
Simulated cycle to stop the simulation at.
Definition: config.h:122
uint32_t num_ranks() const
Number of ranks in the simulation.
Definition: config.h:102
const std::string & output_json() const
File to output json formatted config graph to (empty string means no output)
Definition: config.h:161
bool print_timing() const
Print SST timing information after the run.
Definition: config.h:117
const std::string & configFile() const
Name of the SDL file to use to genearte the simulation.
Definition: config.h:107
Definition: config.cc:33
bool interthread_links() const
Use links that connect directly to ActivityQueue in receiving thread.
Definition: config.h:252
std::string runMode_str() const
Get string version of runmode.
Definition: config.h:306
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 & checkpoint_period() const
Simulation period at which to create a checkpoint.
Definition: config.h:232
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 & debugFile() const
File to which core debug information should be written.
Definition: config.h:264
std::string parallel_load_str() const
Returns the string equivalent for parallel-load: NONE (if parallel load is off), SINGLE or MULTI...
Definition: config.h:222
const std::string & model_options() const
Model options to pass to the SDL file.
Definition: config.h:112
void print()
Print to stdout the current configuration.
Definition: config.cc:492
uint32_t num_threads() const
Level of verbosity to use in the core prints using Output.verbose or Output.debug.
Definition: config.h:97
Base class for Model Generation.
Definition: sstmodel.h:25
const std::string & output_directory() const
The directory to be used for writting output files.
Definition: config.h:142
const std::string & timeBase() const
Core timebase to use as the atomic time unit for the simulation.
Definition: config.h:201
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition: config.cc:834
bool load_from_checkpoint() const
Returns whether the simulation will begin from a checkpoint (true) or not (false).
Definition: config.h:237
bool rank_seq_startup() const
Run simulation initialization stages one rank at a time for debug purposes.
Definition: config.h:337
ConfigShared()
Default constructor used for serialization.
Definition: configShared.h:59
const std::string & partitioner() const
Partitioner to use for parallel simualations.
Definition: config.h:132