Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] C++ification of State
[simgrid.git] / src / mc / mc_state.h
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_STATE_H
8 #define SIMGRID_MC_STATE_H
9
10 #include <list>
11 #include <memory>
12
13 #include <xbt/base.h>
14 #include <xbt/dynar.h>
15
16 #include <simgrid_config.h>
17 #include "src/simix/smx_private.h"
18 #include "src/mc/mc_snapshot.h"
19
20 namespace simgrid {
21 namespace mc {
22
23 extern XBT_PRIVATE std::unique_ptr<s_mc_global_t> initial_global_state;
24
25 /* Possible exploration status of a process in a state */
26 enum class ProcessInterleaveState {
27   no_interleave=0, /* Do not interleave (do not execute) */
28   interleave,      /* Interleave the process (one or more request) */
29   more_interleave, /* Interleave twice the process (for mc_random simcall) */
30   done             /* Already interleaved */
31 };
32
33 /* On every state, each process has an entry of the following type */
34 struct ProcessState {
35   /** Exploration control information */
36   ProcessInterleaveState state = ProcessInterleaveState::no_interleave;
37   /** Number of times that the process was interleaved */
38   unsigned int interleave_count;
39
40   bool done() const
41   {
42     return this->state == ProcessInterleaveState::done;
43   }
44   bool interleave() const {
45     return this->state == ProcessInterleaveState::interleave
46       || this->state == ProcessInterleaveState::more_interleave;
47   }
48 };
49
50 /* An exploration state.
51  *
52  *  The `executed_state` is sometimes transformed into another `internal_req`.
53  *  For example WAITANY is transformes into a WAIT and TESTANY into TEST.
54  *  See `MC_state_set_executed_request()`.
55  */
56 struct XBT_PRIVATE State {
57   /** State's exploration status by process */
58   std::vector<ProcessState> processStates;
59   s_smx_synchro_t internal_comm;        /* To be referenced by the internal_req */
60   s_smx_simcall_t internal_req;         /* Internal translation of request */
61   s_smx_simcall_t executed_req;         /* The executed request of the state */
62   int req_num = 0;                      /* The request number (in the case of a
63                                        multi-request like waitany ) */
64   std::shared_ptr<simgrid::mc::Snapshot> system_state = nullptr;      /* Snapshot of system state */
65   int num = 0;
66   int in_visited_states = 0;
67
68   // comm determinism verification (xbt_dynar_t<xbt_dynar_t<mc_comm_pattern_t>):
69   xbt_dynar_t incomplete_comm_pattern = nullptr;
70
71   // For communication determinism verification:
72   std::vector<unsigned> communicationIndices;
73
74   State();
75   ~State();
76
77   std::size_t interleaveSize() const;
78 };
79
80 XBT_PRIVATE void replay(std::list<std::unique_ptr<simgrid::mc::State>> const& stack);
81
82 }
83 }
84
85 XBT_PRIVATE simgrid::mc::State* MC_state_new(void);
86 XBT_PRIVATE void MC_state_interleave_process(simgrid::mc::State* state, smx_process_t process);
87 XBT_PRIVATE void MC_state_set_executed_request(simgrid::mc::State* state, smx_simcall_t req, int value);
88 XBT_PRIVATE smx_simcall_t MC_state_get_executed_request(simgrid::mc::State* state, int *value);
89 XBT_PRIVATE smx_simcall_t MC_state_get_internal_request(simgrid::mc::State* state);
90 XBT_PRIVATE smx_simcall_t MC_state_get_request(simgrid::mc::State* state, int *value);
91 XBT_PRIVATE void MC_state_remove_interleave_process(simgrid::mc::State* state, smx_process_t process);
92
93 #endif