Logo AND Algorithmique Numérique Distribuée

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