1 /* Copyright (c) 2013-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "workstation_clm03.hpp"
8 #include "vm_workstation_interface.hpp"
9 #include "cpu_cas01.hpp"
10 #include "simgrid/sg_config.h"
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
18 static void workstation_new(sg_platf_host_cbarg_t host){
19 reinterpret_cast<WorkstationCLM03ModelPtr>(surf_workstation_model)->createResource(host->id);
26 void surf_workstation_model_init_current_default(void)
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;
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);
40 void surf_workstation_model_init_compound()
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();
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);
53 WorkstationCLM03Model::WorkstationCLM03Model(const char *name)
54 : WorkstationModel(name)
58 WorkstationCLM03Model::WorkstationCLM03Model()
59 : WorkstationModel("Workstation")
63 WorkstationCLM03Model::~WorkstationCLM03Model()
66 void WorkstationCLM03Model::parseInit(sg_platf_host_cbarg_t host){
67 createResource(host->id);
70 WorkstationPtr WorkstationCLM03Model::createResource(const char *name){
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));
81 double WorkstationCLM03Model::shareResources(double now){
82 adjustWeightOfDummyCpuActions();
84 double min_by_cpu = p_cpuModel->shareResources(now);
85 double min_by_net = surf_network_model->shareResources(now);
86 double min_by_sto = -1;
87 if (p_cpuModel == surf_cpu_model_pm)
88 min_by_sto = surf_storage_model->shareResources(now);
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);
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)
98 if (min_by_net >= 0.0 && min_by_net < res)
100 if (min_by_sto >= 0.0 && min_by_sto < res)
105 void WorkstationCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
109 ActionPtr WorkstationCLM03Model::executeParallelTask(int workstation_nb,
110 void **workstation_list,
111 double *computation_amount,
112 double *communication_amount,
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)) {
127 for (i = 0; i < workstation_nb * workstation_nb; i++) {
128 if (cost_or_zero(communication_amount, i) > 0.0) {
130 value = cost_or_zero(communication_amount, i);
134 return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate);
138 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
142 /* returns an array of network_link_CM02_t */
143 xbt_dynar_t WorkstationCLM03Model::getRoute(WorkstationPtr src, WorkstationPtr dst)
145 XBT_DEBUG("ws_get_route");
146 return surf_network_model->getRoute(src->p_netElm, dst->p_netElm);
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);
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) {}
161 bool WorkstationCLM03::isUsed(){
162 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
166 void WorkstationCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
167 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
170 ActionPtr WorkstationCLM03::execute(double size) {
171 return p_cpu->execute(size);
174 ActionPtr WorkstationCLM03::sleep(double duration) {
175 return p_cpu->sleep(duration);
178 e_surf_resource_state_t WorkstationCLM03::getState() {
179 return p_cpu->getState();