1 /* Copyright (c) 2013-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "host_clm03.hpp"
9 #include "cpu_cas01.hpp"
10 #include "simgrid/sg_config.h"
11 #include "vm_interface.hpp"
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host);
23 void surf_host_model_init_current_default(void)
25 surf_host_model = new HostCLM03Model();
26 xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes");
27 surf_cpu_model_init_Cas01();
28 surf_network_model_init_LegrandVelho();
29 surf_host_model->p_cpuModel = surf_cpu_model_pm;
31 ModelPtr model = surf_host_model;
32 xbt_dynar_push(model_list, &model);
33 xbt_dynar_push(model_list_invoke, &model);
34 sg_platf_host_add_cb(host_parse_init);
37 void surf_host_model_init_compound()
40 xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
41 xbt_assert(surf_network_model, "No network model defined yet!");
42 surf_host_model = new HostCLM03Model();
44 ModelPtr model = surf_host_model;
45 xbt_dynar_push(model_list, &model);
46 xbt_dynar_push(model_list_invoke, &model);
47 sg_platf_host_add_cb(host_parse_init);
50 HostCLM03Model::HostCLM03Model()
51 : HostModel("Host CLM03")
55 HostCLM03Model::~HostCLM03Model()
58 HostPtr HostCLM03Model::createHost(const char *name){
59 HostPtr host = new HostCLM03(surf_host_model, name, NULL,
60 (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL),
61 (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL),
62 static_cast<CpuPtr>(xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL)));
63 XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage));
64 xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host);
68 double HostCLM03Model::shareResources(double now){
69 adjustWeightOfDummyCpuActions();
71 double min_by_cpu = p_cpuModel->shareResources(now);
72 double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
73 double min_by_sto = -1;
74 if (p_cpuModel == surf_cpu_model_pm)
75 min_by_sto = surf_storage_model->shareResources(now);
77 XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
78 this, surf_cpu_model_pm->getName(), min_by_cpu,
79 surf_network_model->getName(), min_by_net,
80 surf_storage_model->getName(), min_by_sto);
82 double res = max(max(min_by_cpu, min_by_net), min_by_sto);
83 if (min_by_cpu >= 0.0 && min_by_cpu < res)
85 if (min_by_net >= 0.0 && min_by_net < res)
87 if (min_by_sto >= 0.0 && min_by_sto < res)
92 void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
96 ActionPtr HostCLM03Model::executeParallelTask(int host_nb,
101 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
102 ActionPtr action =NULL;
104 && (cost_or_zero(bytes_amount, 0) == 0.0)){
105 action = ((HostCLM03Ptr)host_list[0])->execute(flops_amount[0]);
106 } else if ((host_nb == 1)
107 && (cost_or_zero(flops_amount, 0) == 0.0)) {
108 action = communicate((HostCLM03Ptr)host_list[0],
109 (HostCLM03Ptr)host_list[0],bytes_amount[0], rate);
110 } else if ((host_nb == 2)
111 && (cost_or_zero(flops_amount, 0) == 0.0)
112 && (cost_or_zero(flops_amount, 1) == 0.0)) {
116 for (i = 0; i < host_nb * host_nb; i++) {
117 if (cost_or_zero(bytes_amount, i) > 0.0) {
119 value = cost_or_zero(bytes_amount, i);
123 action = communicate((HostCLM03Ptr)host_list[0],
124 (HostCLM03Ptr)host_list[1],value, rate);
127 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
129 xbt_free((HostCLM03Ptr)host_list);
133 ActionPtr HostCLM03Model::communicate(HostPtr src, HostPtr dst, double size, double rate){
134 return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
142 HostCLM03::HostCLM03(HostModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
143 : Host(model, name, properties, storage, netElm, cpu) {}
145 bool HostCLM03::isUsed(){
146 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
150 void HostCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
151 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
154 ActionPtr HostCLM03::execute(double size) {
155 return p_cpu->execute(size);
158 ActionPtr HostCLM03::sleep(double duration) {
159 return p_cpu->sleep(duration);
162 e_surf_resource_state_t HostCLM03::getState() {
163 return p_cpu->getState();