Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
29878330743cca6df16c8cdfcbae7d2d75aa253a
[simgrid.git] / src / surf / host_clm03.cpp
1 /* Copyright (c) 2013-2015. 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 <cstdlib>
8
9 #include <algorithm>
10
11 #include "host_clm03.hpp"
12
13 #include "cpu_cas01.hpp"
14 #include "simgrid/sg_config.h"
15 #include "virtual_machine.hpp"
16
17 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_host);
18
19 /*************
20  * CallBacks *
21  *************/
22
23 /*********
24  * Model *
25  *********/
26
27 void surf_host_model_init_current_default(void)
28 {
29   surf_host_model = new simgrid::surf::HostCLM03Model();
30   xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "yes");
31   surf_cpu_model_init_Cas01();
32   surf_network_model_init_LegrandVelho();
33
34   xbt_dynar_push(all_existing_models, &surf_host_model);
35 }
36
37 void surf_host_model_init_compound()
38 {
39   xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
40   xbt_assert(surf_network_model, "No network model defined yet!");
41
42   surf_host_model = new simgrid::surf::HostCLM03Model();
43   xbt_dynar_push(all_existing_models, &surf_host_model);
44 }
45
46 namespace simgrid {
47 namespace surf {
48
49 double HostCLM03Model::shareResources(double now){
50   adjustWeightOfDummyCpuActions();
51
52   double min_by_cpu = surf_cpu_model_pm->shareResources(now);
53   double min_by_net = surf_network_model->shareResourcesIsIdempotent() ? surf_network_model->shareResources(now) : -1;
54   double min_by_sto = surf_storage_model->shareResources(now);
55
56   XBT_DEBUG("model %p, %s min_by_cpu %f, %s min_by_net %f, %s min_by_sto %f",
57       this, typeid(surf_cpu_model_pm).name(), min_by_cpu,
58                 typeid(surf_network_model).name(), min_by_net,
59                         typeid(surf_storage_model).name(), min_by_sto);
60
61   double res = std::max(std::max(min_by_cpu, min_by_net), min_by_sto);
62   if (min_by_cpu >= 0.0 && min_by_cpu < res)
63         res = min_by_cpu;
64   if (min_by_net >= 0.0 && min_by_net < res)
65         res = min_by_net;
66   if (min_by_sto >= 0.0 && min_by_sto < res)
67         res = min_by_sto;
68   return res;
69 }
70
71 void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){
72   return;
73 }
74
75 Action *HostCLM03Model::executeParallelTask(int host_nb,
76                                         sg_host_t *host_list,
77                                         double *flops_amount,
78                                         double *bytes_amount,
79                                         double rate){
80 #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0)
81   Action *action =NULL;
82   if ((host_nb == 1)
83       && (cost_or_zero(bytes_amount, 0) == 0.0)){
84     action = host_list[0]->pimpl_cpu->execute(flops_amount[0]);
85   } else if ((host_nb == 1)
86            && (cost_or_zero(flops_amount, 0) == 0.0)) {
87     action = surf_network_model->communicate(host_list[0]->pimpl_netcard,
88                                                  host_list[0]->pimpl_netcard,
89                                                                                          bytes_amount[0], rate);
90   } else if ((host_nb == 2)
91              && (cost_or_zero(flops_amount, 0) == 0.0)
92              && (cost_or_zero(flops_amount, 1) == 0.0)) {
93     int i,nb = 0;
94     double value = 0.0;
95
96     for (i = 0; i < host_nb * host_nb; i++) {
97       if (cost_or_zero(bytes_amount, i) > 0.0) {
98         nb++;
99         value = cost_or_zero(bytes_amount, i);
100       }
101     }
102     if (nb == 1){
103       action = surf_network_model->communicate(host_list[0]->pimpl_netcard,
104                                                    host_list[1]->pimpl_netcard,
105                                                                                            value, rate);
106     }
107   } else
108     THROW_UNIMPLEMENTED;      /* This model does not implement parallel tasks for more than 2 hosts */
109 #undef cost_or_zero
110   xbt_free(host_list);
111   return action;
112 }
113
114 }
115 }