Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[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/sg_config.hpp"
8 #include "surf/surf.hpp"
9
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host);
11
12 void surf_host_model_init_current_default()
13 {
14   surf_host_model = new simgrid::surf::HostCLM03Model();
15   simgrid::config::set_default<bool>("network/crosstraffic", true);
16   surf_cpu_model_init_Cas01();
17   surf_network_model_init_LegrandVelho();
18 }
19
20 void surf_host_model_init_compound()
21 {
22   xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
23   xbt_assert(surf_network_model, "No network model defined yet!");
24   surf_host_model = new simgrid::surf::HostCLM03Model();
25 }
26
27 namespace simgrid {
28 namespace surf {
29 HostCLM03Model::HostCLM03Model()
30 {
31   all_existing_models.push_back(this);
32 }
33
34 double HostCLM03Model::next_occurring_event(double now)
35 {
36   double min_by_cpu = surf_cpu_model_pm->next_occurring_event(now);
37   double min_by_net =
38       surf_network_model->next_occurring_event_is_idempotent() ? surf_network_model->next_occurring_event(now) : -1;
39   double min_by_sto = surf_storage_model->next_occurring_event(now);
40   double min_by_dsk = surf_disk_model->next_occurring_event(now);
41
42   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f, %s min_by_dsk %f", this,
43             typeid(surf_cpu_model_pm).name(), min_by_cpu, typeid(surf_network_model).name(), min_by_net,
44             typeid(surf_storage_model).name(), min_by_sto, typeid(surf_disk_model).name(), min_by_dsk);
45
46   double res = min_by_cpu;
47   if (res < 0 || (min_by_net >= 0.0 && min_by_net < res))
48     res = min_by_net;
49   if (res < 0 || (min_by_sto >= 0.0 && min_by_sto < res))
50     res = min_by_sto;
51   if (res < 0 || (min_by_dsk >= 0.0 && min_by_dsk < res))
52     res = min_by_dsk;
53   return res;
54 }
55
56 void HostCLM03Model::update_actions_state(double /*now*/, double /*delta*/)
57 {
58   /* I've no action to update */
59 }
60
61 /* Helper function for executeParallelTask */
62 static inline double has_cost(const double* array, size_t pos)
63 {
64   if (array)
65     return array[pos];
66   return -1.0;
67 }
68
69 kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u::Host*>& host_list,
70                                                            const double* flops_amount, const double* bytes_amount,
71                                                            double rate)
72 {
73   kernel::resource::Action* action = nullptr;
74   if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
75     action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
76   } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
77     action = surf_network_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
78   } else if ((host_list.size() == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
79     int nb       = 0;
80     double value = 0.0;
81
82     for (size_t i = 0; i < host_list.size() * host_list.size(); i++) {
83       if (has_cost(bytes_amount, i) > 0.0) {
84         nb++;
85         value = has_cost(bytes_amount, i);
86       }
87     }
88     if (nb == 1) {
89       action = surf_network_model->communicate(host_list[0], host_list[1], value, rate);
90     } else if (nb == 0) {
91       xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
92               "ptask model");
93     } else {
94       xbt_die("Cannot have a communication that is not a simple point-to-point in this model. You should consider "
95               "using the ptask model");
96     }
97   } else {
98     xbt_die(
99         "This model only accepts one of the following. You should consider using the ptask model for the other cases.\n"
100         " - execution with one host only and no communication\n"
101         " - Self-comms with one host only\n"
102         " - Communications with two hosts and no computation");
103   }
104   return action;
105 }
106
107 } // namespace surf
108 } // namespace simgrid