Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ee6e415d360fd489b9f4775361bba25bd96f3ac0
[simgrid.git] / src / surf / network_smpi.cpp
1 #include "network_smpi.hpp"
2 #include "simgrid/sg_config.h"
3
4 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
5
6 xbt_dynar_t smpi_bw_factor = NULL;
7 xbt_dynar_t smpi_lat_factor = NULL;
8
9 typedef struct s_smpi_factor *smpi_factor_t;
10 typedef struct s_smpi_factor {
11   long factor;
12   double value;
13 } s_smpi_factor_t;
14
15 xbt_dict_t gap_lookup = NULL;
16
17 static int factor_cmp(const void *pa, const void *pb)
18 {
19   return (((s_smpi_factor_t*)pa)->factor > ((s_smpi_factor_t*)pb)->factor);
20 }
21
22
23 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
24 {
25   char *value = NULL;
26   unsigned int iter = 0;
27   s_smpi_factor_t fact;
28   xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
29
30   smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
31   radical_elements = xbt_str_split(smpi_coef_string, ";");
32   xbt_dynar_foreach(radical_elements, iter, value) {
33
34     radical_elements2 = xbt_str_split(value, ":");
35     if (xbt_dynar_length(radical_elements2) != 2)
36       xbt_die("Malformed radical for smpi factor!");
37     fact.factor = atol(xbt_dynar_get_as(radical_elements2, 0, char *));
38     fact.value = atof(xbt_dynar_get_as(radical_elements2, 1, char *));
39     xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
40     XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
41     xbt_dynar_free(&radical_elements2);
42   }
43   xbt_dynar_free(&radical_elements);
44   iter=0;
45   xbt_dynar_sort(smpi_factor, &factor_cmp);
46   xbt_dynar_foreach(smpi_factor, iter, fact) {
47     XBT_DEBUG("ordered smpi_factor:\t%ld : %f", fact.factor, fact.value);
48
49   }
50   return smpi_factor;
51 }
52
53 /*********
54  * Model *
55  *********/
56
57 /************************************************************************/
58 /* New model based on LV08 and experimental results of MPI ping-pongs   */
59 /************************************************************************/
60 /* @Inproceedings{smpi_ipdps, */
61 /*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
62 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
63 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
64 /*  address={Anchorage (Alaska) USA}, */
65 /*  month=may, */
66 /*  year={2011} */
67 /*  } */
68 void surf_network_model_init_SMPI(void)
69 {
70
71   if (surf_network_model)
72     return;
73   surf_network_model = new NetworkSmpiModel();
74   net_define_callbacks();
75   xbt_dynar_push(model_list, &surf_network_model);
76   //network_solve = lmm_solve;
77
78   xbt_cfg_setdefault_double(_sg_cfg_set, "network/sender_gap", 10e-6);
79   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
80 }
81
82 void NetworkSmpiModel::gapAppend(double size, const NetworkCm02LinkLmmPtr link, NetworkCm02ActionLmmPtr action)
83 {
84   const char *src = link->m_name;
85   xbt_fifo_t fifo;
86   //surf_action_network_CM02_t last_action;
87   //double bw;
88
89   if (sg_sender_gap > 0.0) {
90     if (!gap_lookup) {
91       gap_lookup = xbt_dict_new_homogeneous(NULL);
92     }
93     fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
94     action->m_senderGap = 0.0;
95     if (fifo && xbt_fifo_size(fifo) > 0) {
96       /* Compute gap from last send */
97       /*last_action =
98           (surf_action_network_CM02_t)
99           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));*/
100      // bw = net_get_link_bandwidth(link);
101       action->m_senderGap = sg_sender_gap;
102         /*  max(sg_sender_gap,last_action->sender.size / bw);*/
103       action->m_latency += action->m_senderGap;
104     }
105     /* Append action as last send */
106     /*action->sender.link_name = link->lmm_resource.generic_resource.name;
107     fifo =
108         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
109                                           action->sender.link_name);
110     if (!fifo) {
111       fifo = xbt_fifo_new();
112       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
113     }
114     action->sender.fifo_item = xbt_fifo_push(fifo, action);*/
115     action->m_senderSize = size;
116   }
117 }
118
119 void NetworkSmpiModel::gapRemove(ActionLmmPtr lmm_action)
120 {
121   xbt_fifo_t fifo;
122   size_t size;
123   NetworkCm02ActionLmmPtr action = (NetworkCm02ActionLmmPtr)(lmm_action);
124
125   if (sg_sender_gap > 0.0 && action->p_senderLinkName
126       && action->p_senderFifoItem) {
127     fifo =
128         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
129                                           action->p_senderLinkName);
130     xbt_fifo_remove_item(fifo, action->p_senderFifoItem);
131     size = xbt_fifo_size(fifo);
132     if (size == 0) {
133       xbt_fifo_free(fifo);
134       xbt_dict_remove(gap_lookup, action->p_senderLinkName);
135       size = xbt_dict_length(gap_lookup);
136       if (size == 0) {
137         xbt_dict_free(&gap_lookup);
138       }
139     }
140   }
141 }
142
143 double NetworkSmpiModel::bandwidthFactor(double size)
144 {
145   if (!smpi_bw_factor)
146     smpi_bw_factor =
147         parse_factor(sg_cfg_get_string("smpi/bw_factor"));
148
149   unsigned int iter = 0;
150   s_smpi_factor_t fact;
151   double current=1.0;
152   xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
153     if (size <= fact.factor) {
154       XBT_DEBUG("%f <= %ld return %f", size, fact.factor, current);
155       return current;
156     }else
157       current=fact.value;
158   }
159   XBT_DEBUG("%f > %ld return %f", size, fact.factor, current);
160
161   return current;
162 }
163 double NetworkSmpiModel::latencyFactor(double size)
164 {
165   if (!smpi_lat_factor)
166     smpi_lat_factor =
167         parse_factor(sg_cfg_get_string("smpi/lat_factor"));
168
169   unsigned int iter = 0;
170   s_smpi_factor_t fact;
171   double current=1.0;
172   xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
173     if (size <= fact.factor) {
174       XBT_DEBUG("%f <= %ld return %f", size, fact.factor, current);
175       return current;
176     }else
177       current=fact.value;
178   }
179   XBT_DEBUG("%f > %ld return %f", size, fact.factor, current);
180
181   return current;
182 }
183
184 double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
185 {
186   return rate < 0 ? bound : min(bound, rate * bandwidthFactor(size));
187 }
188
189 /************
190  * Resource *
191  ************/
192
193
194
195 /**********
196  * Action *
197  **********/