Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
introduce thread_execute
[simgrid.git] / src / surf / host_clm03.cpp
1 /* Copyright (c) 2013-2022. 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::kernel::resource::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::kernel::resource::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 kernel {
37 namespace 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::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
60                                          const double* bytes_amount, double rate)
61 {
62   Action* action = nullptr;
63   auto net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
64   if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
65     action = host_list[0]->get_cpu()->execution_start(flops_amount[0], rate);
66   } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
67     action = net_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
68   } else if ((host_list.size() == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
69     int nb       = 0;
70     double value = 0.0;
71
72     for (size_t i = 0; i < host_list.size() * host_list.size(); i++) {
73       if (has_cost(bytes_amount, i) > 0.0) {
74         nb++;
75         value = has_cost(bytes_amount, i);
76       }
77     }
78     if (nb == 1) {
79       action = net_model->communicate(host_list[0], host_list[1], value, rate);
80     } else if (nb == 0) {
81       xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
82               "ptask model");
83     } else {
84       xbt_die("Cannot have a communication that is not a simple point-to-point in this model. You should consider "
85               "using the ptask model");
86     }
87   } else {
88     xbt_die(
89         "This model only accepts one of the following. You should consider using the ptask model for the other cases.\n"
90         " - execution with one host only and no communication\n"
91         " - Self-comms with one host only\n"
92         " - Communications with two hosts and no computation");
93   }
94   return action;
95 }
96
97 Action* HostCLM03Model::execute_thread(const s4u::Host* host, double flops_amount, int thread_count)
98 {
99   auto cpu = host->get_cpu();
100   /* Create a single action whose cost is thread_count * flops_amount,, that requests thread_count cores and
101    * is bounded to the currently available speed (i.e., under current load) time the minimum  between the
102    * number of thread and the number of cores of the host */
103   return cpu->execution_start(thread_count * flops_amount, thread_count,
104                               cpu->get_speed(1.0) / cpu->get_speed_ratio() *
105                                   std::min(thread_count, cpu->get_core_count()));
106 }
107
108 } // namespace resource
109 } // namespace kernel
110 } // namespace simgrid