1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
9 #include <xbt/sysdep.h>
10 #include <xbt/dynar.h>
11 #include <xbt/dynar.hpp>
13 #include "src/mc/mc_comm_pattern.h"
14 #include "src/mc/mc_smx.h"
15 #include "src/mc/mc_xbt.hpp"
17 using simgrid::mc::remote;
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_pattern, mc,
20 "Logging specific to MC communication patterns");
24 mc_comm_pattern_t MC_comm_pattern_dup(mc_comm_pattern_t comm)
26 mc_comm_pattern_t res = new s_mc_comm_pattern_t();
27 res->index = comm->index;
28 res->type = comm->type;
29 res->comm_addr = comm->comm_addr;
31 res->data = comm->data;
32 res->dst_proc = comm->dst_proc;
33 res->dst_host = comm->dst_host;
37 xbt_dynar_t MC_comm_patterns_dup(xbt_dynar_t patterns)
39 xbt_dynar_t res = simgrid::xbt::newDeleteDynar<s_mc_comm_pattern_t>();
41 mc_comm_pattern_t comm;
43 xbt_dynar_foreach(patterns, cursor, comm) {
44 mc_comm_pattern_t copy_comm = MC_comm_pattern_dup(comm);
45 xbt_dynar_push(res, ©_comm);
51 static void MC_patterns_copy(xbt_dynar_t dest, xbt_dynar_t source)
53 xbt_dynar_reset(dest);
56 mc_comm_pattern_t comm;
57 xbt_dynar_foreach(source, cursor, comm) {
58 mc_comm_pattern_t copy_comm = MC_comm_pattern_dup(comm);
59 xbt_dynar_push(dest, ©_comm);
63 void MC_restore_communications_pattern(simgrid::mc::State* state)
65 mc_list_comm_pattern_t list_process_comm;
68 xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
69 list_process_comm->index_comm = state->communicationIndices[cursor];
71 for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
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)
78 void MC_state_copy_incomplete_communications_pattern(simgrid::mc::State* state)
80 state->incomplete_comm_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
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, ©);
89 void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
91 state->communicationIndices.clear();
92 mc_list_comm_pattern_t list_process_comm;
94 xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
95 state->communicationIndices.push_back(list_process_comm->index_comm);
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)
104 case MC_CALL_TYPE_NONE:
106 case MC_CALL_TYPE_SEND:
107 case MC_CALL_TYPE_RECV:
108 MC_get_comm_pattern(pattern, req, call_type, backtracking);
110 case MC_CALL_TYPE_WAIT:
111 case MC_CALL_TYPE_WAITANY:
113 smx_synchro_t comm_addr = nullptr;
114 if (call_type == MC_CALL_TYPE_WAIT)
115 comm_addr = simcall_comm_wait__get__comm(req);
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);
125 xbt_die("Unexpected call type %i", (int)call_type);