1 /* Copyright (c) 2013-2021. The SimGrid Team. All rights reserved. */
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. */
6 #include "src/surf/host_clm03.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/sg_config.hpp"
9 #include "surf/surf.hpp"
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_host);
13 void surf_host_model_init_current_default()
15 surf_host_model = new simgrid::surf::HostCLM03Model();
16 simgrid::config::set_default<bool>("network/crosstraffic", true);
17 surf_cpu_model_init_Cas01();
18 surf_network_model_init_LegrandVelho();
21 void surf_host_model_init_compound()
23 xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
24 xbt_assert(surf_network_model, "No network model defined yet!");
25 surf_host_model = new simgrid::surf::HostCLM03Model();
30 HostCLM03Model::HostCLM03Model()
32 all_existing_models.push_back(this);
33 models_by_type[simgrid::kernel::resource::Model::Type::HOST].push_back(this);
36 double HostCLM03Model::next_occurring_event(double now)
38 /* nothing specific to be done here
39 * surf_solve already calls all the models next_occuring_event properly */
43 void HostCLM03Model::update_actions_state(double /*now*/, double /*delta*/)
45 /* I've no action to update */
48 /* Helper function for executeParallelTask */
49 static inline double has_cost(const double* array, size_t pos)
56 kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u::Host*>& host_list,
57 const double* flops_amount, const double* bytes_amount,
60 kernel::resource::Action* action = nullptr;
61 /* FIXME[donassolo]: getting the network_model from the origin host
62 * Soon we need to change this function to first get the routes and later
63 * create the respective surf actions */
64 auto* net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
65 if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
66 action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
67 } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
68 action = net_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
69 } else if ((host_list.size() == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
73 for (size_t i = 0; i < host_list.size() * host_list.size(); i++) {
74 if (has_cost(bytes_amount, i) > 0.0) {
76 value = has_cost(bytes_amount, i);
80 action = net_model->communicate(host_list[0], host_list[1], value, rate);
82 xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
85 xbt_die("Cannot have a communication that is not a simple point-to-point in this model. You should consider "
86 "using the ptask model");
90 "This model only accepts one of the following. You should consider using the ptask model for the other cases.\n"
91 " - execution with one host only and no communication\n"
92 " - Self-comms with one host only\n"
93 " - Communications with two hosts and no computation");
99 } // namespace simgrid