Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Use '=default'.
[simgrid.git] / src / surf / host_clm03.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 "src/surf/host_clm03.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/sg_config.hpp"
9 #include "src/kernel/EngineImpl.hpp"
10 #include "surf/surf.hpp"
11
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_host);
13
14 void surf_host_model_init_current_default()
15 {
16   auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>();
17   simgrid::config::set_default<bool>("network/crosstraffic", true);
18   simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
19                                                          std::move(host_model), true);
20   surf_cpu_model_init_Cas01();
21   surf_network_model_init_LegrandVelho();
22 }
23
24 void surf_host_model_init_compound()
25 {
26   auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>();
27   simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
28                                                          std::move(host_model), true);
29 }
30
31 namespace simgrid {
32 namespace surf {
33 double HostCLM03Model::next_occurring_event(double now)
34 {
35   /* nothing specific to be done here
36    * surf_solve already calls all the models next_occuring_event properly */
37   return -1.0;
38 }
39
40 void HostCLM03Model::update_actions_state(double /*now*/, double /*delta*/)
41 {
42   /* I've no action to update */
43 }
44
45 /* Helper function for executeParallelTask */
46 static inline double has_cost(const double* array, size_t pos)
47 {
48   if (array)
49     return array[pos];
50   return -1.0;
51 }
52
53 kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u::Host*>& host_list,
54                                                            const double* flops_amount, const double* bytes_amount,
55                                                            double rate)
56 {
57   kernel::resource::Action* action = nullptr;
58   /* FIXME[donassolo]: getting the network_model from the origin host
59    * Soon we need to change this function to first get the routes and later
60    * create the respective surf actions */
61   auto* net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
62   if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
63     action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
64   } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
65     action = net_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
66   } else if ((host_list.size() == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
67     int nb       = 0;
68     double value = 0.0;
69
70     for (size_t i = 0; i < host_list.size() * host_list.size(); i++) {
71       if (has_cost(bytes_amount, i) > 0.0) {
72         nb++;
73         value = has_cost(bytes_amount, i);
74       }
75     }
76     if (nb == 1) {
77       action = net_model->communicate(host_list[0], host_list[1], value, rate);
78     } else if (nb == 0) {
79       xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
80               "ptask model");
81     } else {
82       xbt_die("Cannot have a communication that is not a simple point-to-point in this model. You should consider "
83               "using the ptask model");
84     }
85   } else {
86     xbt_die(
87         "This model only accepts one of the following. You should consider using the ptask model for the other cases.\n"
88         " - execution with one host only and no communication\n"
89         " - Self-comms with one host only\n"
90         " - Communications with two hosts and no computation");
91   }
92   return action;
93 }
94
95 } // namespace surf
96 } // namespace simgrid