SST 16.0.0
Structural Simulation Toolkit
config.h
1// Copyright 2009-2026 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-2026, 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 */
26extern int main(int argc, char** argv);
27
28
29namespace SST {
30class Config;
31
33class UnitAlgebra;
34
35namespace StandardConfigParsers {
36
37int 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
54public:
55 // Main creates the config object
56 friend int ::main(int argc, char** argv);
57 friend class SSTModelDescription;
58 friend class Simulation;
59
60 /**
61 Default constructor.
62 */
63 Config();
64
65private:
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
86public:
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) != 0 ) {
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
154private:
155
156 /**
157 Number of ranks in the simulation
158 */
159 uint32_t num_ranks_ = 1;
160
161public:
162 uint32_t num_ranks() const { return num_ranks_; }
163
164private:
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 Simulated cycle to stop the simulation at
192 */
193 SST_CONFIG_DECLARE_OPTION(std::string, stop_at, "0ns", &StandardConfigParsers::from_string<std::string>);
194
195 /**
196 Wall clock time (approximiate) in seconds to stop the simulation at
197 */
198 SST_CONFIG_DECLARE_OPTION(uint32_t, exit_after, 0, &StandardConfigParsers::wall_time_to_seconds);
199
200 /**
201 Partitioner to use for parallel simulations
202 */
203 SST_CONFIG_DECLARE_OPTION(std::string, partitioner, "sst.linear", &StandardConfigParsers::element_name);
204
205 /**
206 Wall-clock period at which to print out a "heartbeat" message
207 */
208 SST_CONFIG_DECLARE_OPTION(uint32_t, heartbeat_wall_period, 0, &StandardConfigParsers::wall_time_to_seconds);
209
210 /**
211 Simulation period at which to print out a "heartbeat" message
212 */
213 SST_CONFIG_DECLARE_OPTION(std::string, heartbeat_sim_period, "",
214 std::bind(&StandardConfigParsers::check_unitalgebra_store_string, "s, Hz", std::placeholders::_1,
215 std::placeholders::_2));
216
217 /**
218 The directory to be used for writing output files
219 */
220 SST_CONFIG_DECLARE_OPTION(std::string, output_directory, "", &StandardConfigParsers::from_string<std::string>);
221
222 /**
223 Prefix to use for the default SST::Output object in core
224 */
225 SST_CONFIG_DECLARE_OPTION(
226 std::string, output_core_prefix, "#@x SST Core: ", &StandardConfigParsers::from_string<std::string>);
227
228
229 /**** Configuration output ****/
230
231 /**
232 File to output python formatted config graph to (empty string means no
233 output)
234 */
235 SST_CONFIG_DECLARE_OPTION(std::string, output_config_graph, "", &StandardConfigParsers::from_string<std::string>);
236
237 /**
238 File to output json formatted config graph to (empty string means no
239 output)
240 */
241 SST_CONFIG_DECLARE_OPTION(std::string, output_json, "", &StandardConfigParsers::from_string<std::string>);
242
243 /**
244 If true, and a config graph output option is specified, write
245 each ranks graph separately
246 */
247 int parse_parallel_output(bool& var, std::string arg)
248 {
249 if ( num_ranks_ == 1 ) return 0;
250
251 int ret_code = StandardConfigParsers::flag_default_true(var, arg);
252 if ( ret_code != 0 ) return ret_code;
253
254 // If parallel_output_ (var) is true, we also need output_partition_
255 // to be true.
256 if ( var ) output_partition_.value1 = true;
257 return 0;
258 }
259
260 SST_CONFIG_DECLARE_OPTION(bool, parallel_output, false,
261 std::bind(&Config::parse_parallel_output, this, std::placeholders::_1, std::placeholders::_2));
262
263
264 /**** Graph output ****/
265
266 /**
267 File to output dot formatted config graph to (empty string means no
268 output). Note, this is not a format that can be used as input for simulation
269
270 */
271 SST_CONFIG_DECLARE_OPTION(std::string, output_dot, "", &StandardConfigParsers::from_string<std::string>);
272
273 /**
274 Level of verbosity to use for the dot output.
275 */
276 SST_CONFIG_DECLARE_OPTION(uint32_t, dot_verbosity, 0, &StandardConfigParsers::from_string<uint32_t>);
277
278 /**
279 Controls whether partition info is output as part of configuration output
280 */
281 int parse_output_partition(bool& output_part_flag, std::string& file_name, std::string arg)
282 {
283 if ( arg == "" ) {
284 output_part_flag = true;
285 }
286 else {
287 file_name = arg;
288 }
289 return 0;
290 }
291
292 SST_CONFIG_DECLARE_OPTION_PAIR(bool, output_partition, false, std::string, component_partition_file, "",
293 std::bind(&Config::parse_output_partition, this, std::placeholders::_1, std::placeholders::_2,
294 std::placeholders::_3));
295 /**
296 File to output component partition info to (empty string means no output)
297 */
298 // DEC_OPTION(component_partition_file, "");
299
300 /**** Advanced options ****/
301
302 /**
303 Core timebase to use as the atomic time unit for the
304 simulation. It is usually best to just leave this at the
305 default (1ps)
306 */
307 static std::string ext_help_timebase();
308
309 SST_CONFIG_DECLARE_OPTION(std::string, timeBase, "1ps",
310 std::bind(&StandardConfigParsers::check_unitalgebra_store_string, "s, Hz", std::placeholders::_1,
311 std::placeholders::_2),
312 &Config::ext_help_timebase);
313
314
315 /**
316 Parallel loading
317
318 parallel_load - Controls whether graph constuction will be done
319 in parallel. If it is, then the SDL file name is modified to
320 add the rank number to the file name right before the file
321 extension, if parallel_load_mode_multi is true.
322
323 parallel-load-mode-multi - If graph constuction will be done in
324 parallel, will use a file per rank if true, and the same file
325 for each rank if false.
326 */
327
328 /**
329 Returns the string equivalent for parallel-load: NONE (if
330 parallel load is off), SINGLE or MULTI.
331 */
332
333 int parse_parallel_load(bool& parallel_load, bool& parallel_load_mode_multi, std::string arg)
334 {
335 // If this is only a one rank job, then we can ignore
336 if ( num_ranks_ == 1 ) return 0;
337
338 if ( arg == "" ) {
339 parallel_load = true;
340 return 0;
341 }
342
343 std::string arg_lower(arg);
344 std::locale loc;
345 for ( auto& ch : arg_lower )
346 ch = std::tolower(ch, loc);
347
348 if ( arg_lower == "none" ) {
349 parallel_load = false;
350 return 0;
351 }
352 else
353 parallel_load = true;
354
355 if ( arg_lower == "single" )
356 parallel_load_mode_multi = false;
357 else if ( arg_lower == "multi" )
358 parallel_load_mode_multi = true;
359 else {
360 fprintf(stderr,
361 "Invalid option '%s' passed to --parallel-load. Valid options are NONE, SINGLE and MULTI.\n",
362 arg.c_str());
363 return -1;
364 }
365 return 0;
366 }
367
368public:
369 std::string parallel_load_str() const
370 {
371 if ( !parallel_load_.value1 ) return "NONE";
372 if ( parallel_load_.value2 ) return "MULTI";
373 return "SINGLE";
374 }
375
376private:
377
378 SST_CONFIG_DECLARE_OPTION_PAIR(bool, parallel_load, false, bool, parallel_load_mode_multi, true,
379 std::bind(
380 &Config::parse_parallel_load, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
381
382 /**
383 TimeVortex implementation to use
384 */
385 SST_CONFIG_DECLARE_OPTION(
386 std::string, timeVortex, "sst.timevortex.priority_queue", &StandardConfigParsers::from_string<std::string>);
387
388 /**
389 Use links that connect directly to ActivityQueue in receiving thread
390 */
391 SST_CONFIG_DECLARE_OPTION(bool, interthread_links, false, &StandardConfigParsers::flag_default_true);
392
393
394#ifdef USE_MEMPOOL
395 /**
396 Controls whether mempool items are cache-aligned
397
398 */
399 SST_CONFIG_DECLARE_OPTION(bool, cache_align_mempools, false, &StandardConfigParsers::flag_default_true);
400#endif
401 /**
402 File to which core debug information should be written
403 */
404 SST_CONFIG_DECLARE_OPTION(std::string, debugFile, "/dev/null", &StandardConfigParsers::from_string<std::string>);
405
406 /**
407 Library path to use for finding element libraries (will replace
408 the libpath in the sstsimulator.conf file)
409
410 ** Included in ConfigShared
411 const std::string& libpath() const { return libpath_; }
412 */
413
414 /**
415 Paths to add to library search (adds to libpath found in
416 sstsimulator.conf file)
417
418 ** Included in ConfigShared
419 const std::string& addLibPath() const { return addLibPath_; }
420 */
421
422
423 /**
424 Controls whether the Python coverage object will be loaded
425 */
426 static std::string ext_help_enable_python_coverage();
427
428 SST_CONFIG_DECLARE_OPTION(bool, enable_python_coverage, false, &StandardConfigParsers::flag_set_true,
429 &Config::ext_help_enable_python_coverage);
430
431
432 /**** Advanced options - Profiling ****/
433
434 /**
435 Profiling points to turn on
436 */
437 static std::string ext_help_enable_profiling();
438
439 SST_CONFIG_DECLARE_OPTION(std::string, enabled_profiling, "",
440 std::bind(&StandardConfigParsers::append_string, ";", "", std::placeholders::_1, std::placeholders::_2),
441 &Config::ext_help_enable_profiling);
442
443 /**
444 Profiling points to turn on
445 */
446 SST_CONFIG_DECLARE_OPTION(
447 std::string, profiling_output, "stdout", &StandardConfigParsers::from_string<std::string>);
448
449
450 /**** Advanced options - Debug ****/
451
452 /**
453 Run mode to use (Init, Both, Run-only). Note that Run-only is
454 not currently supported because there is not component level
455 checkpointing.
456 */
457 static int parseRunMode(SimulationRunMode& val, std::string arg)
458 {
459 if ( !arg.compare("init") )
460 val = SimulationRunMode::INIT;
461 else if ( !arg.compare("run") )
462 val = SimulationRunMode::RUN;
463 else if ( !arg.compare("both") )
464 val = SimulationRunMode::BOTH;
465 else {
466 fprintf(stderr, "Unknown option for --run-mode: %s\n", arg.c_str());
467 val = SimulationRunMode::UNKNOWN;
468 }
469
470 return val != SimulationRunMode::UNKNOWN ? 0 : -1;
471 }
472
473 SST_CONFIG_DECLARE_OPTION(SimulationRunMode, runMode, SimulationRunMode::BOTH, &Config::parseRunMode);
474
475public:
476 /**
477 Get string version of runmode.
478 */
479 std::string runMode_str() const
480 {
481 switch ( runMode_ ) {
482 case SimulationRunMode::INIT:
483 return "INIT";
484 case SimulationRunMode::RUN:
485 return "RUN";
486 case SimulationRunMode::BOTH:
487 return "BOTH";
488 case SimulationRunMode::UNKNOWN:
489 return "UNKNOWN";
490 }
491 return "UNKNOWN";
492 }
493
494private:
495
496 /**
497 Get the InteractiveAction to use for interactive mode
498 */
499 SST_CONFIG_DECLARE_OPTION(std::string, interactive_console, "", &StandardConfigParsers::from_string<std::string>);
500
501 /**
502 Get the time to start interactive mode
503 */
504 SST_CONFIG_DECLARE_OPTION(std::string, interactive_start_time, "",
505 std::bind(&StandardConfigParsers::from_string_default<std::string>, std::placeholders::_1,
506 std::placeholders::_2, "0"));
507
508 /**
509 File to replay an interactive console script
510 */
511 SST_CONFIG_DECLARE_OPTION(std::string, replay_file, "", &StandardConfigParsers::from_string<std::string>);
512
513#ifdef USE_MEMPOOL
514 /**
515 File to output list of events that remain undeleted at the end
516 of the simulation.
517
518 If no mempools, just reutrn empty string. This avoids a check
519 for mempools in main.cc
520 */
521 SST_CONFIG_DECLARE_OPTION(std::string, event_dump_file, "", &StandardConfigParsers::from_string<std::string>);
522#endif
523
524 /**
525 Run simulation initialization stages one rank at a time for
526 debug purposes
527 */
528 SST_CONFIG_DECLARE_OPTION(bool, rank_seq_startup, false, &StandardConfigParsers::flag_set_true);
529
530
531 /**** Advanced options - envrionment ****/
532
533 /**
534 Controls whether the environment variables that SST sees are
535 printed out
536
537 ** Included in ConfigShared
538 bool print_env() const { return print_env_; }
539 */
540
541 /**
542 ** Included in ConfigShared
543 bool no_env_config() const { return no_env_config_; }
544 */
545
546 /**
547 Controls whether signal handlers are enable or not. NOTE: the
548 sense of this variable is opposite of the command1 line option
549 (--disable-signal-handlers)
550 */
551 SST_CONFIG_DECLARE_OPTION(bool, enable_sig_handling, true, &StandardConfigParsers::flag_set_false);
552
553 /**
554 * SIGUSR1 handler
555 */
556 static std::string ext_help_signals();
557
558 SST_CONFIG_DECLARE_OPTION(std::string, sigusr1, "sst.rt.status.core",
559 &StandardConfigParsers::from_string<std::string>, Config::ext_help_signals);
560
561 /**
562 * SIGUSR2 handler
563 */
564 SST_CONFIG_DECLARE_OPTION(std::string, sigusr2, "sst.rt.status.all",
565 &StandardConfigParsers::from_string<std::string>, Config::ext_help_signals);
566
567 /**
568 * SIGALRM handler(s)
569 */
570 SST_CONFIG_DECLARE_OPTION(std::string, sigalrm, "",
571 std::bind(&StandardConfigParsers::append_string, ";", "", std::placeholders::_1, std::placeholders::_2),
572 Config::ext_help_signals);
573
574
575 /**** Advanced options - Checkpointing ****/
576
577 /**
578 * Enable checkpointing for interactive debug
579 */
580 SST_CONFIG_DECLARE_OPTION(bool, checkpoint_enable, 0, &StandardConfigParsers::flag_set_true);
581
582 /**
583 * Interval at which to create a checkpoint in wall time
584 */
585 SST_CONFIG_DECLARE_OPTION(uint32_t, checkpoint_wall_period, 0, &StandardConfigParsers::wall_time_to_seconds);
586
587 /**
588 * Interval at which to create a checkpoint in simulated time
589 */
590 SST_CONFIG_DECLARE_OPTION(std::string, checkpoint_sim_period, "",
591 std::bind(&StandardConfigParsers::check_unitalgebra_store_string, "s, Hz", std::placeholders::_1,
592 std::placeholders::_2));
593
594 /**
595 * Returns whether the simulation will begin from a checkpoint (true) or not (false).
596 */
597 SST_CONFIG_DECLARE_OPTION(bool, load_from_checkpoint, false, &StandardConfigParsers::flag_set_true);
598
599 /**
600 Prefix for checkpoint filenames and directory
601 */
602 static std::string ext_help_checkpoint_prefix();
603
604 SST_CONFIG_DECLARE_OPTION(std::string, checkpoint_prefix, "checkpoint", &StandardConfigParsers::nonempty_string,
605 &Config::ext_help_checkpoint_prefix);
606
607 /**
608 Format for checkout filenames
609 */
610 static int parse_checkpoint_name_format(std::string& var, std::string arg);
611
612 static std::string ext_help_checkpoint_format();
613
614 SST_CONFIG_DECLARE_OPTION(std::string, checkpoint_name_format, "%p_%n_%t/%p_%n_%t",
615 std::bind(&Config::parse_checkpoint_name_format, std::placeholders::_1, std::placeholders::_2),
616 &Config::ext_help_checkpoint_format);
617
618public:
619
620 /** Get whether or not any of the checkpoint options were turned on */
622
623 /** Get whether or not any of the interactive options were turned on */
625
626 /** Print to stdout the current configuration */
627 void print();
628
629 void merge_checkpoint_options(Config& other);
630
631 void serialize_order(SST::Core::Serialization::serializer& ser) override;
632 ImplementSerializable(SST::Config);
633
634
635protected:
636 std::string getUsagePrelude() override;
637 int checkArgsAfterParsing() override;
638 int positionalCallback(int num, const std::string& arg);
639
640private:
641 //// Items private to Config
642
643 std::string run_name;
644 bool first_rank_ = false;
645
646 // Inserts all the command line options into the underlying data
647 // structures
648 void insertOptions();
649
650 bool isFileNameOnly(const std::string& name)
651 {
652 bool nameOnly = true;
653
654 for ( size_t i = 0; i < name.size(); ++i ) {
655 if ( '/' == name[i] ) {
656 nameOnly = false;
657 break;
658 }
659 }
660
661 return nameOnly;
662 }
663};
664
665} // namespace SST
666
667#endif // SST_CORE_CONFIG_H
int printExtHelp(const std::string &option)
Called to print the extended help for an option.
Definition configBase.cc:389
int printUsage()
Called to print the help/usage message.
Definition configBase.cc:275
ConfigShared(bool suppress_print, bool include_libpath, bool include_env, bool include_verbose)
ConfigShared constructor that it meant to be used when needing a stand alone ConfigShared (i....
Definition configShared.cc:23
Class to contain SST Simulation Configuration variables.
Definition config.h:52
int checkArgsAfterParsing() override
Function that will be called at the end of parsing so that error checking can be done.
Definition config.cc:634
static int parseVersion(std::string UNUSED(arg))
Print version info.
Definition config.h:140
bool canInitiateInteractive()
Get whether or not any of the interactive options were turned on.
Definition config.cc:669
bool canInitiateCheckpoint()
Get whether or not any of the checkpoint options were turned on.
Definition config.cc:660
Config()
Default constructor.
Definition config.cc:335
std::string runMode_str() const
Get string version of runmode.
Definition config.h:479
int parseHelp(std::string arg)
Print extended help.
Definition config.h:129
void print()
Print to stdout the current configuration.
Definition config.cc:286
std::string getUsagePrelude() override
Called to get the prelude for the help/usage message.
Definition config.cc:605
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
Definition serializable.h:25
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Base class for Model Generation.
Definition sstmodel.h:32
Performs Unit math in full precision.
Definition unitAlgebra.h:107