Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix log format
[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()
61     : NetworkCm02Model() {
62       haveGap_=true;
63     }
64
65     NetworkSmpiModel::~NetworkSmpiModel(){
66       xbt_dict_free(&gap_lookup);
67     }
68
69     void NetworkSmpiModel::gapAppend(double size, Link* link, NetworkAction *act)
70     {
71       const char *src = link->getName();
72       xbt_fifo_t fifo;
73       NetworkCm02Action *action= static_cast<NetworkCm02Action*>(act);
74
75       if (sg_sender_gap > 0.0) {
76         if (!gap_lookup) {
77           gap_lookup = xbt_dict_new_homogeneous(nullptr);
78         }
79         fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
80         action->senderGap_ = 0.0;
81         if (fifo && xbt_fifo_size(fifo) > 0) {
82           /* Compute gap from last send */
83           /*last_action =
84           (surf_action_network_CM02_t)
85           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));*/
86           // bw = net_get_link_bandwidth(link);
87           action->senderGap_ = sg_sender_gap;
88           /*  max(sg_sender_gap,last_action->sender.size / bw);*/
89           action->latency_ += action->senderGap_;
90         }
91         /* Append action as last send */
92         /*action->sender.link_name = link->lmm_resource.generic_resource.name;
93     fifo =
94         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
95                                           action->sender.link_name);
96     if (!fifo) {
97       fifo = xbt_fifo_new();
98       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, nullptr);
99     }
100     action->sender.fifo_item = xbt_fifo_push(fifo, action);*/
101         action->senderSize_ = size;
102       }
103     }
104
105     void NetworkSmpiModel::gapRemove(Action *lmm_action)
106     {
107       xbt_fifo_t fifo;
108       size_t size;
109       NetworkCm02Action *action = static_cast<NetworkCm02Action*>(lmm_action);
110
111       if (sg_sender_gap > 0.0 && action->senderLinkName_
112           && action->senderFifoItem_) {
113         fifo =
114             (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
115                 action->senderLinkName_);
116         xbt_fifo_remove_item(fifo, action->senderFifoItem_);
117         size = xbt_fifo_size(fifo);
118         if (size == 0) {
119           xbt_fifo_free(fifo);
120           xbt_dict_remove(gap_lookup, action->senderLinkName_);
121           size = xbt_dict_length(gap_lookup);
122           if (size == 0) {
123             xbt_dict_free(&gap_lookup);
124           }
125         }
126       }
127     }
128
129     double NetworkSmpiModel::bandwidthFactor(double size)
130     {
131       if (smpi_bw_factor.empty())
132         smpi_bw_factor = parse_factor(xbt_cfg_get_string("smpi/bw-factor"));
133
134       double current=1.0;
135       for (auto fact: smpi_bw_factor) {
136         if (size <= fact.factor) {
137           XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
138           return current;
139         }else
140           current=fact.values.front();
141       }
142       XBT_DEBUG("%f > %zu return %f", size, smpi_bw_factor.back().factor, current);
143
144       return current;
145     }
146
147     double NetworkSmpiModel::latencyFactor(double size)
148     {
149       if (smpi_lat_factor.empty())
150         smpi_lat_factor = parse_factor(xbt_cfg_get_string("smpi/lat-factor"));
151
152       double current=1.0;
153       for (auto fact: smpi_lat_factor) {
154         if (size <= fact.factor) {
155           XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
156           return current;
157         }else
158           current=fact.values.front();
159       }
160       XBT_DEBUG("%f > %zu return %f", size, smpi_lat_factor.back().factor, current);
161
162       return current;
163     }
164
165     double NetworkSmpiModel::bandwidthConstraint(double rate, double bound, double size)
166     {
167       return rate < 0 ? bound : std::min(bound, rate * bandwidthFactor(size));
168     }
169
170     /************
171      * Resource *
172      ************/
173
174
175
176     /**********
177      * Action *
178      **********/
179
180   }
181 }