Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I'm glad: this prototype was not used
[simgrid.git] / src / surf / network_smpi.cpp
1 /* Copyright (c) 2013-2015. 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 <cstddef>
8
9 #include <algorithm>
10
11 #include <xbt/log.h>
12
13 #include "network_smpi.hpp"
14 #include "simgrid/sg_config.h"
15
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
17
18 xbt_dynar_t smpi_bw_factor = NULL;
19 xbt_dynar_t smpi_lat_factor = NULL;
20
21 typedef struct s_smpi_factor *smpi_factor_t;
22 typedef struct s_smpi_factor { // FIXME: s_smpi_factor_multival (defined in smpi_base) should be used instead to dedupplicate this code
23   long factor;
24   double value;
25 } s_smpi_factor_t;
26
27 xbt_dict_t gap_lookup = NULL;
28
29 static int factor_cmp(const void *pa, const void *pb)
30 {
31   return (((s_smpi_factor_t*)pa)->factor > ((s_smpi_factor_t*)pb)->factor) ? 1 :
32       (((s_smpi_factor_t*)pa)->factor < ((s_smpi_factor_t*)pb)->factor) ? -1 : 0;
33 }
34
35 #include "src/surf/xml/platf.hpp" // FIXME: move that back to the parsing area
36 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
37 {
38   char *value = NULL;
39   unsigned int iter = 0;
40   s_smpi_factor_t fact;
41   xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
42
43   smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
44   radical_elements = xbt_str_split(smpi_coef_string, ";");
45   xbt_dynar_foreach(radical_elements, iter, value) {
46
47     radical_elements2 = xbt_str_split(value, ":");
48     surf_parse_assert(xbt_dynar_length(radical_elements2) == 2,
49         "Malformed radical '%s' for smpi factor. I was expecting something like 'a:b'", value);
50
51     char *errmsg = bprintf("Invalid factor in chunk #%d: %%s", iter+1);
52     fact.factor = xbt_str_parse_int(xbt_dynar_get_as(radical_elements2, 0, char *), errmsg);
53     xbt_free(errmsg);
54     fact.value = xbt_str_parse_double(xbt_dynar_get_as(radical_elements2, 1, char *), errmsg);
55     errmsg = bprintf("Invalid factor value in chunk #%d: %%s", iter+1);
56     xbt_free(errmsg);
57
58     xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
59     XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
60     xbt_dynar_free(&radical_elements2);
61   }
62   xbt_dynar_free(&radical_elements);
63   xbt_dynar_sort(smpi_factor, &factor_cmp);
64   xbt_dynar_foreach(smpi_factor, iter, fact) {
65     XBT_DEBUG("ordered smpi_factor:\t%ld : %f", fact.factor, fact.value);
66
67   }
68   return smpi_factor;
69 }
70
71 /*********
72  * Model *
73  *********/
74
75 /************************************************************************/
76 /* New model based on LV08 and experimental results of MPI ping-pongs   */
77 /************************************************************************/
78 /* @Inproceedings{smpi_ipdps, */
79 /*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
80 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
81 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
82 /*  address={Anchorage (Alaska) USA}, */
83 /*  month=may, */
84 /*  year={2011} */
85 /*  } */
86 void surf_network_model_init_SMPI(void)
87 {
88
89   if (surf_network_model)
90     return;
91   simgrid::surf::on_link.connect(netlink_parse_init);
92   surf_network_model = new simgrid::surf::NetworkSmpiModel();
93   xbt_dynar_push(all_existing_models, &surf_network_model);
94
95   xbt_cfg_setdefault_double(_sg_cfg_set, "network/sender_gap", 10e-6);
96   xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775);
97 }
98
99 namespace simgrid {
100   namespace surf {
101
102     NetworkSmpiModel::NetworkSmpiModel()
103     : NetworkCm02Model() {
104       m_haveGap=true;
105     }
106
107     NetworkSmpiModel::~NetworkSmpiModel(){
108       xbt_dict_free(&gap_lookup);
109       xbt_dynar_free(&smpi_bw_factor);
110       xbt_dynar_free(&smpi_lat_factor);
111     }
112
113     void NetworkSmpiModel::gapAppend(double size, Link* link, NetworkAction *act)
114     {
115       const char *src = link->getName();
116       xbt_fifo_t fifo;
117       NetworkCm02Action *action= static_cast<NetworkCm02Action*>(act);
118
119       if (sg_sender_gap > 0.0) {
120         if (!gap_lookup) {
121           gap_lookup = xbt_dict_new_homogeneous(NULL);
122         }
123         fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
124         action->m_senderGap = 0.0;
125         if (fifo && xbt_fifo_size(fifo) > 0) {
126           /* Compute gap from last send */
127           /*last_action =
128           (surf_action_network_CM02_t)
129           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));*/
130           // bw = net_get_link_bandwidth(link);
131           action->m_senderGap = sg_sender_gap;
132           /*  max(sg_sender_gap,last_action->sender.size / bw);*/
133           action->m_latency += action->m_senderGap;
134         }
135         /* Append action as last send */
136         /*action->sender.link_name = link->lmm_resource.generic_resource.name;
137     fifo =
138         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
139                                           action->sender.link_name);
140     if (!fifo) {
141       fifo = xbt_fifo_new();
142       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
143     }
144     action->sender.fifo_item = xbt_fifo_push(fifo, action);*/
145         action->m_senderSize = size;
146       }
147     }
148
149     void NetworkSmpiModel::gapRemove(Action *lmm_action)
150     {
151       xbt_fifo_t fifo;
152       size_t size;
153       NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_action);
154
155       if (sg_sender_gap > 0.0 && action->p_senderLinkName
156           && action->p_senderFifoItem) {
157         fifo =
158             (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
159                 action->p_senderLinkName);
160         xbt_fifo_remove_item(fifo, action->p_senderFifoItem);
161         size = xbt_fifo_size(fifo);
162         if (size == 0) {
163           xbt_fifo_free(fifo);
164           xbt_dict_remove(gap_lookup, action->p_senderLinkName);
165           size = xbt_dict_length(gap_lookup);
166           if (size == 0) {
167             xbt_dict_free(&gap_lookup);
168           }
169         }
170       }
171     }
172
173     double NetworkSmpiModel::bandwidthFactor(double size)
174     {
175       if (!smpi_bw_factor)
176         smpi_bw_factor =
177             parse_factor(sg_cfg_get_string("smpi/bw_factor"));
178
179       unsigned int iter = 0;
180       s_smpi_factor_t fact;
181       double current=1.0;
182       xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
183         if (size <= fact.factor) {
184           XBT_DEBUG("%f <= %ld return %f", size, fact.factor, current);
185           return current;
186         }else
187           current=fact.value;
188       }
189       XBT_DEBUG("%f > %ld return %f", size, fact.factor, current);
190
191       return current;
192     }
193
194     double NetworkSmpiModel::latencyFactor(double size)
195     {
196       if (!smpi_lat_factor)
197         smpi_lat_factor =
198             parse_factor(sg_cfg_get_string("smpi/lat_factor"));
199
200       unsigned int iter = 0;
201       s_smpi_factor_t fact;
202       double current=1.0;
203       xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
204         if (size <= fact.factor) {
205           XBT_DEBUG("%f <= %ld return %f", size, fact.factor, current);
206           return current;
207         }else
208           current=fact.value;
209       }
210       XBT_DEBUG("%f > %ld return %f", size, fact.factor, current);
211
212       return current;
213     }
214
215     double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
216     {
217       return rate < 0 ? bound : std::min(bound, rate * bandwidthFactor(size));
218     }
219
220     /************
221      * Resource *
222      ************/
223
224
225
226     /**********
227      * Action *
228      **********/
229
230   }
231 }