Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
porivate functions
[simgrid.git] / src / mc / api.hpp
1 #ifndef SIMGRID_MC_API_HPP
2 #define SIMGRID_MC_API_HPP
3
4 #include <memory>
5 #include <vector>
6
7 #include "simgrid/forward.h"
8 #include "src/mc/mc_forward.hpp"
9 #include "src/mc/mc_request.hpp"
10 #include "src/mc/mc_state.hpp"
11 #include "src/mc/mc_record.hpp"
12 #include "xbt/automaton.hpp"
13 #include "xbt/base.h"
14
15 namespace simgrid {
16 namespace mc {
17
18 /*
19 ** This class aimes to implement FACADE APIs for simgrid. The FACADE layer sits between the CheckerSide
20 ** (Unfolding_Checker, DPOR, ...) layer and the
21 ** AppSide layer. The goal is to drill down into the entagled details in the CheckerSide layer and break down the
22 ** detailes in a way that the CheckerSide eventually
23 ** be capable to acquire the required information through the FACADE layer rather than the direct access to the AppSide.
24 */
25
26 class Api {
27 private:
28   Api() = default;
29
30   struct DerefAndCompareByActorsCountAndUsedHeap {
31     template <class X, class Y> bool operator()(X const& a, Y const& b) const
32     {
33       return std::make_pair(a->actors_count, a->heap_bytes_used) < std::make_pair(b->actors_count, b->heap_bytes_used);
34     }
35   };
36
37 smx_mailbox_t get_mbox(smx_simcall_t const r) const;
38 simgrid::kernel::activity::CommImpl* get_comm(smx_simcall_t const r) const;
39 bool request_depend_asymmetric(smx_simcall_t r1, smx_simcall_t r2) const;
40
41 public:
42   // No copy:
43   Api(Api const&) = delete;
44   void operator=(Api const&) = delete;
45
46   static Api& get()
47   {
48     static Api api;
49     return api;
50   }
51
52   void initialize(char** argv) const;
53
54   // ACTOR APIs  
55   std::vector<simgrid::mc::ActorInformation>& get_actors() const;
56   bool actor_is_enabled(aid_t pid) const;
57   unsigned long get_maxpid() const;
58   int get_actors_size() const;
59
60   // COMMUNICATION APIs
61   RemotePtr<kernel::activity::CommImpl> get_comm_isend_raw_addr(smx_simcall_t request) const;
62   RemotePtr<kernel::activity::CommImpl> get_comm_wait_raw_addr(smx_simcall_t request) const;
63   RemotePtr<kernel::activity::CommImpl> get_comm_waitany_raw_addr(smx_simcall_t request, int value) const;
64   std::string get_pattern_comm_rdv(RemotePtr<kernel::activity::CommImpl> const& addr) const;
65   unsigned long get_pattern_comm_src_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const;
66   unsigned long get_pattern_comm_dst_proc(RemotePtr<kernel::activity::CommImpl> const& addr) const;
67   std::vector<char> get_pattern_comm_data(RemotePtr<kernel::activity::CommImpl> const& addr) const;
68   const char* get_actor_host_name(smx_actor_t actor) const;
69 #if HAVE_SMPI
70   bool check_send_request_detached(smx_simcall_t const& simcall) const;
71 #endif
72   smx_actor_t get_src_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const;
73   smx_actor_t get_dst_actor(RemotePtr<kernel::activity::CommImpl> const& comm_addr) const;
74
75   // REMOTE APIs
76   std::size_t get_remote_heap_bytes() const;
77
78   // MODEL CHECKER APIs
79   void mc_inc_visited_states() const;
80   void mc_inc_executed_trans() const;
81   unsigned long mc_get_visited_states() const;
82   unsigned long mc_get_executed_trans() const;
83   bool mc_check_deadlock() const;
84   void mc_show_deadlock() const;
85   bool mc_is_null() const;
86   Checker* mc_get_checker() const;
87   void set_checker(Checker* const checker) const;
88   void handle_simcall(Transition const& transition) const;
89   void mc_wait_for_requests() const;
90   XBT_ATTRIB_NORETURN void mc_exit(int status) const;
91   std::string const& mc_get_host_name(std::string const& hostname) const;
92   void dump_record_path() const;
93   smx_simcall_t mc_state_choose_request(simgrid::mc::State* state) const;
94
95   // SIMCALL APIs
96   std::string request_to_string(smx_simcall_t req, int value, RequestType request_type) const;
97   std::string request_get_dot_output(smx_simcall_t req, int value) const;
98   const char *simcall_get_name(simgrid::simix::Simcall kind) const;
99   smx_actor_t simcall_get_issuer(s_smx_simcall const* req) const;
100   long simcall_get_actor_id(s_smx_simcall const* req) const;
101   smx_mailbox_t simcall_get_mbox(smx_simcall_t const req) const;
102   bool simcall_check_dependency(smx_simcall_t const req1, smx_simcall_t const req2) const;
103
104 #if HAVE_SMPI
105   int get_smpi_request_tag(smx_simcall_t const& simcall, simgrid::simix::Simcall type) const;
106 #endif
107
108   // STATE APIs
109   void restore_state(std::shared_ptr<simgrid::mc::Snapshot> system_state) const;
110   void log_state() const;
111   void restore_initial_state() const;
112
113   // SNAPSHOT APIs
114   bool snapshot_equal(const Snapshot* s1, const Snapshot* s2) const;
115   simgrid::mc::Snapshot* take_snapshot(int num_state) const;
116
117   // SESSION APIs
118   void session_initialize() const;
119   void s_close() const;
120   void execute(Transition const& transition) const;
121
122   // AUTOMATION APIs
123   #if SIMGRID_HAVE_MC
124   void automaton_load(const char *file) const;
125   #endif
126   std::vector<int> automaton_propositional_symbol_evaluate() const;
127   std::vector<xbt_automaton_state_t> get_automaton_state() const;
128   int compare_automaton_exp_label(const xbt_automaton_exp_label* l) const;
129   void set_property_automaton(xbt_automaton_state_t const& automaton_state) const;
130   inline DerefAndCompareByActorsCountAndUsedHeap compare_pair() const {
131     return DerefAndCompareByActorsCountAndUsedHeap();
132   }
133   inline int automaton_state_compare(const_xbt_automaton_state_t const& s1, const_xbt_automaton_state_t const& s2) const {
134     return xbt_automaton_state_compare(s1, s2);
135   }
136   xbt_automaton_exp_label_t get_automaton_transition_label(xbt_dynar_t const& dynar, int index) const;
137   xbt_automaton_state_t get_automaton_transition_dst(xbt_dynar_t const& dynar, int index) const;
138
139   // DYNAR APIs
140   inline unsigned long get_dynar_length(const_xbt_dynar_t const& dynar) const {
141     return xbt_dynar_length(dynar);
142   }
143 };
144
145 } // namespace mc
146 } // namespace simgrid
147
148 #endif