Logo AND Algorithmique Numérique Distribuée

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