Logo AND Algorithmique Numérique Distribuée

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