Logo AND Algorithmique Numérique Distribuée

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