Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add VM energy extensions - Adrien
[simgrid.git] / src / surf / host_clm03.cpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "host_clm03.hpp"
8
9 #include "cpu_cas01.hpp"
10 #include "simgrid/sg_config.h"
11 #include "vm_interface.hpp"
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host);
14
15 /*************
16  * CallBacks *
17  *************/
18
19 /*********
20  * Model *
21  *********/
22
23 void surf_host_model_init_current_default(void)
24 {
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
30   Model *model = surf_host_model;
31   xbt_dynar_push(model_list, &model);
32   xbt_dynar_push(model_list_invoke, &model);
33   sg_platf_host_add_cb(host_parse_init);
34 }
35
36 void surf_host_model_init_compound()
37 {
38
39   xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
40   xbt_assert(surf_network_model, "No network model defined yet!");
41   surf_host_model = new HostCLM03Model();
42
43   Model *model = surf_host_model;
44   xbt_dynar_push(model_list, &model);
45   xbt_dynar_push(model_list_invoke, &model);
46   sg_platf_host_add_cb(host_parse_init);
47 }
48
49 Host *HostCLM03Model::createHost(const char *name){
50   sg_host_t sg_host = sg_host_by_name(name);
51   Host *host = new HostCLM03(surf_host_model, name, NULL,
52                   (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL),
53                   sg_host_edge(sg_host),
54                   sg_host_surfcpu(sg_host));
55   XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage));
56   xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host);
57   return host;
58 }
59
60 double HostCLM03Model::shareResources(double now){
61   adjustWeightOfDummyCpuActions();
62
63   double min_by_cpu = surf_cpu_model_pm->shareResources(now);
64   double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1;
65   double min_by_sto = surf_storage_model->shareResources(now);
66
67   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
68       this, typeid(surf_cpu_model_pm).name(), min_by_cpu,
69                 typeid(surf_network_model).name(), min_by_net,
70                         typeid(surf_storage_model).name(), min_by_sto);
71
72   double res = max(max(min_by_cpu, min_by_net), min_by_sto);
73   if (min_by_cpu >= 0.0 && min_by_cpu < res)
74         res = min_by_cpu;
75   if (min_by_net >= 0.0 && min_by_net < res)
76         res = min_by_net;
77   if (min_by_sto >= 0.0 && min_by_sto < res)
78         res = min_by_sto;
79   return res;
80 }
81
82 void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
83   return;
84 }
85
86 Action *HostCLM03Model::executeParallelTask(int host_nb,
87                                         sg_host_t *host_list,
88                                         double *flops_amount,
89                                         double *bytes_amount,
90                                         double rate){
91 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
92   Action *action =NULL;
93   if ((host_nb == 1)
94       && (cost_or_zero(bytes_amount, 0) == 0.0)){
95     action = surf_host_execute(host_list[0],flops_amount[0]);
96   } else if ((host_nb == 1)
97            && (cost_or_zero(flops_amount, 0) == 0.0)) {
98     action = surf_network_model->communicate(sg_host_edge(host_list[0]),
99                                                  sg_host_edge(host_list[0]),
100                                                                                          bytes_amount[0], rate);
101   } else if ((host_nb == 2)
102              && (cost_or_zero(flops_amount, 0) == 0.0)
103              && (cost_or_zero(flops_amount, 1) == 0.0)) {
104     int i,nb = 0;
105     double value = 0.0;
106
107     for (i = 0; i < host_nb * host_nb; i++) {
108       if (cost_or_zero(bytes_amount, i) > 0.0) {
109         nb++;
110         value = cost_or_zero(bytes_amount, i);
111       }
112     }
113     if (nb == 1){
114       action = surf_network_model->communicate(sg_host_edge(host_list[0]),
115                                                    sg_host_edge(host_list[1]),
116                                                                                            value, rate);
117     }
118   } else
119     THROW_UNIMPLEMENTED;      /* This model does not implement parallel tasks for more than 2 hosts */
120 #undef cost_or_zero
121   xbt_free(host_list);
122   return action;
123 }
124
125 /************
126  * Resource *
127  ************/
128 HostCLM03::HostCLM03(HostModel *model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
129   : Host(model, name, properties, storage, netElm, cpu) {}
130
131 bool HostCLM03::isUsed(){
132   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
133   return -1;
134 }
135
136 void HostCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
137   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
138 }
139
140 Action *HostCLM03::execute(double size) {
141   return p_cpu->execute(size);
142 }
143
144 Action *HostCLM03::sleep(double duration) {
145   return p_cpu->sleep(duration);
146 }
147
148 e_surf_resource_state_t HostCLM03::getState() {
149   return p_cpu->getState();
150 }
151
152 /**********
153  * Action *
154  **********/