Logo AND Algorithmique Numérique Distribuée

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