SST  15.1.0
StructuralSimulationToolkit
config.h
1 // Copyright 2009-2025 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-2025, 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 // Pull in the patchlevel for Python so we can check Python version
20 #include <cstddef>
21 #include <cstdio>
22 #include <patchlevel.h>
23 #include <string>
24 
25 /* Forward declare for Friendship */
26 extern int main(int argc, char** argv);
27 
28 
29 namespace SST {
30 class Config;
31 
32 class SSTModelDescription;
33 class UnitAlgebra;
34 
35 namespace StandardConfigParsers {
36 
37 int check_unitalgebra_store_string(std::string valid_units, std::string& var, std::string arg);
38 
39 } // namespace StandardConfigParsers
40 
41 
42 /**
43  * Class to contain SST Simulation Configuration variables.
44  *
45  * NOTE: This class needs to be serialized for the sst.x executable,
46  * but not for the sst (wrapper compiled from the boot*.{h,cc} files)
47  * executable. To avoid having to compile all the serialization code
48  * into the bootstrap executable, the Config class is the first level
49  * of class hierarchy to inherit from serializable.
50  */
52 {
53 
54 public:
55  // Main creates the config object
56  friend int ::main(int argc, char** argv);
57  friend class SSTModelDescription;
58  friend class Simulation_impl;
59 
60  /**
61  Default constructor.
62  */
63  Config();
64 
65 private:
66  /**
67  Initial Config object created with default constructor
68  */
69  void initialize(uint32_t num_ranks, bool first_rank);
70 
71  //// Functions for use in main
72 
73  /**
74  Checks for the existance of the config file. This needs to be
75  called after adding any rank numbers to the file in the case of
76  parallel loading.
77  */
78  bool checkConfigFile();
79 
80  // Function to be called from ModelDescriptions
81 
82  /** Set a configuration string to update configuration values */
83  bool setOptionFromModel(const std::string& entryName, const std::string& value);
84 
85 
86 public:
87  ~Config() {}
88 
89  // Functions to access config options. Declared in order they show
90  // up in the options array
91 
92  // Information options
93  // No variable associated with help
94  // No variable associated with version
95 
96  // Basic options
97 
98  /**
99  Level of verbosity to use in the core prints using
100  Output.verbose or Output.debug.
101 
102  ** Included in ConfigShared
103  uint32_t verbose() const { return verbose_; }
104  */
105 
106  /********************************************************************
107  Define all the options in the Config object
108 
109  This section uses the SST_CONFIG_DECLARE_OPTION macro that
110  defines both the variable (name_) and the getter function
111  (name()).
112 
113  The options should be in the same order as they appear in the
114  insertOptions() function.
115  ********************************************************************/
116 
117  /**** Informational Options ****/
118 
119  /**
120  Print the usage text
121  */
122  int parseUsage(std::string UNUSED(arg)) { return printUsage(); }
123 
124  SST_CONFIG_DECLARE_OPTION_NOVAR(usage, std::bind(&Config::parseUsage, this, std::placeholders::_1));
125 
126  /**
127  Print extended help
128  */
129  int parseHelp(std::string arg)
130  {
131  if ( !arg.empty() ) return printExtHelp(arg);
132  return printUsage();
133  }
134 
135  SST_CONFIG_DECLARE_OPTION_NOVAR(help, std::bind(&Config::parseHelp, this, std::placeholders::_1));
136 
137  /**
138  Print version info
139  */
140  static int parseVersion(std::string UNUSED(arg))
141  {
142  printf("SST-Core Version (" PACKAGE_VERSION);
143  if ( strcmp(SSTCORE_GIT_HEADSHA, PACKAGE_VERSION) ) {
144  printf(", git branch : " SSTCORE_GIT_BRANCH);
145  printf(", SHA: " SSTCORE_GIT_HEADSHA);
146  }
147  printf(")\n");
148 
149  return 1; /* Should not continue, but clean exit */
150  }
151 
152  SST_CONFIG_DECLARE_OPTION_NOVAR(version, std::bind(&Config::parseVersion, std::placeholders::_1));
153 
154 private:
155 
156  /**
157  Number of ranks in the simulation
158  */
159  uint32_t num_ranks_ = 1;
160 
161 public:
162  uint32_t num_ranks() const { return num_ranks_; }
163 
164 private:
165 
166  /**** Basic Options ****/
167 
168  /**
169  Number of threads requested
170  */
171  SST_CONFIG_DECLARE_OPTION(uint32_t, num_threads, 1, &StandardConfigParsers::from_string<uint32_t>);
172 
173  /**
174  Name of the SDL file to use to generate the simulation
175  */
176  SST_CONFIG_DECLARE_OPTION(std::string, configFile, "NONE", &StandardConfigParsers::from_string<std::string>);
177 
178  /**
179  Model options to pass to the SDL file
180  */
181  SST_CONFIG_DECLARE_OPTION(std::string, model_options, "",
182  std::bind(&StandardConfigParsers::append_string, " \"", "\"", std::placeholders::_1, std::placeholders::_2));
183 
184  /**
185  Print SST timing information after the run
186  */
187  SST_CONFIG_DECLARE_OPTION(int, print_timing, 0,
188  std::bind(&StandardConfigParsers::from_string_default<int>, std::placeholders::_1, std::placeholders::_2, 2));
189 
190  /**
191  Print SST timing information to JSON file
192  */
193  SST_CONFIG_DECLARE_OPTION(std::string, timing_json, "", &StandardConfigParsers::from_string<std::string>);
194 
195  /**
196  Simulated cycle to stop the simulation at
197  */
198  SST_CONFIG_DECLARE_OPTION(std::string, stop_at, "0ns", &StandardConfigParsers::from_string<std::string>);
199 
200  /**
201  Wall clock time (approximiate) in seconds to stop the simulation at
202  */
203  SST_CONFIG_DECLARE_OPTION(uint32_t, exit_after, 0, &StandardConfigParsers::wall_time_to_seconds);
204 
205  /**
206  Partitioner to use for parallel simulations
207  */
208  SST_CONFIG_DECLARE_OPTION(std::string, partitioner, "sst.linear", &StandardConfigParsers::element_name);
209 
210  /**
211  Wall-clock period at which to print out a "heartbeat" message
212  */
213  SST_CONFIG_DECLARE_OPTION(uint32_t, heartbeat_wall_period, 0, &StandardConfigParsers::wall_time_to_seconds);
214 
215  /**
216  Simulation period at which to print out a "heartbeat" message
217  */
218  SST_CONFIG_DECLARE_OPTION(std::string, heartbeat_sim_period, "",
219  std::bind(&StandardConfigParsers::check_unitalgebra_store_string, "s, Hz", std::placeholders::_1,
220  std::placeholders::_2));
221 
222  /**
223  The directory to be used for writing output files
224  */
225  SST_CONFIG_DECLARE_OPTION(std::string, output_directory, "", &StandardConfigParsers::from_string<std::string>);
226 
227  /**
228  Prefix to use for the default SST::Output object in core
229  */
230  SST_CONFIG_DECLARE_OPTION(
231  std::string, output_core_prefix, "@x SST Core: ", &StandardConfigParsers::from_string<std::string>);
232 
233 
234  /**** Configuration output ****/
235 
236  /**
237  File to output python formatted config graph to (empty string means no
238  output)
239  */
240  SST_CONFIG_DECLARE_OPTION(std::string, output_config_graph, "", &StandardConfigParsers::from_string<std::string>);
241 
242  /**
243  File to output json formatted config graph to (empty string means no
244  output)
245  */
246  SST_CONFIG_DECLARE_OPTION(std::string, output_json, "", &StandardConfigParsers::from_string<std::string>);
247 
248  /**
249  If true, and a config graph output option is specified, write
250  each ranks graph separately
251  */
252  int parse_parallel_output(bool& var, std::string arg)
253  {
254  if ( num_ranks_ == 1 ) return 0;
255 
256  int ret_code = StandardConfigParsers::flag_default_true(var, arg);
257  if ( ret_code != 0 ) return ret_code;
258 
259  // If parallel_output_ (var) is true, we also need output_partition_
260  // to be true.
261  if ( var ) output_partition_.value1 = true;
262  return 0;
263  }
264 
265  SST_CONFIG_DECLARE_OPTION(bool, parallel_output, false,
266  std::bind(&Config::parse_parallel_output, this, std::placeholders::_1, std::placeholders::_2));
267 
268 
269  /**** Graph output ****/
270 
271  /**
272  File to output dot formatted config graph to (empty string means no
273  output). Note, this is not a format that can be used as input for simulation
274 
275  */
276  SST_CONFIG_DECLARE_OPTION(std::string, output_dot, "", &StandardConfigParsers::from_string<std::string>);
277 
278  /**
279  Level of verbosity to use for the dot output.
280  */
281  SST_CONFIG_DECLARE_OPTION(uint32_t, dot_verbosity, 0, &StandardConfigParsers::from_string<uint32_t>);
282 
283  /**
284  Controls whether partition info is output as part of configuration output
285  */
286  int parse_output_partition(bool& output_part_flag, std::string& file_name, std::string arg)
287  {
288  if ( arg == "" ) {
289  output_part_flag = true;
290  }
291  else {
292  file_name = arg;
293  }
294  return 0;
295  }
296 
297  SST_CONFIG_DECLARE_OPTION_PAIR(bool, output_partition, false, std::string, component_partition_file, "",
298  std::bind(&Config::parse_output_partition, this, std::placeholders::_1, std::placeholders::_2,
299  std::placeholders::_3));
300  /**
301  File to output component partition info to (empty string means no output)
302  */
303  // DEC_OPTION(component_partition_file, "");
304 
305  /**** Advanced options ****/
306 
307  /**
308  Core timebase to use as the atomic time unit for the
309  simulation. It is usually best to just leave this at the
310  default (1ps)
311  */
312  static std::string ext_help_timebase();
313 
314  SST_CONFIG_DECLARE_OPTION(std::string, timeBase, "1ps",
315  std::bind(&StandardConfigParsers::check_unitalgebra_store_string, "s, Hz", std::placeholders::_1,
316  std::placeholders::_2),
317  &Config::ext_help_timebase);
318 
319 
320  /**
321  Parallel loading
322 
323  parallel_load - Controls whether graph constuction will be done
324  in parallel. If it is, then the SDL file name is modified to
325  add the rank number to the file name right before the file
326  extension, if parallel_load_mode_multi is true.
327 
328  parallel-load-mode-multi - If graph constuction will be done in
329  parallel, will use a file per rank if true, and the same file
330  for each rank if false.
331  */
332 
333  /**
334  Returns the string equivalent for parallel-load: NONE (if
335  parallel load is off), SINGLE or MULTI.
336  */
337 
338  int parse_parallel_load(bool& parallel_load, bool& parallel_load_mode_multi, std::string arg)
339  {
340  // If this is only a one rank job, then we can ignore
341  if ( num_ranks_ == 1 ) return 0;
342 
343  if ( arg == "" ) {
344  parallel_load = true;
345  return 0;
346  }
347 
348  std::string arg_lower(arg);
349  std::locale loc;
350  for ( auto& ch : arg_lower )
351  ch = std::tolower(ch, loc);
352 
353  if ( arg_lower == "none" ) {
354  parallel_load = false;
355  return 0;
356  }
357  else
358  parallel_load = true;
359 
360  if ( arg_lower == "single" )
361  parallel_load_mode_multi = false;
362  else if ( arg_lower == "multi" )
363  parallel_load_mode_multi = true;
364  else {
365  fprintf(stderr,
366  "Invalid option '%s' passed to --parallel-load. Valid options are NONE, SINGLE and MULTI.\n",
367  arg.c_str());
368  return -1;
369  }
370  return 0;
371  }
372 
373 public:
374  std::string parallel_load_str() const
375  {
376  if ( !parallel_load_.value1 ) return "NONE";
377  if ( parallel_load_.value2 ) return "MULTI";
378  return "SINGLE";
379  }
380 
381 private:
382 
383  SST_CONFIG_DECLARE_OPTION_PAIR(bool, parallel_load, false, bool, parallel_load_mode_multi, true,
384  std::bind(
385  &Config::parse_parallel_load, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
386 
387  /**
388  TimeVortex implementation to use
389  */
390  SST_CONFIG_DECLARE_OPTION(
391  std::string, timeVortex, "sst.timevortex.priority_queue", &StandardConfigParsers::from_string<std::string>);
392 
393  /**
394  Use links that connect directly to ActivityQueue in receiving thread
395  */
396  SST_CONFIG_DECLARE_OPTION(bool, interthread_links, false, &StandardConfigParsers::flag_default_true);
397 
398 
399 #ifdef USE_MEMPOOL
400  /**
401  Controls whether mempool items are cache-aligned
402 
403  */
404  SST_CONFIG_DECLARE_OPTION(bool, cache_align_mempools, false, &StandardConfigParsers::flag_default_true);
405 #endif
406  /**
407  File to which core debug information should be written
408  */
409  SST_CONFIG_DECLARE_OPTION(std::string, debugFile, "/dev/null", &StandardConfigParsers::from_string<std::string>);
410 
411  /**
412  Library path to use for finding element libraries (will replace
413  the libpath in the sstsimulator.conf file)
414 
415  ** Included in ConfigShared
416  const std::string& libpath() const { return libpath_; }
417  */
418 
419  /**
420  Paths to add to library search (adds to libpath found in
421  sstsimulator.conf file)
422 
423  ** Included in ConfigShared
424  const std::string& addLibPath() const { return addLibPath_; }
425  */
426 
427 
428 #if PY_MINOR_VERSION >= 9
429  /**
430  Controls whether the Python coverage object will be loaded
431  */
432  static std::string ext_help_enable_python_coverage();
433 
434  SST_CONFIG_DECLARE_OPTION(bool, enable_python_coverage, false, &StandardConfigParsers::flag_set_true,
435  &Config::ext_help_enable_python_coverage);
436 #endif
437 
438 
439  /**** Advanced options - Profiling ****/
440 
441  /**
442  Profiling points to turn on
443  */
444  static std::string ext_help_enable_profiling();
445 
446  SST_CONFIG_DECLARE_OPTION(std::string, enabled_profiling, "",
447  std::bind(&StandardConfigParsers::append_string, ";", "", std::placeholders::_1, std::placeholders::_2),
448  &Config::ext_help_enable_profiling);
449 
450  /**
451  Profiling points to turn on
452  */
453  SST_CONFIG_DECLARE_OPTION(
454  std::string, profiling_output, "stdout", &StandardConfigParsers::from_string<std::string>);
455 
456 
457  /**** Advanced options - Debug ****/
458 
459  /**
460  Run mode to use (Init, Both, Run-only). Note that Run-only is
461  not currently supported because there is not component level
462  checkpointing.
463  */
464  static int parseRunMode(SimulationRunMode& val, std::string arg)
465  {
466  if ( !arg.compare("init") )
467  val = SimulationRunMode::INIT;
468  else if ( !arg.compare("run") )
469  val = SimulationRunMode::RUN;
470  else if ( !arg.compare("both") )
471  val = SimulationRunMode::BOTH;
472  else {
473  fprintf(stderr, "Unknown option for --run-mode: %s\n", arg.c_str());
474  val = SimulationRunMode::UNKNOWN;
475  }
476 
477  return val != SimulationRunMode::UNKNOWN ? 0 : -1;
478  }
479 
480  SST_CONFIG_DECLARE_OPTION(SimulationRunMode, runMode, SimulationRunMode::BOTH, &Config::parseRunMode);
481 
482 public:
483  /**
484  Get string version of runmode.
485  */
486  std::string runMode_str() const
487  {
488  switch ( runMode_ ) {
489  case SimulationRunMode::INIT:
490  return "INIT";
491  case SimulationRunMode::RUN:
492  return "RUN";
493  case SimulationRunMode::BOTH:
494  return "BOTH";
495  case SimulationRunMode::UNKNOWN:
496  return "UNKNOWN";
497  }
498  return "UNKNOWN";
499  }
500 
501 private:
502 
503  /**
504  Get the InteractiveAction to use for interactive mode
505  */
506  SST_CONFIG_DECLARE_OPTION(std::string, interactive_console, "", &StandardConfigParsers::from_string<std::string>);
507 
508  /**
509  Get the time to start interactive mode
510  */
511  SST_CONFIG_DECLARE_OPTION(std::string, interactive_start_time, "",
512  std::bind(&StandardConfigParsers::from_string_default<std::string>, std::placeholders::_1,
513  std::placeholders::_2, "0"));
514 
515  /**
516  File to replay an interactive console script
517  */
518  SST_CONFIG_DECLARE_OPTION(std::string, replay_file, "", &StandardConfigParsers::from_string<std::string>);
519 
520 #ifdef USE_MEMPOOL
521  /**
522  File to output list of events that remain undeleted at the end
523  of the simulation.
524 
525  If no mempools, just reutrn empty string. This avoids a check
526  for mempools in main.cc
527  */
528  SST_CONFIG_DECLARE_OPTION(std::string, event_dump_file, "", &StandardConfigParsers::from_string<std::string>);
529 #endif
530 
531  /**
532  Run simulation initialization stages one rank at a time for
533  debug purposes
534  */
535  SST_CONFIG_DECLARE_OPTION(bool, rank_seq_startup, false, &StandardConfigParsers::flag_set_true);
536 
537 
538  /**** Advanced options - envrionment ****/
539 
540  /**
541  Controls whether the environment variables that SST sees are
542  printed out
543 
544  ** Included in ConfigShared
545  bool print_env() const { return print_env_; }
546  */
547 
548  /**
549  ** Included in ConfigShared
550  bool no_env_config() const { return no_env_config_; }
551  */
552 
553  /**
554  Controls whether signal handlers are enable or not. NOTE: the
555  sense of this variable is opposite of the command1 line option
556  (--disable-signal-handlers)
557  */
558  SST_CONFIG_DECLARE_OPTION(bool, enable_sig_handling, true, &StandardConfigParsers::flag_set_false);
559 
560  /**
561  * SIGUSR1 handler
562  */
563  static std::string ext_help_signals();
564 
565  SST_CONFIG_DECLARE_OPTION(std::string, sigusr1, "sst.rt.status.core",
566  &StandardConfigParsers::from_string<std::string>, Config::ext_help_signals);
567 
568  /**
569  * SIGUSR2 handler
570  */
571  SST_CONFIG_DECLARE_OPTION(std::string, sigusr2, "sst.rt.status.all",
572  &StandardConfigParsers::from_string<std::string>, Config::ext_help_signals);
573 
574  /**
575  * SIGALRM handler(s)
576  */
577  SST_CONFIG_DECLARE_OPTION(std::string, sigalrm, "",
578  std::bind(&StandardConfigParsers::append_string, ";", "", std::placeholders::_1, std::placeholders::_2),
579  Config::ext_help_signals);
580 
581 
582  /**** Advanced options - Checkpointing ****/
583 
584  /**
585  * Enable checkpointing for interactive debug
586  */
587  SST_CONFIG_DECLARE_OPTION(bool, checkpoint_enable, 0, &StandardConfigParsers::flag_set_true);
588 
589  /**
590  * Interval at which to create a checkpoint in wall time
591  */
592  SST_CONFIG_DECLARE_OPTION(uint32_t, checkpoint_wall_period, 0, &StandardConfigParsers::wall_time_to_seconds);
593 
594  /**
595  * Interval at which to create a checkpoint in simulated time
596  */
597  SST_CONFIG_DECLARE_OPTION(std::string, checkpoint_sim_period, "",
598  std::bind(&StandardConfigParsers::check_unitalgebra_store_string, "s, Hz", std::placeholders::_1,
599  std::placeholders::_2));
600 
601  /**
602  * Returns whether the simulation will begin from a checkpoint (true) or not (false).
603  */
604  SST_CONFIG_DECLARE_OPTION(bool, load_from_checkpoint, false, &StandardConfigParsers::flag_set_true);
605 
606  /**
607  Prefix for checkpoint filenames and directory
608  */
609  static std::string ext_help_checkpoint_prefix();
610 
611  SST_CONFIG_DECLARE_OPTION(std::string, checkpoint_prefix, "checkpoint", &StandardConfigParsers::nonempty_string,
612  &Config::ext_help_checkpoint_prefix);
613 
614  /**
615  Format for checkout filenames
616  */
617  static int parse_checkpoint_name_format(std::string& var, std::string arg);
618 
619  static std::string ext_help_checkpoint_format();
620 
621  SST_CONFIG_DECLARE_OPTION(std::string, checkpoint_name_format, "%p_%n_%t/%p_%n_%t",
622  std::bind(&Config::parse_checkpoint_name_format, std::placeholders::_1, std::placeholders::_2),
623  &Config::ext_help_checkpoint_format);
624 
625 public:
626 
627  /** Get whether or not any of the checkpoint options were turned on */
628  bool canInitiateCheckpoint();
629 
630  /** Print to stdout the current configuration */
631  void print();
632 
633  void merge_checkpoint_options(Config& other);
634 
635  void serialize_order(SST::Core::Serialization::serializer& ser) override;
636  ImplementSerializable(SST::Config);
637 
638 
639 protected:
640  std::string getUsagePrelude() override;
641  int checkArgsAfterParsing() override;
642  int positionalCallback(int num, const std::string& arg);
643 
644 private:
645  //// Items private to Config
646 
647  std::string run_name;
648  bool first_rank_ = false;
649 
650  // Inserts all the command line options into the underlying data
651  // structures
652  void insertOptions();
653 
654  bool isFileNameOnly(const std::string& name)
655  {
656  bool nameOnly = true;
657 
658  for ( size_t i = 0; i < name.size(); ++i ) {
659  if ( '/' == name[i] ) {
660  nameOnly = false;
661  break;
662  }
663  }
664 
665  return nameOnly;
666  }
667 };
668 
669 } // namespace SST
670 
671 #endif // SST_CORE_CONFIG_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
Class to contain SST Simulation Configuration variables.
Definition: config.h:51
bool canInitiateCheckpoint()
Get whether or not any of the checkpoint options were turned on.
Definition: config.cc:658
Class to contain SST Simulation Configuration variables.
Definition: configShared.h:36
Definition: action.cc:18
Definition: serializable.h:23
int checkArgsAfterParsing() override
Function that will be called at the end of parsing so that error checking can be done.
Definition: config.cc:632
int printUsage()
Called to print the help/usage message.
Definition: configBase.cc:275
int printExtHelp(const std::string &option)
Called to print the extended help for an option.
Definition: configBase.cc:388
std::string runMode_str() const
Get string version of runmode.
Definition: config.h:486
Main control class for a SST Simulation.
Definition: simulation_impl.h:122
void print()
Print to stdout the current configuration.
Definition: config.cc:287
Config()
Default constructor.
Definition: config.cc:336
int parseHelp(std::string arg)
Print extended help.
Definition: config.h:129
int parseUsage(std::string UNUSED(arg))
Level of verbosity to use in the core prints using Output.verbose or Output.debug.
Definition: config.h:122
Base class for Model Generation.
Definition: sstmodel.h:29
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition: config.cc:603
static int parseVersion(std::string UNUSED(arg))
Print version info.
Definition: config.h:140