Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
small simplifications and cleanups
[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/kernel/routing/NetZoneImpl.hpp"
8 #include "simgrid/s4u/Engine.hpp"
9 #include "simgrid/sg_config.hpp"
10 #include "smpi_utils.hpp"
11 #include "src/kernel/EngineImpl.hpp"
12 #include "src/surf/surf_interface.hpp"
13 #include "surf/surf.hpp"
14
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_network);
16
17 /*********
18  * Model *
19  *********/
20
21 /************************************************************************/
22 /* New model based on LV08 and experimental results of MPI ping-pongs   */
23 /************************************************************************/
24 /* @Inproceedings{smpi_ipdps, */
25 /*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and
26  * Martin Quinson}, */
27 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
28 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
29 /*  address={Anchorage (Alaska) USA}, */
30 /*  month=may, */
31 /*  year={2011} */
32 /*  } */
33 void surf_network_model_init_SMPI()
34 {
35   auto net_model = std::make_shared<simgrid::kernel::resource::NetworkSmpiModel>("Network_SMPI");
36   simgrid::kernel::EngineImpl::get_instance()->add_model(net_model);
37   simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_network_model(net_model);
38
39   simgrid::config::set_default<double>("network/weight-S", 8775);
40 }
41
42 namespace simgrid {
43 namespace kernel {
44 namespace resource {
45
46 double NetworkSmpiModel::get_bandwidth_factor(double size)
47 {
48   static std::vector<s_smpi_factor_t> smpi_bw_factor;
49   if (smpi_bw_factor.empty())
50     smpi_bw_factor = smpi::utils::parse_factor(config::get_value<std::string>("smpi/bw-factor"));
51
52   double current = 1.0;
53   for (auto const& fact : smpi_bw_factor) {
54     if (size <= fact.factor) {
55       XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
56       return current;
57     } else
58       current = fact.values.front();
59   }
60   XBT_DEBUG("%f > %zu return %f", size, smpi_bw_factor.back().factor, current);
61
62   return current;
63 }
64
65 double NetworkSmpiModel::get_latency_factor(double size)
66 {
67   static std::vector<s_smpi_factor_t> smpi_lat_factor;
68   if (smpi_lat_factor.empty())
69     smpi_lat_factor = smpi::utils::parse_factor(config::get_value<std::string>("smpi/lat-factor"));
70
71   double current = 1.0;
72   for (auto const& fact : smpi_lat_factor) {
73     if (size <= fact.factor) {
74       XBT_DEBUG("%f <= %zu return %f", size, fact.factor, current);
75       return current;
76     } else
77       current = fact.values.front();
78   }
79   XBT_DEBUG("%f > %zu return %f", size, smpi_lat_factor.back().factor, current);
80
81   return current;
82 }
83
84 double NetworkSmpiModel::get_bandwidth_constraint(double rate, double bound, double size)
85 {
86   return rate < 0 ? bound : std::min(bound, rate * get_bandwidth_factor(size));
87 }
88 } // namespace resource
89 } // namespace kernel
90 } // namespace simgrid