Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill a bunch of empty ctor/dtor
[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 #include <algorithm>
9
10 #include <xbt/log.h>
11
12 #include "network_smpi.hpp"
13 #include "simgrid/sg_config.h"
14 #include "smpi/smpi_utils.hpp"
15
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network);
17
18 std::vector<s_smpi_factor_t> smpi_bw_factor;
19 std::vector<s_smpi_factor_t> smpi_lat_factor;
20
21 xbt_dict_t gap_lookup = nullptr;
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 #include "src/surf/xml/platf.hpp" // FIXME: move that back to the parsing area
30
31 /*********
32  * Model *
33  *********/
34
35 /************************************************************************/
36 /* New model based on LV08 and experimental results of MPI ping-pongs   */
37 /************************************************************************/
38 /* @Inproceedings{smpi_ipdps, */
39 /*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
40 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
41 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
42 /*  address={Anchorage (Alaska) USA}, */
43 /*  month=may, */
44 /*  year={2011} */
45 /*  } */
46 void surf_network_model_init_SMPI()
47 {
48   if (surf_network_model)
49     return;
50   surf_network_model = new simgrid::surf::NetworkSmpiModel();
51   all_existing_models->push_back(surf_network_model);
52
53   xbt_cfg_setdefault_double("network/sender-gap", 10e-6);
54   xbt_cfg_setdefault_double("network/weight-S", 8775);
55 }
56
57 namespace simgrid {
58   namespace surf {
59
60   NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
61   {
62     haveGap_ = true;
63     }
64
65     NetworkSmpiModel::~NetworkSmpiModel()
66     {
67       xbt_dict_free(&gap_lookup);
68     }
69
70     void NetworkSmpiModel::gapAppend(double size, Link* link, NetworkAction *act)
71     {
72       const char *src = link->getName();
73       xbt_fifo_t fifo;
74       NetworkCm02Action *action= static_cast<NetworkCm02Action*>(act);
75
76       if (sg_sender_gap > 0.0) {
77         if (!gap_lookup) {
78           gap_lookup = xbt_dict_new_homogeneous(nullptr);
79         }
80         fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
81         action->senderGap_ = 0.0;
82         if (fifo && xbt_fifo_size(fifo) > 0) {
83           /* Compute gap from last send */
84           /*last_action =
85           (surf_action_network_CM02_t)
86           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));*/
87           // bw = net_get_link_bandwidth(link);
88           action->senderGap_ = sg_sender_gap;
89           /*  max(sg_sender_gap,last_action->sender.size / bw);*/
90           action->latency_ += action->senderGap_;
91         }
92         /* Append action as last send */
93         /*action->sender.link_name = link->lmm_resource.generic_resource.name;
94     fifo =
95         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
96                                           action->sender.link_name);
97     if (!fifo) {
98       fifo = xbt_fifo_new();
99       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, nullptr);
100     }
101     action->sender.fifo_item = xbt_fifo_push(fifo, action);*/
102         action->senderSize_ = size;
103       }
104     }
105
106     void NetworkSmpiModel::gapRemove(Action *lmm_action)
107     {
108       xbt_fifo_t fifo;
109       size_t size;
110       NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_action);
111
112       if (sg_sender_gap > 0.0 && action->senderLinkName_
113           && action->senderFifoItem_) {
114         fifo =
115             (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
116                 action->senderLinkName_);
117         xbt_fifo_remove_item(fifo, action->senderFifoItem_);
118         size = xbt_fifo_size(fifo);
119         if (size == 0) {
120           xbt_fifo_free(fifo);
121           xbt_dict_remove(gap_lookup, action->senderLinkName_);
122           size = xbt_dict_length(gap_lookup);
123           if (size == 0) {
124             xbt_dict_free(&gap_lookup);
125           }
126         }
127       }
128     }
129
130     double NetworkSmpiModel::bandwidthFactor(double size)
131     {
132       if (smpi_bw_factor.empty())
133         smpi_bw_factor = parse_factor(xbt_cfg_get_string("smpi/bw-factor"));
134
135       double current=1.0;
136       for (auto fact: smpi_bw_factor) {
137         if (size <= fact.factor) {
138           XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
139           return current;
140         }else
141           current=fact.values.front();
142       }
143       XBT_DEBUG("%f > %zu return %f", size, smpi_bw_factor.back().factor, current);
144
145       return current;
146     }
147
148     double NetworkSmpiModel::latencyFactor(double size)
149     {
150       if (smpi_lat_factor.empty())
151         smpi_lat_factor = parse_factor(xbt_cfg_get_string("smpi/lat-factor"));
152
153       double current=1.0;
154       for (auto fact: smpi_lat_factor) {
155         if (size <= fact.factor) {
156           XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
157           return current;
158         }else
159           current=fact.values.front();
160       }
161       XBT_DEBUG("%f > %zu return %f", size, smpi_lat_factor.back().factor, current);
162
163       return current;
164     }
165
166     double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
167     {
168       return rate < 0 ? bound : std::min(bound, rate * bandwidthFactor(size));
169     }
170
171     /************
172      * Resource *
173      ************/
174
175
176
177     /**********
178      * Action *
179      **********/
180
181   }
182 }