Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4cd45d9e780ed5e12943a7cf78d5370b31f2194a
[simgrid.git] / src / mc / udpor_global.hpp
1 /* Copyright (c) 2007-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_UDPOR_GLOBAL_HPP
7 #define SIMGRID_MC_UDPOR_GLOBAL_HPP
8
9 #include <iostream>
10 #include <queue>
11 #include <string_view>
12
13 /* TODO: many method declared in this module are not implemented */
14
15 namespace simgrid::mc {
16
17 class UnfoldingEvent;
18 using EventSet = std::deque<UnfoldingEvent*>;
19
20 class EvtSetTools {
21 public:
22   static bool contains(const EventSet& events, const UnfoldingEvent* e);
23   static UnfoldingEvent* find(const EventSet& events, const UnfoldingEvent* e);
24   static void subtract(EventSet& events, EventSet const& otherSet);
25   static bool depends(const EventSet& events, const EventSet& otherSet);
26   static bool isEmptyIntersection(EventSet evtS1, EventSet evtS2);
27   static EventSet makeUnion(const EventSet& s1, const EventSet& s2);
28   static void pushBack(EventSet& events, UnfoldingEvent* e);
29   static void remove(EventSet& events, UnfoldingEvent* e);
30   static EventSet minus(EventSet events, UnfoldingEvent* e);
31   static EventSet plus(EventSet events, UnfoldingEvent* e);
32 };
33
34 struct s_evset_in_t {
35   EventSet causuality_events;
36   EventSet cause;
37   EventSet ancestorSet;
38 };
39
40 class Configuration {
41 public:
42   EventSet events_;
43   EventSet maxEvent;         // Events recently added to events_
44   EventSet actorMaxEvent;    // maximal events of the actors in current configuration
45   UnfoldingEvent* lastEvent; // The last added event
46
47   Configuration plus_config(UnfoldingEvent*) const;
48   void createEvts(Configuration C, EventSet& result, const std::string& trans_tag, s_evset_in_t ev_sets, bool chk,
49                   UnfoldingEvent* immPreEvt);
50   void updateMaxEvent(UnfoldingEvent*);         // update maximal events of the configuration and actors
51   UnfoldingEvent* findActorMaxEvt(int actorId); // find maximal event of a Actor whose id = actorId
52
53   UnfoldingEvent* findTestedComm(const UnfoldingEvent* testEvt); // find comm tested by action testTrans
54
55   Configuration()                     = default;
56   Configuration(const Configuration&) = default;
57   Configuration& operator=(Configuration const&) = default;
58   Configuration(Configuration&&)                 = default;
59 };
60
61 class UnfoldingEvent {
62 public:
63   UnfoldingEvent(unsigned int nb_events, std::string const& trans_tag, EventSet const& causes, int sid = -1);
64   UnfoldingEvent(const UnfoldingEvent&) = default;
65   UnfoldingEvent& operator=(UnfoldingEvent const&) = default;
66   UnfoldingEvent(UnfoldingEvent&&)                 = default;
67
68   EventSet getHistory() const;
69
70   bool isConflict(UnfoldingEvent* event, UnfoldingEvent* otherEvent) const;
71   bool concernSameComm(const UnfoldingEvent* event, const UnfoldingEvent* otherEvent) const;
72
73   // check otherEvent is in my history ?
74   bool inHistory(UnfoldingEvent* otherEvent) const;
75
76   bool isImmediateConflict1(UnfoldingEvent* evt, UnfoldingEvent* otherEvt) const;
77
78   bool conflictWithConfig(UnfoldingEvent* event, Configuration const& config) const;
79   bool operator==(const UnfoldingEvent&) const { return false; };
80   void print() const;
81
82   inline int get_state_id() const { return state_id; }
83   inline void set_state_id(int sid) { state_id = sid; }
84
85   inline std::string get_transition_tag() const { return transition_tag; }
86   inline void set_transition_tag(std::string_view tr_tag) { transition_tag = tr_tag; }
87
88 private:
89   EventSet causes; // used to store directed ancestors of event e
90   int id = -1;
91   int state_id{-1};
92   std::string transition_tag{""}; // The tag of the last transition that lead to creating the event
93   bool transition_is_IReceive(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
94   bool transition_is_ISend(const UnfoldingEvent* testedEvt, const UnfoldingEvent* SdRcEvt) const;
95   bool check_tr_concern_same_comm(bool& chk1, bool& chk2, UnfoldingEvent* evt1, UnfoldingEvent* evt2) const;
96 };
97 } // namespace simgrid::mc
98 #endif