Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / mc / mc_pattern.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_PATTERN_H
7 #define SIMGRID_MC_PATTERN_H
8
9 #include "src/kernel/activity/CommImpl.hpp"
10
11 namespace simgrid {
12 namespace mc {
13
14 enum class PatternCommunicationType {
15   none    = 0,
16   send    = 1,
17   receive = 2,
18 };
19
20 class PatternCommunication {
21 public:
22   int num = 0;
23   RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr{nullptr};
24   PatternCommunicationType type = PatternCommunicationType::send;
25   unsigned long src_proc        = 0;
26   unsigned long dst_proc        = 0;
27   const xbt::string* src_host   = nullptr;
28   const xbt::string* dst_host   = nullptr;
29   std::string rdv;
30   std::vector<char> data;
31   int tag   = 0;
32   int index = 0;
33
34   PatternCommunication dup() const
35   {
36     simgrid::mc::PatternCommunication res;
37     // num?
38     res.comm_addr = this->comm_addr;
39     res.type      = this->type;
40     // src_proc?
41     // dst_proc?
42     res.dst_proc = this->dst_proc;
43     res.dst_host = this->dst_host;
44     res.rdv      = this->rdv;
45     res.data     = this->data;
46     // tag?
47     res.index = this->index;
48     return res;
49   }
50 };
51
52 /* On every state, each actor has an entry of the following type.
53  * This represents both the actor and its transition because
54  *   an actor cannot have more than one enabled transition at a given time.
55  */
56 class ActorState {
57   /* Possible exploration status of an actor transition in a state.
58    * Either the checker did not consider the transition, or it was considered and still to do, or considered and done.
59    */
60   enum class InterleavingType {
61     /** This actor transition is not considered by the checker (yet?) */
62     disabled = 0,
63     /** The checker algorithm decided that this actor transitions should be done at some point */
64     todo,
65     /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
66     done,
67   };
68
69   /** Exploration control information */
70   InterleavingType state_ = InterleavingType::disabled;
71
72   /** Number of times that the process was considered to be executed */
73   unsigned int times_considered_ = 0;
74
75 public:
76   unsigned int get_times_considered() const { return times_considered_; }
77   unsigned int get_times_considered_and_inc() { return times_considered_++; }
78
79   bool is_disabled() const { return this->state_ == InterleavingType::disabled; }
80   bool is_done() const { return this->state_ == InterleavingType::done; }
81   bool is_todo() const { return this->state_ == InterleavingType::todo; }
82   /** Mark that we should try executing this process at some point in the future of the checker algorithm */
83   void mark_todo()
84   {
85     this->state_            = InterleavingType::todo;
86     this->times_considered_ = 0;
87   }
88   void set_done() { this->state_ = InterleavingType::done; }
89 };
90
91 } // namespace mc
92 } // namespace simgrid
93
94 #endif