Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove XBT_INFO call
[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()
54  : WorkstationModel("Workstation")
55 {
56 }
57
58 WorkstationCLM03Model::~WorkstationCLM03Model()
59 {}
60
61 void WorkstationCLM03Model::parseInit(sg_platf_host_cbarg_t host){
62   createResource(host->id);
63 }
64
65 WorkstationPtr WorkstationCLM03Model::createResource(const char *name){
66
67   WorkstationPtr workstation = new WorkstationCLM03(surf_workstation_model, name, NULL,
68                   (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL),
69                   (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL),
70                   static_cast<CpuPtr>(xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL)));
71   XBT_DEBUG("Create workstation %s with %ld mounted disks", name, xbt_dynar_length(workstation->p_storage));
72   xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, static_cast<ResourcePtr>(workstation));
73   return workstation;
74 }
75
76 double WorkstationCLM03Model::shareResources(double now){
77   adjustWeightOfDummyCpuActions();
78
79   double min_by_cpu = p_cpuModel->shareResources(now);
80   double min_by_net = (strcmp(surf_network_model->getName(), "network NS3")) ? surf_network_model->shareResources(now) : -1;
81   double min_by_sto = -1;
82   if (p_cpuModel == surf_cpu_model_pm)
83         min_by_sto = surf_storage_model->shareResources(now);
84
85   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
86       this, surf_cpu_model_pm->getName(), min_by_cpu,
87             surf_network_model->getName(), min_by_net,
88             surf_storage_model->getName(), min_by_sto);
89
90   double res = max(max(min_by_cpu, min_by_net), min_by_sto);
91   if (min_by_cpu >= 0.0 && min_by_cpu < res)
92         res = min_by_cpu;
93   if (min_by_net >= 0.0 && min_by_net < res)
94         res = min_by_net;
95   if (min_by_sto >= 0.0 && min_by_sto < res)
96         res = min_by_sto;
97   return res;
98 }
99
100 void WorkstationCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
101   return;
102 }
103
104 ActionPtr WorkstationCLM03Model::executeParallelTask(int workstation_nb,
105                                         void **workstation_list,
106                                         double *computation_amount,
107                                         double *communication_amount,
108                                         double rate){
109 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
110   if ((workstation_nb == 1)
111       && (cost_or_zero(communication_amount, 0) == 0.0))
112     return ((WorkstationCLM03Ptr)workstation_list[0])->execute(computation_amount[0]);
113   else if ((workstation_nb == 1)
114            && (cost_or_zero(computation_amount, 0) == 0.0))
115     return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[0],communication_amount[0], rate);
116   else if ((workstation_nb == 2)
117              && (cost_or_zero(computation_amount, 0) == 0.0)
118              && (cost_or_zero(computation_amount, 1) == 0.0)) {
119     int i,nb = 0;
120     double value = 0.0;
121
122     for (i = 0; i < workstation_nb * workstation_nb; i++) {
123       if (cost_or_zero(communication_amount, i) > 0.0) {
124         nb++;
125         value = cost_or_zero(communication_amount, i);
126       }
127     }
128     if (nb == 1)
129       return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate);
130   }
131 #undef cost_or_zero
132
133   THROW_UNIMPLEMENTED;          /* This model does not implement parallel tasks */
134   return NULL;
135 }
136
137 ActionPtr WorkstationCLM03Model::communicate(WorkstationPtr src, WorkstationPtr dst, double size, double rate){
138   return surf_network_model->communicate(src->p_netElm, dst->p_netElm, size, rate);
139 }
140
141
142
143 /************
144  * Resource *
145  ************/
146 WorkstationCLM03::WorkstationCLM03(WorkstationModelPtr model, const char* name, xbt_dict_t properties, xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
147   : Workstation(model, name, properties, storage, netElm, cpu) {}
148
149 bool WorkstationCLM03::isUsed(){
150   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
151   return -1;
152 }
153
154 void WorkstationCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
155   THROW_IMPOSSIBLE;             /* This model does not implement parallel tasks */
156 }
157
158 ActionPtr WorkstationCLM03::execute(double size) {
159   return p_cpu->execute(size);
160 }
161
162 ActionPtr WorkstationCLM03::sleep(double duration) {
163   return p_cpu->sleep(duration);
164 }
165
166 e_surf_resource_state_t WorkstationCLM03::getState() {
167   return p_cpu->getState();
168 }
169
170 /**********
171  * Action *
172  **********/