SST  14.1.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 simulations
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_sim_period() const { return heartbeat_sim_period_; }
138 
139  /**
140  Wall-clock period at which to print out a "heartbeat" message
141  */
142  uint32_t heartbeat_wall_period() const { return heartbeat_wall_period_; }
143 
144  /**
145  The directory to be used for writting output files
146  */
147  const std::string& output_directory() const { return output_directory_; }
148 
149  /**
150  Prefix to use for the default SST::Output object in core
151  */
152  const std::string output_core_prefix() const { return output_core_prefix_; }
153 
154  // Configuration output
155 
156  /**
157  File to output python formatted config graph to (empty string means no
158  output)
159  */
160  const std::string& output_config_graph() const { return output_config_graph_; }
161 
162  /**
163  File to output json formatted config graph to (empty string means no
164  output)
165  */
166  const std::string& output_json() const { return output_json_; }
167 
168  /**
169  If true, and a config graph output option is specified, write
170  each ranks graph separately
171  */
172  bool parallel_output() const { return parallel_output_; }
173 
174 
175  // Graph output
176 
177  /**
178  File to output dot formatted config graph to (empty string means no
179  output). Note, this is not a format that can be used as input for simulation
180 
181  */
182  const std::string& output_dot() const { return output_dot_; }
183 
184  /**
185  Level of verbosity to use for the dot output.
186  */
187  uint32_t dot_verbosity() const { return dot_verbosity_; }
188 
189  /**
190  File to output component partition info to (empty string means no output)
191  */
192  const std::string& component_partition_file() const { return component_partition_file_; }
193 
194  /**
195  Controls whether partition info is output as part of configuration output
196  */
197  bool output_partition() const { return output_partition_; }
198 
199  // Advanced options
200 
201  /**
202  Core timebase to use as the atomic time unit for the
203  simulation. It is usually best to just leave this at the
204  default (1ps)
205  */
206  const std::string& timeBase() const { return timeBase_; }
207 
208  /**
209  Controls whether graph constuction will be done in parallel.
210  If it is, then the SDL file name is modified to add the rank
211  number to the file name right before the file extension, if
212  parallel_load_mode_multi is true.
213  */
214  bool parallel_load() const { return parallel_load_; }
215 
216  /**
217  If graph constuction will be done in parallel, will use a
218  file per rank if true, and the same file for each rank if
219  false.
220  */
221  bool parallel_load_mode_multi() const { return parallel_load_mode_multi_; }
222 
223  /**
224  Returns the string equivalent for parallel-load: NONE (if
225  parallel load is off), SINGLE or MULTI.
226  */
227  std::string parallel_load_str() const
228  {
229  if ( !parallel_load_ ) return "NONE";
230  if ( parallel_load_mode_multi_ ) return "MULTI";
231  return "SINGLE";
232  }
233 
234  /**
235  * Interval at which to create a checkpoint in wall time
236  */
237  uint32_t checkpoint_wall_period() const { return checkpoint_wall_period_; }
238  /**
239  * Interval at which to create a checkpoint in simulated time
240  */
241  const std::string& checkpoint_sim_period() const { return checkpoint_sim_period_; }
242 
243  /**
244  * Returns whether the simulation will begin from a checkpoint (true) or not (false).
245  */
246  bool load_from_checkpoint() const { return load_from_checkpoint_; }
247 
248  /**
249  Prefix for checkpoint filenames and directory
250  */
251  const std::string& checkpoint_prefix() const { return checkpoint_prefix_; }
252 
253  /**
254  TimeVortex implementation to use
255  */
256  const std::string& timeVortex() const { return timeVortex_; }
257 
258  /**
259  Use links that connect directly to ActivityQueue in receiving thread
260  */
261  bool interthread_links() const { return interthread_links_; }
262 
263 #ifdef USE_MEMPOOL
264  /**
265  Controls whether mempool items are cache-aligned
266 
267  */
268  bool cache_align_mempools() const { return cache_align_mempools_; }
269 #endif
270  /**
271  File to which core debug information should be written
272  */
273  const std::string& debugFile() const { return debugFile_; }
274 
275  /**
276  Library path to use for finding element libraries (will replace
277  the libpath in the sstsimulator.conf file)
278 
279  ** Included in ConfigShared
280  const std::string& libpath() const { return libpath_; }
281  */
282 
283  /**
284  Paths to add to library search (adds to libpath found in
285  sstsimulator.conf file)
286 
287  ** Included in ConfigShared
288  const std::string& addLibPath() const { return addLibPath_; }
289  */
290 
291  // Advanced options - Profiling
292 
293  /**
294  Profiling points to turn on
295  */
296  const std::string& enabledProfiling() const { return enabled_profiling_; }
297 
298  /**
299  Profiling points to turn on
300  */
301  const std::string& profilingOutput() const { return profiling_output_; }
302 
303  // Advanced options - Debug
304 
305  /**
306  Run mode to use (Init, Both, Run-only). Note that Run-only is
307  not currently supported because there is not component level
308  checkpointing.
309  */
310  SimulationRunMode runMode() const { return runMode_; }
311 
312  /**
313  Get string version of runmode.
314  */
315  std::string runMode_str() const
316  {
317  switch ( runMode_ ) {
318  case SimulationRunMode::INIT:
319  return "INIT";
320  case SimulationRunMode::RUN:
321  return "RUN";
322  case SimulationRunMode::BOTH:
323  return "BOTH";
324  case SimulationRunMode::UNKNOWN:
325  return "UNKNOWN";
326  }
327  return "UNKNOWN";
328  }
329 
330  /**
331  Get the InteractiveAction to use for interactive mode
332  */
333  std::string interactive_console() const { return interactive_console_; }
334 
335  /**
336  Get the time to start interactive mode
337  */
338  std::string interactive_start_time() const { return interactive_start_time_; }
339 
340 
341 #ifdef USE_MEMPOOL
342  /**
343  File to output list of events that remain undeleted at the end
344  of the simulation.
345 
346  If no mempools, just reutrn empty string. This avoids a check
347  for mempools in main.cc
348  */
349  const std::string& event_dump_file() const { return event_dump_file_; }
350 #endif
351 
352  /**
353  Run simulation initialization stages one rank at a time for
354  debug purposes
355  */
356  bool rank_seq_startup() const { return rank_seq_startup_; }
357 
358  // Advanced options - envrionment
359 
360  /**
361  Controls whether the environment variables that SST sees are
362  printed out
363 
364  ** Included in ConfigShared
365  bool print_env() const { return print_env_; }
366  */
367 
368  /**
369  ** Included in ConfigShared
370  bool no_env_config() const { return no_env_config_; }
371  */
372 
373  /**
374  Controls whether signal handlers are enable or not. NOTE: the
375  sense of this variable is opposite of the command1 line option
376  (--disable-signal-handlers)
377  */
378  bool enable_sig_handling() const { return enable_sig_handling_; }
379 
380  /**
381  * SIGUSR1 handler
382  */
383  const std::string& sigusr1() const { return sigusr1_; }
384 
385  /**
386  * SIGUSR2 handler
387  */
388  const std::string& sigusr2() const { return sigusr2_; }
389 
390  /**
391  * SIGALRM handler(s)
392  */
393  const std::string& sigalrm() const { return sigalrm_; }
394 
395  // This option is used by the SST wrapper found in
396  // bootshare.{h,cc} and is never actually accessed once sst.x
397  // executes.
398 
399 
400  /** Get whether or not any of the checkpoint options were turned on */
401  bool canInitiateCheckpoint();
402 
403  /** Print to stdout the current configuration */
404  void print();
405 
406  void serialize_order(SST::Core::Serialization::serializer& ser) override
407  {
408  ser& verbose_;
409  ser& configFile_;
410  ser& model_options_;
411  ser& print_timing_;
412  ser& stop_at_;
413  ser& exit_after_;
414  ser& partitioner_;
415  ser& heartbeat_wall_period_;
416  ser& heartbeat_sim_period_;
417  ser& output_directory_;
418  ser& output_core_prefix_;
419 
420  ser& output_config_graph_;
421  ser& output_json_;
422  ser& parallel_output_;
423 
424  ser& output_dot_;
425  ser& dot_verbosity_;
426  ser& component_partition_file_;
427  ser& output_partition_;
428 
429  ser& timeBase_;
430  ser& parallel_load_;
431  ser& parallel_load_mode_multi_;
432  ser& timeVortex_;
433  ser& interthread_links_;
434 #ifdef USE_MEMPOOL
435  ser& cache_align_mempools_;
436 #endif
437  ser& debugFile_;
438  ser& libpath_;
439  ser& addlibpath_;
440  ser& enabled_profiling_;
441  ser& profiling_output_;
442  ser& runMode_;
443  ser& interactive_console_;
444  ser& interactive_start_time_;
445 #ifdef USE_MEMPOOL
446  ser& event_dump_file_;
447 #endif
448  ser& load_from_checkpoint_;
449  ser& checkpoint_wall_period_;
450  ser& checkpoint_sim_period_;
451  ser& checkpoint_prefix_;
452 
453  ser& enable_sig_handling_;
454  ser& sigusr1_;
455  ser& sigusr2_;
456  ser& sigalrm_;
457  ser& print_env_;
458  ser& no_env_config_;
459  }
460  ImplementSerializable(SST::Config);
461 
462 protected:
463  std::string getUsagePrelude() override;
464  int checkArgsAfterParsing() override;
465  int positionalCallback(int num, const std::string& arg);
466 
467 private:
468  //// Items private to Config
469 
470  std::string run_name;
471  bool first_rank_;
472 
473  // Inserts all the command line options into the underlying data
474  // structures
475  void insertOptions();
476 
477  bool isFileNameOnly(const std::string& name)
478  {
479  bool nameOnly = true;
480 
481  for ( size_t i = 0; i < name.size(); ++i ) {
482  if ( '/' == name[i] ) {
483  nameOnly = false;
484  break;
485  }
486  }
487 
488  return nameOnly;
489  }
490 
491  // Variables to hold the options. Declared in order they show up
492  // in the options array
493 
494  // Information options
495  // No variable associated with help
496  // No variable associated with version
497 
498  // Basic options
499  // uint32_t verbose_; ** in ConfigShared
500  // Num threads held in RankInfo.thread
501  uint32_t num_ranks_; /*!< Number of ranks in the simulation */
502  uint32_t num_threads_; /*!< Number of threads requested */
503  std::string configFile_; /*!< Graph generation file */
504  std::string model_options_; /*!< Options to pass to Python Model generator */
505  bool print_timing_; /*!< Print SST timing information */
506  std::string stop_at_; /*!< When to stop the simulation */
507  uint32_t exit_after_; /*!< When (wall-time) to stop the simulation */
508  std::string partitioner_; /*!< Partitioner to use */
509  std::string heartbeat_sim_period_; /*!< Sets the heartbeat (simulated time) period for the simulation */
510  uint32_t heartbeat_wall_period_; /*!< Sets the heartbeat (wall-clock time) period for the simulation */
511  std::string output_directory_; /*!< Output directory to dump all files to */
512  std::string output_core_prefix_; /*!< Set the SST::Output prefix for the core */
513 
514  // Configuration output
515  std::string output_config_graph_; /*!< File to dump configuration graph */
516  std::string output_json_; /*!< File to dump JSON output */
517  bool parallel_output_; /*!< Output simulation graph in parallel */
518 
519  // Graph output
520  std::string output_dot_; /*!< File to dump dot output */
521  uint32_t dot_verbosity_; /*!< Amount of detail to include in the dot graph output */
522  std::string component_partition_file_; /*!< File to dump component graph */
523  bool output_partition_; /*!< Output paritition info when writing config output */
524 
525  // Advanced options
526  std::string timeBase_; /*!< Timebase of simulation */
527  bool parallel_load_; /*!< Load simulation graph in parallel */
528  bool parallel_load_mode_multi_; /*!< If true, load using multiple files */
529  std::string timeVortex_; /*!< TimeVortex implementation to use */
530  bool interthread_links_; /*!< Use interthread links */
531 #ifdef USE_MEMPOOL
532  bool cache_align_mempools_; /*!< Cache align allocations from mempools */
533 #endif
534  std::string debugFile_; /*!< File to which debug information should be written */
535  // std::string libpath_; ** in ConfigShared
536  // std::string addLibPath_; ** in ConfigShared
537 
538  // Advanced options - profiling
539  std::string enabled_profiling_; /*!< Enabled default profiling points */
540  std::string profiling_output_; /*!< Location to write profiling data */
541 
542  // Advanced options - debug
543  SimulationRunMode runMode_; /*!< Run Mode (Init, Both, Run-only) */
544  std::string interactive_console_; /*!< Action to use for interactive mode */
545  std::string interactive_start_time_; /*!< Time to drop into interactive mode */
546 #ifdef USE_MEMPOOL
547  std::string event_dump_file_; /*!< File to dump undeleted events to */
548 #endif
549  bool rank_seq_startup_; /*!< Run simulation initialization phases one rank at a time */
550 
551  // Advanced options - checkpoint
552  bool load_from_checkpoint_; /*!< If true, load from checkpoint instead of config file */
553  std::string checkpoint_sim_period_; /*!< Interval to generate checkpoints at in terms of the simulated clock */
554  uint32_t
555  checkpoint_wall_period_; /*!< Interval to generate checkpoints at in terms of wall-clock measured seconds */
556  std::string checkpoint_prefix_; /*!< Prefix for checkpoint filename and checkpoint directory */
557  std::string checkpoint_directory_; /*!< Directory to write checkpoints to */
558 
559  // Advanced options - environment
560  bool enable_sig_handling_; /*!< Enable signal handling */
561  std::string sigusr1_; /*!< RealTimeAction to call on a SIGUSR1 */
562  std::string sigusr2_; /*!< RealTimeAction to call on a SIGUSR2 */
563  std::string sigalrm_; /*!< RealTimeAction(s) to call on a SIGALRM */
564  // bool print_env_; ** in ConfigShared
565  // bool no_env_config_; ** in ConfigShared
566 };
567 
568 } // namespace SST
569 
570 #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:296
uint32_t heartbeat_wall_period() const
Wall-clock period at which to print out a "heartbeat" message.
Definition: config.h:142
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
bool enable_sig_handling() const
Controls whether the environment variables that SST sees are printed out.
Definition: config.h:378
uint32_t dot_verbosity() const
Level of verbosity to use for the dot output.
Definition: config.h:187
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:251
uint32_t checkpoint_wall_period() const
Interval at which to create a checkpoint in wall time.
Definition: config.h:237
const std::string & profilingOutput() const
Profiling points to turn on.
Definition: config.h:301
bool parallel_load() const
Controls whether graph constuction will be done in parallel.
Definition: config.h:214
bool parallel_output() const
If true, and a config graph output option is specified, write each ranks graph separately.
Definition: config.h:172
const std::string output_core_prefix() const
Prefix to use for the default SST::Output object in core.
Definition: config.h:152
bool canInitiateCheckpoint()
Get whether or not any of the checkpoint options were turned on.
Definition: config.cc:1159
const std::string & checkpoint_sim_period() const
Interval at which to create a checkpoint in simulated time.
Definition: config.h:241
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:182
bool output_partition() const
Controls whether partition info is output as part of configuration output.
Definition: config.h:197
const std::string & timeVortex() const
TimeVortex implementation to use.
Definition: config.h:256
const std::string & component_partition_file() const
File to output component partition info to (empty string means no output)
Definition: config.h:192
SimulationRunMode runMode() const
Run mode to use (Init, Both, Run-only).
Definition: config.h:310
Definition: serializable.h:24
const std::string & heartbeat_sim_period() const
Simulation period at which to print out a "heartbeat" message.
Definition: config.h:137
const std::string & stop_at() const
Simulated cycle to stop the simulation at.
Definition: config.h:122
const std::string & sigusr1() const
SIGUSR1 handler.
Definition: config.h:383
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:166
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:34
bool interthread_links() const
Use links that connect directly to ActivityQueue in receiving thread.
Definition: config.h:261
std::string runMode_str() const
Get string version of runmode.
Definition: config.h:315
const std::string & output_config_graph() const
File to output python formatted config graph to (empty string means no output)
Definition: config.h:160
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:221
const std::string & debugFile() const
File to which core debug information should be written.
Definition: config.h:273
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:227
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:680
uint32_t num_threads() const
Level of verbosity to use in the core prints using Output.verbose or Output.debug.
Definition: config.h:97
std::string interactive_start_time() const
Get the time to start interactive mode.
Definition: config.h:338
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:147
std::string interactive_console() const
Get the InteractiveAction to use for interactive mode.
Definition: config.h:333
const std::string & sigusr2() const
SIGUSR2 handler.
Definition: config.h:388
const std::string & sigalrm() const
SIGALRM handler(s)
Definition: config.h:393
const std::string & timeBase() const
Core timebase to use as the atomic time unit for the simulation.
Definition: config.h:206
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition: config.cc:1088
bool load_from_checkpoint() const
Returns whether the simulation will begin from a checkpoint (true) or not (false).
Definition: config.h:246
bool rank_seq_startup() const
Run simulation initialization stages one rank at a time for debug purposes.
Definition: config.h:356
ConfigShared()
Default constructor used for serialization.
Definition: configShared.h:59
const std::string & partitioner() const
Partitioner to use for parallel simulations.
Definition: config.h:132