1 /* Copyright (c) 2007-2014. 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>
12 #include "mc_comm_pattern.h"
14 mc_comm_pattern_t MC_comm_pattern_dup(mc_comm_pattern_t comm)
16 mc_comm_pattern_t res = xbt_new0(s_mc_comm_pattern_t, 1);
17 res->index = comm->index;
18 res->type = comm->type;
19 res->comm = comm->comm;
20 res->rdv = strdup(comm->rdv);
23 if (comm->type == SIMIX_COMM_SEND) {
24 res->src_proc = comm->src_proc;
25 res->src_host = comm->src_host;
26 if (comm->data != NULL) {
27 res->data_size = comm->data_size;
28 res->data = xbt_malloc0(comm->data_size);
29 memcpy(res->data, comm->data, comm->data_size);
32 res->dst_proc = comm->dst_proc;
33 res->dst_host = comm->dst_host;
38 xbt_dynar_t MC_comm_patterns_dup(xbt_dynar_t patterns)
40 xbt_dynar_t res = xbt_dynar_new(sizeof(mc_comm_pattern_t), MC_comm_pattern_free_voidp);
42 mc_comm_pattern_t comm;
44 xbt_dynar_foreach(patterns, cursor, comm) {
45 mc_comm_pattern_t copy_comm = MC_comm_pattern_dup(comm);
46 xbt_dynar_push(res, ©_comm);
52 void MC_restore_communications_pattern(mc_state_t state)
54 mc_list_comm_pattern_t list_process_comm;
57 xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm){
58 list_process_comm->index_comm = (int)xbt_dynar_get_as(state->index_comm, cursor, int);
61 for (int i = 0; i < MC_smx_get_maxpid(); i++) {
62 xbt_dynar_t initial_incomplete_process_comms = xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t);
63 xbt_dynar_reset(initial_incomplete_process_comms);
64 xbt_dynar_t incomplete_process_comms = xbt_dynar_get_as(state->incomplete_comm_pattern, i, xbt_dynar_t);
66 mc_comm_pattern_t comm;
67 xbt_dynar_foreach(incomplete_process_comms, cursor, comm) {
68 mc_comm_pattern_t copy_comm = MC_comm_pattern_dup(comm);
69 xbt_dynar_push(initial_incomplete_process_comms, ©_comm);
75 void MC_state_copy_incomplete_communications_pattern(mc_state_t state)
77 state->incomplete_comm_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
80 for (i=0; i < MC_smx_get_maxpid(); i++) {
81 xbt_dynar_t comms = xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t);
82 xbt_dynar_t copy = MC_comm_patterns_dup(comms);
83 xbt_dynar_insert_at(state->incomplete_comm_pattern, i, ©);
87 void MC_state_copy_index_communications_pattern(mc_state_t state)
89 state->index_comm = xbt_dynar_new(sizeof(unsigned int), NULL);
90 mc_list_comm_pattern_t list_process_comm;
92 xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm){
93 xbt_dynar_push_as(state->index_comm, unsigned int, list_process_comm->index_comm);
97 void MC_comm_pattern_free(mc_comm_pattern_t p)
105 static void MC_list_comm_pattern_free(mc_list_comm_pattern_t l)
107 xbt_dynar_free(&(l->list));
112 void MC_comm_pattern_free_voidp(void *p)
114 MC_comm_pattern_free((mc_comm_pattern_t) * (void **) p);
117 void MC_list_comm_pattern_free_voidp(void *p)
119 MC_list_comm_pattern_free((mc_list_comm_pattern_t) * (void **) p);