Logo AND Algorithmique Numérique Distribuée

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