Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Rename the communication pattern types
[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 extern "C" {
23
24 simgrid::mc::PatternCommunication* MC_comm_pattern_dup(simgrid::mc::PatternCommunication* comm)
25 {
26   simgrid::mc::PatternCommunication* res = new simgrid::mc::PatternCommunication();
27   res->index = comm->index;
28   res->type = comm->type;
29   res->comm_addr = comm->comm_addr;
30   res->rdv = comm->rdv;
31   res->data = comm->data;
32   res->dst_proc = comm->dst_proc;
33   res->dst_host = comm->dst_host;
34   return res;
35 }
36
37 xbt_dynar_t MC_comm_patterns_dup(xbt_dynar_t patterns)
38 {
39   xbt_dynar_t res = simgrid::xbt::newDeleteDynar<simgrid::mc::PatternCommunication>();
40
41   simgrid::mc::PatternCommunication* comm;
42   unsigned int cursor;
43   xbt_dynar_foreach(patterns, cursor, comm) {
44     simgrid::mc::PatternCommunication* copy_comm = MC_comm_pattern_dup(comm);
45     xbt_dynar_push(res, &copy_comm);
46   }
47
48   return res;
49 }
50
51 static void MC_patterns_copy(xbt_dynar_t dest, xbt_dynar_t source)
52 {
53   xbt_dynar_reset(dest);
54
55   unsigned int cursor;
56   simgrid::mc::PatternCommunication* comm;
57   xbt_dynar_foreach(source, cursor, comm) {
58     simgrid::mc::PatternCommunication* copy_comm = MC_comm_pattern_dup(comm);
59     xbt_dynar_push(dest, &copy_comm);
60   }
61 }
62
63 void MC_restore_communications_pattern(simgrid::mc::State* state)
64 {
65   simgrid::mc::PatternCommunicationList* list_process_comm;
66   unsigned int cursor;
67
68   xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
69     list_process_comm->index_comm = state->communicationIndices[cursor];
70
71   for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
72     MC_patterns_copy(
73       xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t),
74       xbt_dynar_get_as(state->incomplete_comm_pattern, i, xbt_dynar_t)
75     );
76 }
77
78 void MC_state_copy_incomplete_communications_pattern(simgrid::mc::State* state)
79 {
80   state->incomplete_comm_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
81
82   for (unsigned i=0; i < MC_smx_get_maxpid(); i++) {
83     xbt_dynar_t comms = xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t);
84     xbt_dynar_t copy = MC_comm_patterns_dup(comms);
85     xbt_dynar_insert_at(state->incomplete_comm_pattern, i, &copy);
86   }
87 }
88
89 void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
90 {
91   state->communicationIndices.clear();
92   simgrid::mc::PatternCommunicationList* list_process_comm;
93   unsigned int cursor;
94   xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
95     state->communicationIndices.push_back(list_process_comm->index_comm);
96 }
97
98 void MC_handle_comm_pattern(
99   e_mc_call_type_t call_type, smx_simcall_t req,
100   int value, xbt_dynar_t pattern, int backtracking)
101 {
102
103   switch(call_type) {
104   case MC_CALL_TYPE_NONE:
105     break;
106   case MC_CALL_TYPE_SEND:
107   case MC_CALL_TYPE_RECV:
108     MC_get_comm_pattern(pattern, req, call_type, backtracking);
109     break;
110   case MC_CALL_TYPE_WAIT:
111   case MC_CALL_TYPE_WAITANY:
112     {
113       smx_synchro_t comm_addr = nullptr;
114       if (call_type == MC_CALL_TYPE_WAIT)
115         comm_addr = simcall_comm_wait__get__comm(req);
116       else
117         // comm_addr = REMOTE(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_synchro_t)):
118         simgrid::mc::read_element(mc_model_checker->process(), &comm_addr,
119           remote(simcall_comm_waitany__get__comms(req)), value, sizeof(comm_addr));
120       MC_complete_comm_pattern(pattern, comm_addr,
121         MC_smx_simcall_get_issuer(req)->pid, backtracking);
122     }
123     break;
124   default:
125     xbt_die("Unexpected call type %i", (int)call_type);
126   }
127
128 }
129
130 }