Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Compile the safe part of MC in default mode too
[simgrid.git] / src / mc / mc_config.cpp
1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
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>
10
11 #if SIMGRID_HAVE_MC
12 #include <string_view>
13 #endif
14
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_cfg);
16
17 simgrid::mc::ModelCheckingMode simgrid::mc::model_checking_mode = simgrid::mc::ModelCheckingMode::NONE;
18
19 static void _mc_cfg_cb_check(const char* spec, bool more_check = true)
20 {
21   xbt_assert(_sg_cfg_init_status == 0 || MC_is_active() || MC_record_replay_is_active() || not more_check,
22              "Specifying a %s is only allowed within the model-checker. Please use simgrid-mc, or specify this option "
23              "after the replay path.",
24              spec);
25 }
26
27 /* Replay (this part is enabled even if MC it disabled) */
28 simgrid::config::Flag<std::string> _sg_mc_record_path{
29     "model-check/replay", "Model-check path to replay (as reported by SimGrid when a violation is reported)", "",
30     [](std::string_view value) {
31       xbt_assert(simgrid::mc::model_checking_mode == simgrid::mc::ModelCheckingMode::NONE ||
32                      simgrid::mc::model_checking_mode == simgrid::mc::ModelCheckingMode::REPLAY,
33                  "Specifying a MC replay path is not allowed when running the model-checker in mode %s. "
34                  "Either remove the model-check/replay parameter, or execute your code out of simgrid-mc.",
35                  to_c_str(simgrid::mc::model_checking_mode));
36       simgrid::mc::model_checking_mode = simgrid::mc::ModelCheckingMode::REPLAY;
37       MC_record_path()                 = value;
38     }};
39
40 simgrid::config::Flag<bool> _sg_mc_timeout{
41     "model-check/timeout", "Whether to enable timeouts for wait requests", false, [](bool) {
42       _mc_cfg_cb_check("value to enable/disable timeout for wait requests", not MC_record_replay_is_active());
43     }};
44
45 int _sg_mc_max_visited_states = 0;
46
47 static simgrid::config::Flag<std::string> cfg_mc_reduction{
48     "model-check/reduction", "Specify the kind of exploration reduction (either none or DPOR)", "dpor",
49     [](std::string_view value) {
50       if (value != "none" && value != "dpor")
51         xbt_die("configuration option 'model-check/reduction' can only take 'none' or 'dpor' as a value");
52     }};
53
54 simgrid::config::Flag<bool> _sg_mc_sleep_set{
55     "model-check/sleep-set", "Whether to enable the use of sleep-set in the reduction algorithm", false,
56     [](bool) { _mc_cfg_cb_check("value to enable/disable the use of sleep-set in the reduction algorithm"); }};
57
58 simgrid::config::Flag<std::string> _sg_mc_strategy{
59     "model-check/strategy", "Specify the the kind of heuristic to use for guided model-checking", "none",
60     [](std::string_view value) {
61       if (value != "none" && value != "nb_wait")
62         xbt_die("configuration option 'model-check/guided-mc' can only take 'none' or 'nb_wait' as a value");
63     }};
64
65 #if SIMGRID_HAVE_MC
66 simgrid::config::Flag<int> _sg_mc_checkpoint{
67     "model-check/checkpoint", "Specify the amount of steps between checkpoints during stateful model-checking "
68                               "(default: 0 => stateless verification). If value=1, one checkpoint is saved for each "
69                               "step => faster verification, but huge memory consumption; higher values are good "
70                               "compromises between speed and memory consumption.",
71     0, [](int) { _mc_cfg_cb_check("checkpointing value"); }};
72
73 simgrid::config::Flag<std::string> _sg_mc_property_file{
74     "model-check/property", "Name of the file containing the property, as formatted by the ltl2ba program.", "",
75     [](const std::string&) { _mc_cfg_cb_check("property"); }};
76
77 simgrid::config::Flag<bool> _sg_mc_comms_determinism{
78     "model-check/communications-determinism",
79     "Whether to enable the detection of communication determinism",
80     false,
81     [](bool) {
82       _mc_cfg_cb_check("value to enable/disable the detection of determinism in the communications schemes");
83     }};
84
85 simgrid::config::Flag<bool> _sg_mc_send_determinism{
86     "model-check/send-determinism",
87     "Enable/disable the detection of send-determinism in the communications schemes",
88     false,
89     [](bool) {
90       _mc_cfg_cb_check("value to enable/disable the detection of send-determinism in the communications schemes");
91     }};
92
93 simgrid::config::Flag<bool> _sg_mc_unfolding_checker{
94     "model-check/unfolding-checker",
95     "Whether to enable the unfolding-based dynamic partial order reduction to MPI programs", false, [](bool) {
96       _mc_cfg_cb_check("value to to enable/disable the unfolding-based dynamic partial order reduction to MPI programs");
97     }};
98 #endif
99
100 simgrid::config::Flag<std::string> _sg_mc_buffering{
101     "smpi/buffering",
102     "Buffering semantic to use for MPI (only used in MC)",
103     "infty",
104     {{"zero", "No system buffering: MPI_Send is blocking"},
105      {"infty", "Infinite system buffering: MPI_Send returns immediately"}},
106     [](std::string_view) { _mc_cfg_cb_check("buffering mode"); }};
107
108 simgrid::config::Flag<int> _sg_mc_max_depth{"model-check/max-depth",
109                                             "Maximal exploration depth (default: 1000)",
110                                             1000,
111                                             [](int) { _mc_cfg_cb_check("max depth value"); }};
112
113 static simgrid::config::Flag<int> _sg_mc_max_visited_states__{
114     "model-check/visited",
115     "Specify the number of visited state stored for state comparison reduction: any branch leading to a state that is "
116     "already stored is cut.\n"
117     "If value=5, the last 5 visited states are stored. If value=0 (the default), no state is stored and this reduction "
118     "technique is disabled.",
119     0, [](int value) {
120       _mc_cfg_cb_check("number of stored visited states");
121       _sg_mc_max_visited_states = value;
122     }};
123
124 simgrid::config::Flag<bool> _sg_mc_termination{
125     "model-check/termination", "Whether to enable non progressive cycle detection", false,
126     [](bool) { _mc_cfg_cb_check("value to enable/disable the detection of non progressive cycles"); }};
127
128 bool simgrid::mc::cfg_use_DPOR()
129 {
130   if (cfg_mc_reduction.get() == "dpor" && _sg_mc_max_visited_states__ > 0) {
131     XBT_INFO("Disabling DPOR since state-equality reduction is activated with 'model-check/visited'");
132     return false;
133   }
134   return cfg_mc_reduction.get() == "dpor";
135 }