Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove one of the many pimple: HostModel::p_cpuModel
[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
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 HostCLM03Model::HostCLM03Model()
50  : HostModel("Host CLM03")
51 {
52 }
53
54 HostCLM03Model::~HostCLM03Model()
55 {}
56
57 Host *HostCLM03Model::createHost(const char *name){
58   sg_host_t sg_host = sg_host_by_name(name);
59   Host *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                   sg_host_edge(sg_host),
62                   sg_host_surfcpu(sg_host));
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);
65   return host;
66 }
67
68 double HostCLM03Model::shareResources(double now){
69   adjustWeightOfDummyCpuActions();
70
71   double min_by_cpu = surf_cpu_model_pm->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 = surf_storage_model->shareResources(now);
74
75   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
76       this, surf_cpu_model_pm->getName(), min_by_cpu,
77             surf_network_model->getName(), min_by_net,
78             surf_storage_model->getName(), min_by_sto);
79
80   double res = max(max(min_by_cpu, min_by_net), min_by_sto);
81   if (min_by_cpu >= 0.0 && min_by_cpu < res)
82         res = min_by_cpu;
83   if (min_by_net >= 0.0 && min_by_net < res)
84         res = min_by_net;
85   if (min_by_sto >= 0.0 && min_by_sto < res)
86         res = min_by_sto;
87   return res;
88 }
89
90 void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
91   return;
92 }
93
94 Action *HostCLM03Model::executeParallelTask(int host_nb,
95                                         void **host_list,
96                                         double *flops_amount,
97                                         double *bytes_amount,
98                                         double rate){
99 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
100   Action *action =NULL;
101   if ((host_nb == 1)
102       && (cost_or_zero(bytes_amount, 0) == 0.0)){
103     action = static_cast<HostCLM03*>(host_list[0])->execute(flops_amount[0]);
104   } else if ((host_nb == 1)
105            && (cost_or_zero(flops_amount, 0) == 0.0)) {
106     action = communicate(static_cast<HostCLM03*>(host_list[0]),
107                 static_cast<HostCLM03*>(host_list[0]),bytes_amount[0], rate);
108   } else if ((host_nb == 2)
109              && (cost_or_zero(flops_amount, 0) == 0.0)
110              && (cost_or_zero(flops_amount, 1) == 0.0)) {
111     int i,nb = 0;
112     double value = 0.0;
113
114     for (i = 0; i < host_nb * host_nb; i++) {
115       if (cost_or_zero(bytes_amount, i) > 0.0) {
116         nb++;
117         value = cost_or_zero(bytes_amount, i);
118       }
119     }
120     if (nb == 1){
121       action = communicate(static_cast<HostCLM03*>(host_list[0]),
122                   static_cast<HostCLM03*>(host_list[1]),value, rate);
123     }
124   } else
125     THROW_UNIMPLEMENTED;      /* This model does not implement parallel tasks */
126 #undef cost_or_zero
127   xbt_free(host_list);
128   return action;
129 }
130
131 Action *HostCLM03Model::communicate(Host *src, Host *dst, double size, double rate){
132   return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
133 }
134
135
136
137 /************
138  * Resource *
139  ************/
140 HostCLM03::HostCLM03(HostModel *model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
141   : Host(model, name, properties, storage, netElm, cpu) {}
142
143 bool HostCLM03::isUsed(){
144   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
145   return -1;
146 }
147
148 void HostCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
149   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
150 }
151
152 Action *HostCLM03::execute(double size) {
153   return p_cpu->execute(size);
154 }
155
156 Action *HostCLM03::sleep(double duration) {
157   return p_cpu->sleep(duration);
158 }
159
160 e_surf_resource_state_t HostCLM03::getState() {
161   return p_cpu->getState();
162 }
163
164 /**********
165  * Action *
166  **********/