Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2c4afc6f234770895a537ff059904bce7e101062
[simgrid.git] / src / kernel / resource / models / host_clm03.cpp
1 /* Copyright (c) 2013-2023. 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 "src/kernel/EngineImpl.hpp"
11 #include "src/kernel/resource/NetworkModel.hpp"
12 #include "src/kernel/resource/models/host_clm03.hpp"
13 #include "src/simgrid/module.hpp"
14 #include "src/simgrid/sg_config.hpp"
15
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_host);
17
18 SIMGRID_REGISTER_HOST_MODEL(
19     default, "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19", []() {
20       simgrid::config::set_default<bool>("network/crosstraffic", true);
21       auto host_model = std::make_shared<simgrid::kernel::resource::HostCLM03Model>("Host_CLM03");
22       auto* engine    = simgrid::kernel::EngineImpl::get_instance();
23       engine->add_model(host_model);
24       engine->get_netzone_root()->set_host_model(host_model);
25
26       simgrid_cpu_models().init_from_flag_value();
27       simgrid_disk_models().init_from_flag_value();
28       simgrid_network_models().init_from_flag_value();
29     });
30
31 namespace simgrid::kernel::resource {
32
33 double HostCLM03Model::next_occurring_event(double /*now*/)
34 {
35   /* nothing specific to be done here
36    * EngineImpl::solve already calls all the models next_occurring_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 Action* HostCLM03Model::io_stream(s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk,
54                                   double size)
55 {
56   auto net_model = src_host->get_englobing_zone()->get_network_model();
57   auto system    = net_model->get_maxmin_system();
58   auto* action   = net_model->communicate(src_host, dst_host, size, -1, true);
59
60   // We don't want to apply the network model bandwidth factor to the I/O constraints
61   double bw_factor = net_model->get_bandwidth_factor();
62   if (src_disk != nullptr) {
63     // FIXME: if the stream starts from a disk, we might not want to pay the network latency
64     system->expand(src_disk->get_constraint(), action->get_variable(), bw_factor);
65     system->expand(src_disk->get_read_constraint(), action->get_variable(), bw_factor);
66   }
67   if (dst_disk != nullptr) {
68     system->expand(dst_disk->get_constraint(), action->get_variable(), bw_factor);
69     system->expand(dst_disk->get_write_constraint(), action->get_variable(), bw_factor);
70   }
71
72   return action;
73 }
74
75 Action* HostCLM03Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
76                                          const double* bytes_amount, double rate)
77 {
78   Action* action = nullptr;
79   auto net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
80   if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
81     action = host_list[0]->get_cpu()->execution_start(flops_amount[0], rate);
82   } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
83     action = net_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate, false);
84   } else if ((host_list.size() == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
85     int nb       = 0;
86     double value = 0.0;
87
88     for (size_t i = 0; i < host_list.size() * host_list.size(); i++) {
89       if (has_cost(bytes_amount, i) > 0.0) {
90         nb++;
91         value = has_cost(bytes_amount, i);
92       }
93     }
94     if (nb == 1) {
95       action = net_model->communicate(host_list[0], host_list[1], value, rate, false);
96     } else if (nb == 0) {
97       xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
98               "ptask model");
99     } else {
100       xbt_die("Cannot have a communication that is not a simple point-to-point in this model. You should consider "
101               "using the ptask model");
102     }
103   } else {
104     xbt_die(
105         "This model only accepts one of the following. You should consider using the ptask model for the other cases.\n"
106         " - execution with one host only and no communication\n"
107         " - Self-comms with one host only\n"
108         " - Communications with two hosts and no computation");
109   }
110   return action;
111 }
112
113 Action* HostCLM03Model::execute_thread(const s4u::Host* host, double flops_amount, int thread_count)
114 {
115   auto cpu = host->get_cpu();
116   /* Create a single action whose cost is thread_count * flops_amount and that requests thread_count cores. */
117   return cpu->execution_start(thread_count * flops_amount, thread_count, -1);
118 }
119
120 } // namespace simgrid::kernel::resource