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 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_cfg);
13 static simgrid::mc::ModelCheckingMode model_checking_mode = simgrid::mc::ModelCheckingMode::NONE;
14 simgrid::mc::ModelCheckingMode simgrid::mc::get_model_checking_mode()
16 return model_checking_mode;
18 void simgrid::mc::set_model_checking_mode(simgrid::mc::ModelCheckingMode mode)
20 model_checking_mode = mode;
23 static void _mc_cfg_cb_check(const char* spec, bool more_check = true)
25 xbt_assert(_sg_cfg_init_status == 0 || MC_is_active() || MC_record_replay_is_active() || not more_check,
26 "Specifying a %s is only allowed within the model-checker. Please use simgrid-mc, or specify this option "
27 "after the replay path.",
31 /* Replay (this part is enabled even if MC it disabled) */
32 simgrid::config::Flag<std::string> _sg_mc_record_path{
33 "model-check/replay", "Model-check path to replay (as reported by SimGrid when a violation is reported)", "",
34 [](std::string_view value) {
35 if (value.empty()) // Ignore default value
37 xbt_assert(simgrid::mc::get_model_checking_mode() == simgrid::mc::ModelCheckingMode::NONE ||
38 simgrid::mc::get_model_checking_mode() == simgrid::mc::ModelCheckingMode::REPLAY,
39 "Specifying a MC replay path is not allowed when running the model-checker in mode %s. "
40 "Either remove the model-check/replay parameter, or execute your code out of simgrid-mc.",
41 to_c_str(simgrid::mc::get_model_checking_mode()));
42 simgrid::mc::set_model_checking_mode(simgrid::mc::ModelCheckingMode::REPLAY);
43 MC_record_path() = value;
46 simgrid::config::Flag<bool> _sg_mc_timeout{
47 "model-check/timeout", "Whether to enable timeouts for wait requests", false, [](bool) {
48 _mc_cfg_cb_check("value to enable/disable timeout for wait requests", not MC_record_replay_is_active());
51 static simgrid::config::Flag<std::string> cfg_mc_reduction{
52 "model-check/reduction", "Specify the kind of exploration reduction (either none or DPOR)", "dpor",
53 [](std::string_view value) {
54 if (value != "none" && value != "dpor" && value != "sdpor" && value != "odpor" && value != "udpor")
55 xbt_die("configuration option 'model-check/reduction' must be one of the following: "
56 " 'none', 'dpor', 'sdpor', 'odpor', or 'udpor'");
59 simgrid::config::Flag<std::string> _sg_mc_strategy{
60 "model-check/strategy",
61 "Specify the the kind of heuristic to use for guided model-checking",
63 {{"none", "No specific strategy: simply pick the first available transition and act as a DFS."},
64 {"max_match_comm", "Try to minimize the number of in-fly communication by appairing matching send and receive."},
66 "Try to maximize the number of in-fly communication by not appairing matching send and receive."},
67 {"uniform", "No specific strategy: choices are made randomly based on a uniform sampling."}}};
69 simgrid::config::Flag<int> _sg_mc_random_seed{"model-check/rand-seed",
70 "give a specific random seed to initialize the uniform distribution", 0,
71 [](int) { _mc_cfg_cb_check("Random seed"); }};
73 simgrid::config::Flag<bool> _sg_mc_comms_determinism{
74 "model-check/communications-determinism", "Whether to enable the detection of communication determinism", false,
76 _mc_cfg_cb_check("value to enable/disable the detection of determinism in the communications schemes");
78 simgrid::config::Flag<bool> _sg_mc_send_determinism{
79 "model-check/send-determinism",
80 "Enable/disable the detection of send-determinism in the communications schemes",
83 _mc_cfg_cb_check("value to enable/disable the detection of send-determinism in the communications schemes");
86 simgrid::config::Flag<bool> _sg_mc_unfolding_checker{
87 "model-check/unfolding-checker",
88 "Whether to enable the unfolding-based dynamic partial order reduction to MPI programs", false, [](bool) {
89 _mc_cfg_cb_check("value to to enable/disable the unfolding-based dynamic partial order reduction to MPI programs");
92 simgrid::config::Flag<std::string> _sg_mc_buffering{
94 "Buffering semantic to use for MPI (only used in MC)",
96 {{"zero", "No system buffering: MPI_Send is blocking"},
97 {"infty", "Infinite system buffering: MPI_Send returns immediately"}},
98 [](std::string_view) { _mc_cfg_cb_check("buffering mode"); }};
100 simgrid::config::Flag<int> _sg_mc_max_depth{"model-check/max-depth",
101 "Maximal exploration depth (default: 1000)",
103 [](int) { _mc_cfg_cb_check("max depth value"); }};
105 simgrid::mc::ReductionMode simgrid::mc::get_model_checking_reduction()
107 if (cfg_mc_reduction.get() == "none") {
108 return ReductionMode::none;
109 } else if (cfg_mc_reduction.get() == "dpor") {
110 return ReductionMode::dpor;
111 } else if (cfg_mc_reduction.get() == "sdpor") {
112 return ReductionMode::sdpor;
113 } else if (cfg_mc_reduction.get() == "odpor") {
114 return ReductionMode::odpor;
115 } else if (cfg_mc_reduction.get() == "udpor") {
116 XBT_INFO("No reduction will be used: "
117 "UDPOR has a dedicated invocation 'model-check/unfolding-checker' "
118 "but is not yet fully supported in SimGrid");
119 return ReductionMode::none;
121 XBT_INFO("Unknown reduction mode: defaulting to no reduction");
122 return ReductionMode::none;