Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill 2 more functions from mc::api
[simgrid.git] / src / mc / api.hpp
1 /* Copyright (c) 2020-2022. 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 #ifndef SIMGRID_MC_API_HPP
7 #define SIMGRID_MC_API_HPP
8
9 #include <memory>
10 #include <vector>
11
12 #include "simgrid/forward.h"
13 #include "src/mc/api/RemoteApp.hpp"
14 #include "src/mc/api/State.hpp"
15 #include "src/mc/mc_forward.hpp"
16 #include "src/mc/mc_record.hpp"
17 #include "xbt/automaton.hpp"
18 #include "xbt/base.h"
19
20 namespace simgrid::mc {
21
22 XBT_DECLARE_ENUM_CLASS(ExplorationAlgorithm, Safety, UDPOR, Liveness, CommDeterminism);
23
24 /*
25 ** This class aimes to implement FACADE APIs for simgrid. The FACADE layer sits between the CheckerSide
26 ** (Unfolding_Checker, DPOR, ...) layer and the
27 ** AppSide layer. The goal is to drill down into the entagled details in the CheckerSide layer and break down the
28 ** detailes in a way that the CheckerSide eventually
29 ** be capable to acquire the required information through the FACADE layer rather than the direct access to the AppSide.
30 */
31
32 class Api {
33 private:
34   Api() = default;
35
36   struct DerefAndCompareByActorsCountAndUsedHeap {
37     template <class X, class Y> bool operator()(X const& a, Y const& b) const
38     {
39       return std::make_pair(a->actor_count_, a->heap_bytes_used) < std::make_pair(b->actor_count_, b->heap_bytes_used);
40     }
41   };
42
43   std::unique_ptr<simgrid::mc::RemoteApp> remote_app_;
44
45 public:
46   // No copy:
47   Api(Api const&) = delete;
48   void operator=(Api const&) = delete;
49
50   static Api& get()
51   {
52     static Api api;
53     return api;
54   }
55
56   simgrid::mc::Exploration* initialize(char** argv, const std::unordered_map<std::string, std::string>& env,
57                                        simgrid::mc::ExplorationAlgorithm algo);
58
59   // REMOTE APIs
60   std::size_t get_remote_heap_bytes() const;
61
62   // STATE APIs
63   void restore_state(const Snapshot* system_state) const;
64
65   // SNAPSHOT APIs
66   bool snapshot_equal(const Snapshot* s1, const Snapshot* s2) const;
67   simgrid::mc::Snapshot* take_snapshot(long num_state) const;
68
69   // AUTOMATION APIs
70   inline DerefAndCompareByActorsCountAndUsedHeap compare_pair() const
71   {
72     return DerefAndCompareByActorsCountAndUsedHeap();
73   }
74 };
75
76 } // namespace simgrid::mc
77
78 #endif