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()
54 : WorkstationModel("Workstation")
58 WorkstationCLM03Model::~WorkstationCLM03Model()
61 void WorkstationCLM03Model::parseInit(sg_platf_host_cbarg_t host){
62 createResource(host->id);
65 WorkstationPtr WorkstationCLM03Model::createResource(const char *name){
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));
76 double WorkstationCLM03Model::shareResources(double now){
77 adjustWeightOfDummyCpuActions();
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);
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);
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)
93 if (min_by_net >= 0.0 && min_by_net < res)
95 if (min_by_sto >= 0.0 && min_by_sto < res)
100 void WorkstationCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
104 ActionPtr WorkstationCLM03Model::executeParallelTask(int workstation_nb,
105 void **workstation_list,
106 double *computation_amount,
107 double *communication_amount,
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)) {
122 for (i = 0; i < workstation_nb * workstation_nb; i++) {
123 if (cost_or_zero(communication_amount, i) > 0.0) {
125 value = cost_or_zero(communication_amount, i);
129 return communicate((WorkstationCLM03Ptr)workstation_list[0], (WorkstationCLM03Ptr)workstation_list[1],value, rate);
133 THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */
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);
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) {}
149 bool WorkstationCLM03::isUsed(){
150 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
154 void WorkstationCLM03::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/){
155 THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */
158 ActionPtr WorkstationCLM03::execute(double size) {
159 return p_cpu->execute(size);
162 ActionPtr WorkstationCLM03::sleep(double duration) {
163 return p_cpu->sleep(duration);
166 e_surf_resource_state_t WorkstationCLM03::getState() {
167 return p_cpu->getState();