Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
069d1cee7dedbaf40ad3b95654638e43e26e8a23
[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_STATEFUL_MC
12 #include <string_view>
13 #endif
14
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_cfg);
16
17 static simgrid::mc::ModelCheckingMode model_checking_mode = simgrid::mc::ModelCheckingMode::NONE;
18 simgrid::mc::ModelCheckingMode simgrid::mc::get_model_checking_mode()
19 {
20   return model_checking_mode;
21 }
22 void simgrid::mc::set_model_checking_mode(simgrid::mc::ModelCheckingMode mode)
23 {
24   model_checking_mode = mode;
25 }
26
27 static void _mc_cfg_cb_check(const char* spec, bool more_check = true)
28 {
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.",
32              spec);
33 }
34
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
40         return;
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;
48     }};
49
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());
53     }};
54
55 int _sg_mc_max_visited_states = 0;
56
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")
61         xbt_die("configuration option 'model-check/reduction' can only take 'none' or 'dpor' as a value");
62     }};
63
64 simgrid::config::Flag<bool> _sg_mc_sleep_set{
65     "model-check/sleep-set", "Whether to enable the use of sleep-set in the reduction algorithm", false,
66     [](bool) { _mc_cfg_cb_check("value to enable/disable the use of sleep-set in the reduction algorithm"); }};
67
68 simgrid::config::Flag<std::string> _sg_mc_strategy{
69     "model-check/strategy",
70     "Specify the the kind of heuristic to use for guided model-checking",
71     "none",
72     {{"none", "No specific strategy: simply pick the first available transistion."},
73      {"nb_wait", "Take any enabled wait transition, to reduce the distance between an async and its wait."}}};
74
75 #if SIMGRID_HAVE_STATEFUL_MC
76 simgrid::config::Flag<int> _sg_mc_checkpoint{
77     "model-check/checkpoint", "Specify the amount of steps between checkpoints during stateful model-checking "
78                               "(default: 0 => stateless verification). If value=1, one checkpoint is saved for each "
79                               "step => faster verification, but huge memory consumption; higher values are good "
80                               "compromises between speed and memory consumption.",
81     0, [](int) { _mc_cfg_cb_check("checkpointing value"); }};
82
83 simgrid::config::Flag<std::string> _sg_mc_property_file{
84     "model-check/property", "Name of the file containing the property, as formatted by the ltl2ba program.", "",
85     [](const std::string&) { _mc_cfg_cb_check("property"); }};
86
87 simgrid::config::Flag<bool> _sg_mc_comms_determinism{
88     "model-check/communications-determinism",
89     "Whether to enable the detection of communication determinism",
90     false,
91     [](bool) {
92       _mc_cfg_cb_check("value to enable/disable the detection of determinism in the communications schemes");
93     }};
94
95 simgrid::config::Flag<bool> _sg_mc_send_determinism{
96     "model-check/send-determinism",
97     "Enable/disable the detection of send-determinism in the communications schemes",
98     false,
99     [](bool) {
100       _mc_cfg_cb_check("value to enable/disable the detection of send-determinism in the communications schemes");
101     }};
102
103 simgrid::config::Flag<bool> _sg_mc_unfolding_checker{
104     "model-check/unfolding-checker",
105     "Whether to enable the unfolding-based dynamic partial order reduction to MPI programs", false, [](bool) {
106       _mc_cfg_cb_check("value to to enable/disable the unfolding-based dynamic partial order reduction to MPI programs");
107     }};
108 #endif
109
110 simgrid::config::Flag<std::string> _sg_mc_buffering{
111     "smpi/buffering",
112     "Buffering semantic to use for MPI (only used in MC)",
113     "infty",
114     {{"zero", "No system buffering: MPI_Send is blocking"},
115      {"infty", "Infinite system buffering: MPI_Send returns immediately"}},
116     [](std::string_view) { _mc_cfg_cb_check("buffering mode"); }};
117
118 simgrid::config::Flag<int> _sg_mc_max_depth{"model-check/max-depth",
119                                             "Maximal exploration depth (default: 1000)",
120                                             1000,
121                                             [](int) { _mc_cfg_cb_check("max depth value"); }};
122
123 static simgrid::config::Flag<int> _sg_mc_max_visited_states__{
124     "model-check/visited",
125     "Specify the number of visited state stored for state comparison reduction: any branch leading to a state that is "
126     "already stored is cut.\n"
127     "If value=5, the last 5 visited states are stored. If value=0 (the default), no state is stored and this reduction "
128     "technique is disabled.",
129     0, [](int value) {
130       _mc_cfg_cb_check("number of stored visited states");
131       _sg_mc_max_visited_states = value;
132     }};
133
134 simgrid::config::Flag<bool> _sg_mc_termination{
135     "model-check/termination", "Whether to enable non progressive cycle detection", false,
136     [](bool) { _mc_cfg_cb_check("value to enable/disable the detection of non progressive cycles"); }};
137
138 bool simgrid::mc::cfg_use_DPOR()
139 {
140   if (cfg_mc_reduction.get() == "dpor" && _sg_mc_max_visited_states__ > 0) {
141     XBT_INFO("Disabling DPOR since state-equality reduction is activated with 'model-check/visited'");
142     return false;
143   }
144   return cfg_mc_reduction.get() == "dpor";
145 }