Logo AND Algorithmique Numérique Distribuée

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