Logo AND Algorithmique Numérique Distribuée

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