Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'bruno.donassolo/simgrid-add_model_shared' into next
[simgrid.git] / src / surf / network_smpi.cpp
1 /* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "network_smpi.hpp"
7 #include "simgrid/sg_config.hpp"
8 #include "smpi_utils.hpp"
9 #include "src/kernel/EngineImpl.hpp"
10 #include "src/surf/surf_interface.hpp"
11 #include "surf/surf.hpp"
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
14
15 std::vector<s_smpi_factor_t> smpi_bw_factor;
16 std::vector<s_smpi_factor_t> smpi_lat_factor;
17
18 /*********
19  * Model *
20  *********/
21
22 /************************************************************************/
23 /* New model based on LV08 and experimental results of MPI ping-pongs   */
24 /************************************************************************/
25 /* @Inproceedings{smpi_ipdps, */
26 /*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and
27  * Martin Quinson}, */
28 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
29 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
30 /*  address={Anchorage (Alaska) USA}, */
31 /*  month=may, */
32 /*  year={2011} */
33 /*  } */
34 void surf_network_model_init_SMPI()
35 {
36   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkSmpiModel>();
37   simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
38                                                          std::move(net_model), true);
39
40   simgrid::config::set_default<double>("network/weight-S", 8775);
41 }
42
43 namespace simgrid {
44 namespace kernel {
45 namespace resource {
46
47 NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
48 {
49 }
50
51 double NetworkSmpiModel::get_bandwidth_factor(double size)
52 {
53   if (smpi_bw_factor.empty())
54     smpi_bw_factor = parse_factor(config::get_value<std::string>("smpi/bw-factor"));
55
56   double current = 1.0;
57   for (auto const& fact : smpi_bw_factor) {
58     if (size <= fact.factor) {
59       XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
60       return current;
61     } else
62       current = fact.values.front();
63   }
64   XBT_DEBUG("%f > %zu return %f", size, smpi_bw_factor.back().factor, current);
65
66   return current;
67 }
68
69 double NetworkSmpiModel::get_latency_factor(double size)
70 {
71   if (smpi_lat_factor.empty())
72     smpi_lat_factor = parse_factor(config::get_value<std::string>("smpi/lat-factor"));
73
74   double current = 1.0;
75   for (auto const& fact : smpi_lat_factor) {
76     if (size <= fact.factor) {
77       XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
78       return current;
79     } else
80       current = fact.values.front();
81   }
82   XBT_DEBUG("%f > %zu return %f", size, smpi_lat_factor.back().factor, current);
83
84   return current;
85 }
86
87 double NetworkSmpiModel::get_bandwidth_constraint(double rate, double bound, double size)
88 {
89   return rate < 0 ? bound : std::min(bound, rate * get_bandwidth_factor(size));
90 }
91 } // namespace resource
92 } // namespace kernel
93 } // namespace simgrid