Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cleanup.
[simgrid.git] / src / surf / workstation_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 "workstation_clm03.hpp"
8 #include "vm_workstation_interface.hpp"
9 #include "cpu_cas01.hpp"
10 #include "simgrid/sg_config.h"
11
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
13
14 /*************
15  * CallBacks *
16  *************/
17
18 static void workstation_new(sg_platf_host_cbarg_t host){
19   reinterpret_cast<WorkstationCLM03ModelPtr>(surf_workstation_model)->createResource(host->id);
20 }
21
22 /*********
23  * Model *
24  *********/
25
26 void surf_workstation_model_init_current_default(void)
27 {
28   surf_workstation_model = new WorkstationCLM03Model();
29   xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes");
30   surf_cpu_model_init_Cas01();
31   surf_network_model_init_LegrandVelho();
32   surf_workstation_model->p_cpuModel = surf_cpu_model_pm;
33
34   ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
35   xbt_dynar_push(model_list, &model);
36   xbt_dynar_push(model_list_invoke, &model);
37   sg_platf_host_add_cb(workstation_new);
38 }
39
40 void surf_workstation_model_init_compound()
41 {
42
43   xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
44   xbt_assert(surf_network_model, "No network model defined yet!");
45   surf_workstation_model = new WorkstationCLM03Model();
46
47   ModelPtr model = static_cast<ModelPtr>(surf_workstation_model);
48   xbt_dynar_push(model_list, &model);
49   xbt_dynar_push(model_list_invoke, &model);
50   sg_platf_host_add_cb(workstation_new);
51 }
52
53 WorkstationCLM03Model::WorkstationCLM03Model(const char *name)
54  : WorkstationModel(name)
55 {}
56
57
58 WorkstationCLM03Model::WorkstationCLM03Model()
59  : WorkstationModel("Workstation")
60 {
61 }
62
63 WorkstationCLM03Model::~WorkstationCLM03Model()
64 {}
65
66 void WorkstationCLM03Model::parseInit(sg_platf_host_cbarg_t host){
67   createResource(host->id);
68 }
69
70 WorkstationPtr WorkstationCLM03Model::createResource(const char *name){
71
72   WorkstationPtr workstation = new WorkstationCLM03(surf_workstation_model, name, NULL,
73                   (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL),
74                   (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL),
75                   static_cast<CpuPtr>(xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL)));
76   XBT_DEBUG("Create workstation %s with %ld mounted disks", name, xbt_dynar_length(workstation->p_storage));
77   xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, static_cast<ResourcePtr>(workstation));
78   return workstation;
79 }
80
81 double WorkstationCLM03Model::shareResources(double now){
82   adjustWeightOfDummyCpuActions();
83
84   double min_by_cpu = p_cpuModel->shareResources(now);
85   double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
86   double min_by_sto = -1;
87   if (p_cpuModel == surf_cpu_model_pm)
88         min_by_sto = surf_storage_model->shareResources(now);
89
90   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
91       this, surf_cpu_model_pm->getName(), min_by_cpu,
92             surf_network_model->getName(), min_by_net,
93             surf_storage_model->getName(), min_by_sto);
94
95   double res = max(max(min_by_cpu, min_by_net), min_by_sto);
96   if (min_by_cpu >= 0.0 && min_by_cpu < res)
97         res = min_by_cpu;
98   if (min_by_net >= 0.0 && min_by_net < res)
99         res = min_by_net;
100   if (min_by_sto >= 0.0 && min_by_sto < res)
101         res = min_by_sto;
102   return res;
103 }
104
105 void WorkstationCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
106   return;
107 }
108
109 ActionPtr WorkstationCLM03Model::executeParallelTask(int workstation_nb,
110                                         void **workstation_list,
111                                         double *computation_amount,
112                                         double *communication_amount,
113                                         double rate){
114 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
115   if ((workstation_nb == 1)
116       && (cost_or_zero(communication_amount, 0) == 0.0))
117     return ((WorkstationCLM03Ptr)workstation_list[0])->execute(computation_amount[0]);
118   else if ((workstation_nb == 1)
119            && (cost_or_zero(computation_amount, 0) == 0.0))
120     return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],communication_amount[0], rate);
121   else if ((workstation_nb == 2)
122              && (cost_or_zero(computation_amount, 0) == 0.0)
123              && (cost_or_zero(computation_amount, 1) == 0.0)) {
124     int i,nb = 0;
125     double value = 0.0;
126
127     for (i = 0; i < workstation_nb * workstation_nb; i++) {
128       if (cost_or_zero(communication_amount, i) > 0.0) {
129         nb++;
130         value = cost_or_zero(communication_amount, i);
131       }
132     }
133     if (nb == 1)
134       return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate);
135   }
136 #undef cost_or_zero
137
138   THROW_UNIMPLEMENTED;          /* This model does not implement parallel tasks */
139   return NULL;
140 }
141
142 /* returns an array of network_link_CM02_t */
143 xbt_dynar_t WorkstationCLM03Model::getRoute(WorkstationPtr src, WorkstationPtr dst)
144 {
145   XBT_DEBUG("ws_get_route");
146   return surf_network_model->getRoute(src->p_netElm, dst->p_netElm);
147 }
148
149 ActionPtr WorkstationCLM03Model::communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate){
150   return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
151 }
152
153
154
155 /************
156  * Resource *
157  ************/
158 WorkstationCLM03::WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
159   : Workstation(model, name, properties, storage, netElm, cpu) {}
160
161 bool WorkstationCLM03::isUsed(){
162   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
163   return -1;
164 }
165
166 void WorkstationCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
167   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
168 }
169
170 ActionPtr WorkstationCLM03::execute(double size) {
171   return p_cpu->execute(size);
172 }
173
174 ActionPtr WorkstationCLM03::sleep(double duration) {
175   return p_cpu->sleep(duration);
176 }
177
178 e_surf_resource_state_t WorkstationCLM03::getState() {
179   return p_cpu->getState();
180 }
181
182 /**********
183  * Action *
184  **********/