Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill dead code: Action::recycle never got implemented
[simgrid.git] / src / surf / host_clm03.cpp
1 /* Copyright (c) 2013-2014. 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   surf_host_model->p_cpuModel = surf_cpu_model_pm;
30
31   Model *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);
35 }
36
37 void surf_host_model_init_compound()
38 {
39
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();
43
44   Model *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);
48 }
49
50 HostCLM03Model::HostCLM03Model()
51  : HostModel("Host CLM03")
52 {
53 }
54
55 HostCLM03Model::~HostCLM03Model()
56 {}
57
58 Host *HostCLM03Model::createHost(const char *name){
59   sg_host_t sg_host = sg_host_by_name(name);
60   Host *host = new HostCLM03(surf_host_model, name, NULL,
61                   (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL),
62                   sg_host_edge(sg_host),
63                   sg_host_surfcpu(sg_host));
64   XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage));
65   xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host);
66   return host;
67 }
68
69 double HostCLM03Model::shareResources(double now){
70   adjustWeightOfDummyCpuActions();
71
72   double min_by_cpu = p_cpuModel->shareResources(now);
73   double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
74   double min_by_sto = -1;
75   if (p_cpuModel == surf_cpu_model_pm)
76         min_by_sto = surf_storage_model->shareResources(now);
77
78   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
79       this, surf_cpu_model_pm->getName(), min_by_cpu,
80             surf_network_model->getName(), min_by_net,
81             surf_storage_model->getName(), min_by_sto);
82
83   double res = max(max(min_by_cpu, min_by_net), min_by_sto);
84   if (min_by_cpu >= 0.0 && min_by_cpu < res)
85         res = min_by_cpu;
86   if (min_by_net >= 0.0 && min_by_net < res)
87         res = min_by_net;
88   if (min_by_sto >= 0.0 && min_by_sto < res)
89         res = min_by_sto;
90   return res;
91 }
92
93 void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
94   return;
95 }
96
97 Action *HostCLM03Model::executeParallelTask(int host_nb,
98                                         void **host_list,
99                                         double *flops_amount,
100                                         double *bytes_amount,
101                                         double rate){
102 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
103   Action *action =NULL;
104   if ((host_nb == 1)
105       && (cost_or_zero(bytes_amount, 0) == 0.0)){
106     action = static_cast<HostCLM03*>(host_list[0])->execute(flops_amount[0]);
107   } else if ((host_nb == 1)
108            && (cost_or_zero(flops_amount, 0) == 0.0)) {
109     action = communicate(static_cast<HostCLM03*>(host_list[0]),
110                 static_cast<HostCLM03*>(host_list[0]),bytes_amount[0], rate);
111   } else if ((host_nb == 2)
112              && (cost_or_zero(flops_amount, 0) == 0.0)
113              && (cost_or_zero(flops_amount, 1) == 0.0)) {
114     int i,nb = 0;
115     double value = 0.0;
116
117     for (i = 0; i < host_nb * host_nb; i++) {
118       if (cost_or_zero(bytes_amount, i) > 0.0) {
119         nb++;
120         value = cost_or_zero(bytes_amount, i);
121       }
122     }
123     if (nb == 1){
124       action = communicate(static_cast<HostCLM03*>(host_list[0]),
125                   static_cast<HostCLM03*>(host_list[1]),value, rate);
126     }
127   } else
128     THROW_UNIMPLEMENTED;      /* This model does not implement parallel tasks */
129 #undef cost_or_zero
130   xbt_free(host_list);
131   return action;
132 }
133
134 Action *HostCLM03Model::communicate(Host *src, Host *dst, double size, double rate){
135   return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
136 }
137
138
139
140 /************
141  * Resource *
142  ************/
143 HostCLM03::HostCLM03(HostModel *model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
144   : Host(model, name, properties, storage, netElm, cpu) {}
145
146 bool HostCLM03::isUsed(){
147   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
148   return -1;
149 }
150
151 void HostCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
152   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
153 }
154
155 Action *HostCLM03::execute(double size) {
156   return p_cpu->execute(size);
157 }
158
159 Action *HostCLM03::sleep(double duration) {
160   return p_cpu->sleep(duration);
161 }
162
163 e_surf_resource_state_t HostCLM03::getState() {
164   return p_cpu->getState();
165 }
166
167 /**********
168  * Action *
169  **********/