Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace surf by surf++ and make it compile
[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
75   xbt_dynar_push(model_list, &surf_network_model);
76
77   xbt_cfg_setdefault_double(_sg_cfg_set, "network/sender_gap", 10e-6);
78   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
79 }
80
81 void NetworkSmpiModel::gapAppend(double size, const NetworkCm02LinkLmmPtr link, NetworkCm02ActionLmmPtr action)
82 {
83   const char *src = link->m_name;
84   xbt_fifo_t fifo;
85   //surf_action_network_CM02_t last_action;
86   //double bw;
87
88   if (sg_sender_gap > 0.0) {
89     if (!gap_lookup) {
90       gap_lookup = xbt_dict_new();
91     }
92     fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
93     action->m_senderGap = 0.0;
94     if (fifo && xbt_fifo_size(fifo) > 0) {
95       /* Compute gap from last send */
96       /*last_action =
97           (surf_action_network_CM02_t)
98           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));*/
99      // bw = net_get_link_bandwidth(link);
100       action->m_senderGap = sg_sender_gap;
101         /*  max(sg_sender_gap,last_action->sender.size / bw);*/
102       action->m_latency += action->m_senderGap;
103     }
104     /* Append action as last send */
105     /*action->sender.link_name = link->lmm_resource.generic_resource.name;
106     fifo =
107         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
108                                           action->sender.link_name);
109     if (!fifo) {
110       fifo = xbt_fifo_new();
111       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
112     }
113     action->sender.fifo_item = xbt_fifo_push(fifo, action);*/
114     action->m_senderSize = size;
115   }
116 }
117
118 void NetworkSmpiModel::gapRemove(ActionLmmPtr lmm_action)
119 {
120   xbt_fifo_t fifo;
121   size_t size;
122   NetworkCm02ActionLmmPtr action = (NetworkCm02ActionLmmPtr)(lmm_action);
123
124   if (sg_sender_gap > 0.0 && action->p_senderLinkName
125       && action->p_senderFifoItem) {
126     fifo =
127         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
128                                           action->p_senderLinkName);
129     xbt_fifo_remove_item(fifo, action->p_senderFifoItem);
130     size = xbt_fifo_size(fifo);
131     if (size == 0) {
132       xbt_fifo_free(fifo);
133       xbt_dict_remove(gap_lookup, action->p_senderLinkName);
134       size = xbt_dict_length(gap_lookup);
135       if (size == 0) {
136         xbt_dict_free(&gap_lookup);
137       }
138     }
139   }
140 }
141
142 double NetworkSmpiModel::latencyFactor(double size)
143 {
144   if (!smpi_bw_factor)
145     smpi_bw_factor =
146         parse_factor(sg_cfg_get_string("smpi/bw_factor"));
147
148   unsigned int iter = 0;
149   s_smpi_factor_t fact;
150   double current=1.0;
151   xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
152     if (size <= fact.factor) {
153       XBT_DEBUG("%lf <= %ld return %f", size, fact.factor, current);
154       return current;
155     }else
156       current=fact.value;
157   }
158   XBT_DEBUG("%lf > %ld return %f", size, fact.factor, current);
159
160   return current;
161 }
162 double NetworkSmpiModel::bandwidthFactor(double size)
163 {
164   if (!smpi_lat_factor)
165     smpi_lat_factor =
166         parse_factor(sg_cfg_get_string("smpi/lat_factor"));
167
168   unsigned int iter = 0;
169   s_smpi_factor_t fact;
170   double current=1.0;
171   xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
172     if (size <= fact.factor) {
173       XBT_DEBUG("%lf <= %ld return %f", size, fact.factor, current);
174       return current;
175     }else
176       current=fact.value;
177   }
178   XBT_DEBUG("%lf > %ld return %f", size, fact.factor, current);
179
180   return current;
181 }
182
183 double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
184 {
185   return rate < 0 ? bound : min(bound, rate * bandwidthFactor(size));
186 }
187
188 /************
189  * Resource *
190  ************/
191
192
193
194 /**********
195  * Action *
196  **********/