Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Do not take NULL to mean 'the current address space' in dwarf expressions
[simgrid.git] / src / mc / mc_comm_pattern.c
1 /* Copyright (c) 2007-2014. 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
12 #include "mc_comm_pattern.h"
13
14 mc_comm_pattern_t MC_comm_pattern_dup(mc_comm_pattern_t comm)
15 {
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);
21   res->data_size = -1;
22   res->data = NULL;
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);
30     }
31   } else {
32     res->dst_proc = comm->dst_proc;
33     res->dst_host = comm->dst_host;
34   }
35   return res;
36 }
37
38 xbt_dynar_t MC_comm_patterns_dup(xbt_dynar_t patterns)
39 {
40   xbt_dynar_t res = xbt_dynar_new(sizeof(mc_comm_pattern_t), MC_comm_pattern_free_voidp);
41
42   mc_comm_pattern_t comm;
43   unsigned int cursor;
44   xbt_dynar_foreach(patterns, cursor, comm) {
45     mc_comm_pattern_t copy_comm = MC_comm_pattern_dup(comm);
46     xbt_dynar_push(res, &copy_comm);
47   }
48
49   return res;
50 }
51
52 void MC_restore_communications_pattern(mc_state_t state)
53 {
54   mc_list_comm_pattern_t list_process_comm;
55   unsigned int cursor;
56
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);
59   }
60
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);
65
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, &copy_comm);
70     }
71
72   }
73 }
74
75 void MC_state_copy_incomplete_communications_pattern(mc_state_t state)
76 {
77   state->incomplete_comm_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
78
79   int i;
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, &copy);
84   }
85 }
86
87 void MC_state_copy_index_communications_pattern(mc_state_t state)
88 {
89   state->index_comm = xbt_dynar_new(sizeof(unsigned int), NULL);
90   mc_list_comm_pattern_t list_process_comm;
91   unsigned int cursor;
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);
94   }
95 }
96
97 void MC_comm_pattern_free(mc_comm_pattern_t p)
98 {
99   xbt_free(p->rdv);
100   xbt_free(p->data);
101   xbt_free(p);
102   p = NULL;
103 }
104
105 static void MC_list_comm_pattern_free(mc_list_comm_pattern_t l)
106 {
107   xbt_dynar_free(&(l->list));
108   xbt_free(l);
109   l = NULL;
110 }
111
112 void MC_comm_pattern_free_voidp(void *p)
113 {
114   MC_comm_pattern_free((mc_comm_pattern_t) * (void **) p);
115 }
116
117 void MC_list_comm_pattern_free_voidp(void *p)
118 {
119   MC_list_comm_pattern_free((mc_list_comm_pattern_t) * (void **) p);
120 }