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/kernel/routing/NetZoneImpl.hpp"
9 #include "simgrid/s4u/Engine.hpp"
10 #include "simgrid/sg_config.hpp"
11 #include "src/kernel/EngineImpl.hpp"
12 #include "surf/surf.hpp"
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_host);
16 void surf_host_model_init_current_default()
18 auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>("Host_CLM03");
19 simgrid::config::set_default<bool>("network/crosstraffic", true);
20 simgrid::kernel::EngineImpl::get_instance()->add_model(host_model);
21 simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
22 surf_cpu_model_init_Cas01();
23 surf_network_model_init_LegrandVelho();
26 void surf_host_model_init_compound()
28 auto host_model = std::make_shared<simgrid::surf::HostCLM03Model>("Host_CLM03");
29 simgrid::kernel::EngineImpl::get_instance()->add_model(host_model);
30 simgrid::s4u::Engine::get_instance()->get_netzone_root()->get_impl()->set_host_model(host_model);
35 double HostCLM03Model::next_occurring_event(double now)
37 /* nothing specific to be done here
38 * surf_solve already calls all the models next_occurring_event properly */
42 void HostCLM03Model::update_actions_state(double /*now*/, double /*delta*/)
44 /* I've no action to update */
47 /* Helper function for executeParallelTask */
48 static inline double has_cost(const double* array, size_t pos)
55 kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u::Host*>& host_list,
56 const double* flops_amount, const double* bytes_amount,
59 kernel::resource::Action* action = nullptr;
60 /* FIXME[donassolo]: getting the network_model from the origin host
61 * Soon we need to change this function to first get the routes and later
62 * create the respective surf actions */
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]);
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)) {
72 for (size_t i = 0; i < host_list.size() * host_list.size(); i++) {
73 if (has_cost(bytes_amount, i) > 0.0) {
75 value = has_cost(bytes_amount, i);
79 action = net_model->communicate(host_list[0], host_list[1], value, rate);
81 xbt_die("Cannot have a communication with no flop to exchange in this model. You should consider using the "
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");
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");
98 } // namespace simgrid