1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/mc/mc_config.hpp"
7 #include "src/mc/mc_replay.hpp"
8 #include "src/simgrid/sg_config.hpp"
9 #include <simgrid/modelchecker.h>
11 #if SIMGRID_HAVE_STATEFUL_MC
12 #include <string_view>
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_cfg);
17 static simgrid::mc::ModelCheckingMode model_checking_mode = simgrid::mc::ModelCheckingMode::NONE;
18 simgrid::mc::ModelCheckingMode simgrid::mc::get_model_checking_mode()
20 return model_checking_mode;
22 void simgrid::mc::set_model_checking_mode(simgrid::mc::ModelCheckingMode mode)
24 model_checking_mode = mode;
27 static void _mc_cfg_cb_check(const char* spec, bool more_check = true)
29 xbt_assert(_sg_cfg_init_status == 0 || MC_is_active() || MC_record_replay_is_active() || not more_check,
30 "Specifying a %s is only allowed within the model-checker. Please use simgrid-mc, or specify this option "
31 "after the replay path.",
35 /* Replay (this part is enabled even if MC it disabled) */
36 simgrid::config::Flag<std::string> _sg_mc_record_path{
37 "model-check/replay", "Model-check path to replay (as reported by SimGrid when a violation is reported)", "",
38 [](std::string_view value) {
39 if (value.empty()) // Ignore default value
41 xbt_assert(simgrid::mc::get_model_checking_mode() == simgrid::mc::ModelCheckingMode::NONE ||
42 simgrid::mc::get_model_checking_mode() == simgrid::mc::ModelCheckingMode::REPLAY,
43 "Specifying a MC replay path is not allowed when running the model-checker in mode %s. "
44 "Either remove the model-check/replay parameter, or execute your code out of simgrid-mc.",
45 to_c_str(simgrid::mc::get_model_checking_mode()));
46 simgrid::mc::set_model_checking_mode(simgrid::mc::ModelCheckingMode::REPLAY);
47 MC_record_path() = value;
50 simgrid::config::Flag<bool> _sg_mc_timeout{
51 "model-check/timeout", "Whether to enable timeouts for wait requests", false, [](bool) {
52 _mc_cfg_cb_check("value to enable/disable timeout for wait requests", not MC_record_replay_is_active());
55 int _sg_mc_max_visited_states = 0;
57 static simgrid::config::Flag<std::string> cfg_mc_reduction{
58 "model-check/reduction", "Specify the kind of exploration reduction (either none or DPOR)", "dpor",
59 [](std::string_view value) {
60 if (value != "none" && value != "dpor" && value != "sdpor" && value != "odpor" && value != "udpor")
61 xbt_die("configuration option 'model-check/reduction' must be one of the following: "
62 " 'none', 'dpor', 'sdpor', 'odpor', or 'udpor'");
65 simgrid::config::Flag<std::string> _sg_mc_strategy{
66 "model-check/strategy",
67 "Specify the the kind of heuristic to use for guided model-checking",
69 {{"none", "No specific strategy: simply pick the first available transition and act as a DFS."},
70 {"max_match_comm", "Try to minimize the number of in-fly communication by appairing matching send and receive."},
71 {"min_match_comm", "Try to maximize the number of in-fly communication by not appairing matching send and receive."},
72 {"uniform", "No specific strategy: choices are made randomly based on a uniform sampling."}
75 simgrid::config::Flag<int> _sg_mc_random_seed{"model-check/rand-seed",
76 "give a specific random seed to initialize the uniform distribution", 0,
77 [](int) { _mc_cfg_cb_check("Random seed"); }};
79 #if SIMGRID_HAVE_STATEFUL_MC
80 simgrid::config::Flag<int> _sg_mc_checkpoint{
81 "model-check/checkpoint", "Specify the amount of steps between checkpoints during stateful model-checking "
82 "(default: 0 => stateless verification). If value=1, one checkpoint is saved for each "
83 "step => faster verification, but huge memory consumption; higher values are good "
84 "compromises between speed and memory consumption.",
85 0, [](int) { _mc_cfg_cb_check("checkpointing value"); }};
87 simgrid::config::Flag<std::string> _sg_mc_property_file{
88 "model-check/property", "Name of the file containing the property, as formatted by the ltl2ba program.", "",
89 [](const std::string&) { _mc_cfg_cb_check("property"); }};
91 simgrid::config::Flag<bool> _sg_mc_comms_determinism{
92 "model-check/communications-determinism",
93 "Whether to enable the detection of communication determinism",
96 _mc_cfg_cb_check("value to enable/disable the detection of determinism in the communications schemes");
99 simgrid::config::Flag<bool> _sg_mc_send_determinism{
100 "model-check/send-determinism",
101 "Enable/disable the detection of send-determinism in the communications schemes",
104 _mc_cfg_cb_check("value to enable/disable the detection of send-determinism in the communications schemes");
107 simgrid::config::Flag<bool> _sg_mc_unfolding_checker{
108 "model-check/unfolding-checker",
109 "Whether to enable the unfolding-based dynamic partial order reduction to MPI programs", false, [](bool) {
110 _mc_cfg_cb_check("value to to enable/disable the unfolding-based dynamic partial order reduction to MPI programs");
114 simgrid::config::Flag<std::string> _sg_mc_buffering{
116 "Buffering semantic to use for MPI (only used in MC)",
118 {{"zero", "No system buffering: MPI_Send is blocking"},
119 {"infty", "Infinite system buffering: MPI_Send returns immediately"}},
120 [](std::string_view) { _mc_cfg_cb_check("buffering mode"); }};
122 simgrid::config::Flag<int> _sg_mc_max_depth{"model-check/max-depth",
123 "Maximal exploration depth (default: 1000)",
125 [](int) { _mc_cfg_cb_check("max depth value"); }};
127 static simgrid::config::Flag<int> _sg_mc_max_visited_states__{
128 "model-check/visited",
129 "Specify the number of visited state stored for state comparison reduction: any branch leading to a state that is "
130 "already stored is cut.\n"
131 "If value=5, the last 5 visited states are stored. If value=0 (the default), no state is stored and this reduction "
132 "technique is disabled.",
134 _mc_cfg_cb_check("number of stored visited states");
135 _sg_mc_max_visited_states = value;
138 simgrid::config::Flag<bool> _sg_mc_termination{
139 "model-check/termination", "Whether to enable non progressive cycle detection", false,
140 [](bool) { _mc_cfg_cb_check("value to enable/disable the detection of non progressive cycles"); }};
142 simgrid::mc::ReductionMode simgrid::mc::get_model_checking_reduction()
144 if ((cfg_mc_reduction.get() == "dpor" || cfg_mc_reduction.get() == "sdpor" || cfg_mc_reduction.get() == "odpor") &&
145 _sg_mc_max_visited_states__ > 0) {
146 XBT_INFO("Disabling DPOR since state-equality reduction is activated with 'model-check/visited'");
147 return simgrid::mc::ReductionMode::none;
150 if (cfg_mc_reduction.get() == "none") {
151 return ReductionMode::none;
152 } else if (cfg_mc_reduction.get() == "dpor") {
153 return ReductionMode::dpor;
154 } else if (cfg_mc_reduction.get() == "sdpor") {
155 return ReductionMode::sdpor;
156 } else if (cfg_mc_reduction.get() == "odpor") {
157 return ReductionMode::odpor;
158 } else if (cfg_mc_reduction.get() == "udpor") {
159 XBT_INFO("No reduction will be used: "
160 "UDPOR has a dedicated invocation 'model-check/unfolding-checker' "
161 "but is not yet fully supported in SimGrid");
162 return ReductionMode::none;
164 XBT_INFO("Unknown reduction mode: defaulting to no reduction");
165 return ReductionMode::none;