1 /* Copyright (c) 2013-2015. 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 "virtual_machine.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();
30 Model *model = surf_host_model;
31 xbt_dynar_push(all_existing_models, &model);
34 void surf_host_model_init_compound()
37 xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
38 xbt_assert(surf_network_model, "No network model defined yet!");
39 surf_host_model = new HostCLM03Model();
41 Model *model = surf_host_model;
42 xbt_dynar_push(all_existing_models, &model);
45 Host *HostCLM03Model::createHost(const char *name,RoutingEdge *netElm, Cpu *cpu){
46 Host *host = new HostCLM03(surf_host_model, name, NULL,
47 (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL),
49 surf_callback_emit(hostCreatedCallbacks, host);
50 XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage));
51 xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host);
55 double HostCLM03Model::shareResources(double now){
56 adjustWeightOfDummyCpuActions();
58 double min_by_cpu = surf_cpu_model_pm->shareResources(now);
59 double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1;
60 double min_by_sto = surf_storage_model->shareResources(now);
62 XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
63 this, typeid(surf_cpu_model_pm).name(), min_by_cpu,
64 typeid(surf_network_model).name(), min_by_net,
65 typeid(surf_storage_model).name(), min_by_sto);
67 double res = max(max(min_by_cpu, min_by_net), min_by_sto);
68 if (min_by_cpu >= 0.0 && min_by_cpu < res)
70 if (min_by_net >= 0.0 && min_by_net < res)
72 if (min_by_sto >= 0.0 && min_by_sto < res)
77 void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
81 Action *HostCLM03Model::executeParallelTask(int host_nb,
86 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
89 && (cost_or_zero(bytes_amount, 0) == 0.0)){
90 action = surf_host_execute(host_list[0],flops_amount[0]);
91 } else if ((host_nb == 1)
92 && (cost_or_zero(flops_amount, 0) == 0.0)) {
93 action = surf_network_model->communicate(sg_host_edge(host_list[0]),
94 sg_host_edge(host_list[0]),
95 bytes_amount[0], rate);
96 } else if ((host_nb == 2)
97 && (cost_or_zero(flops_amount, 0) == 0.0)
98 && (cost_or_zero(flops_amount, 1) == 0.0)) {
102 for (i = 0; i < host_nb * host_nb; i++) {
103 if (cost_or_zero(bytes_amount, i) > 0.0) {
105 value = cost_or_zero(bytes_amount, i);
109 action = surf_network_model->communicate(sg_host_edge(host_list[0]),
110 sg_host_edge(host_list[1]),
114 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks for more than 2 hosts */
123 HostCLM03::HostCLM03(HostModel *model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
124 : Host(model, name, properties, storage, netElm, cpu) {}
126 bool HostCLM03::isUsed(){
127 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
131 void HostCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
132 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
135 Action *HostCLM03::execute(double size) {
136 return p_cpu->execute(size);
139 Action *HostCLM03::sleep(double duration) {
140 return p_cpu->sleep(duration);
143 e_surf_resource_state_t HostCLM03::getState() {
144 return p_cpu->getState();