Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Add PatternCommunication::dup()
[simgrid.git] / src / mc / mc_comm_pattern.cpp
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 #include <string.h>
8
9 #include <xbt/sysdep.h>
10 #include <xbt/dynar.h>
11 #include <xbt/dynar.hpp>
12
13 #include "src/mc/mc_comm_pattern.h"
14 #include "src/mc/mc_smx.h"
15 #include "src/mc/mc_xbt.hpp"
16
17 using simgrid::mc::remote;
18
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_pattern, mc,
20                                 "Logging specific to MC communication patterns");
21
22 static xbt_dynar_t MC_comm_patterns_dup(xbt_dynar_t patterns)
23 {
24   xbt_dynar_t res = simgrid::xbt::newDeleteDynar<simgrid::mc::PatternCommunication>();
25
26   simgrid::mc::PatternCommunication* comm;
27   unsigned int cursor;
28   xbt_dynar_foreach(patterns, cursor, comm) {
29     simgrid::mc::PatternCommunication* copy_comm = new simgrid::mc::PatternCommunication(comm->dup());
30     xbt_dynar_push(res, &copy_comm);
31   }
32
33   return res;
34 }
35
36 static void MC_patterns_copy(xbt_dynar_t dest, xbt_dynar_t source)
37 {
38   xbt_dynar_reset(dest);
39
40   unsigned int cursor;
41   simgrid::mc::PatternCommunication* comm;
42   xbt_dynar_foreach(source, cursor, comm) {
43     simgrid::mc::PatternCommunication* copy_comm = new simgrid::mc::PatternCommunication(comm->dup());
44     xbt_dynar_push(dest, &copy_comm);
45   }
46 }
47
48 void MC_restore_communications_pattern(simgrid::mc::State* state)
49 {
50   simgrid::mc::PatternCommunicationList* list_process_comm;
51   unsigned int cursor;
52
53   xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
54     list_process_comm->index_comm = state->communicationIndices[cursor];
55
56   for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
57     MC_patterns_copy(
58       xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t),
59       xbt_dynar_get_as(state->incomplete_comm_pattern, i, xbt_dynar_t)
60     );
61 }
62
63 void MC_state_copy_incomplete_communications_pattern(simgrid::mc::State* state)
64 {
65   state->incomplete_comm_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
66
67   for (unsigned i=0; i < MC_smx_get_maxpid(); i++) {
68     xbt_dynar_t comms = xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t);
69     xbt_dynar_t copy = MC_comm_patterns_dup(comms);
70     xbt_dynar_insert_at(state->incomplete_comm_pattern, i, &copy);
71   }
72 }
73
74 void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
75 {
76   state->communicationIndices.clear();
77   simgrid::mc::PatternCommunicationList* list_process_comm;
78   unsigned int cursor;
79   xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
80     state->communicationIndices.push_back(list_process_comm->index_comm);
81 }
82
83 void MC_handle_comm_pattern(
84   e_mc_call_type_t call_type, smx_simcall_t req,
85   int value, xbt_dynar_t pattern, int backtracking)
86 {
87
88   switch(call_type) {
89   case MC_CALL_TYPE_NONE:
90     break;
91   case MC_CALL_TYPE_SEND:
92   case MC_CALL_TYPE_RECV:
93     MC_get_comm_pattern(pattern, req, call_type, backtracking);
94     break;
95   case MC_CALL_TYPE_WAIT:
96   case MC_CALL_TYPE_WAITANY:
97     {
98       smx_synchro_t comm_addr = nullptr;
99       if (call_type == MC_CALL_TYPE_WAIT)
100         comm_addr = simcall_comm_wait__get__comm(req);
101       else
102         // comm_addr = REMOTE(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_synchro_t)):
103         simgrid::mc::read_element(mc_model_checker->process(), &comm_addr,
104           remote(simcall_comm_waitany__get__comms(req)), value, sizeof(comm_addr));
105       MC_complete_comm_pattern(pattern, comm_addr,
106         MC_smx_simcall_get_issuer(req)->pid, backtracking);
107     }
108     break;
109   default:
110     xbt_die("Unexpected call type %i", (int)call_type);
111   }
112
113 }