Logo AND Algorithmique Numérique Distribuée

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