From e082f5068bf34dbe8b917be567bcf5f4b6776f8f Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 16 Jan 2016 15:23:07 +0100 Subject: [PATCH] move the vanilla def of executeParallelTask in HostModel Two of the three subclasses were redefining this method to the same content. --- src/surf/host_clm03.cpp | 39 ------------------------------------- src/surf/host_clm03.hpp | 7 ------- src/surf/host_interface.cpp | 39 +++++++++++++++++++++++++++++++++++++ src/surf/host_interface.hpp | 8 ++++---- src/surf/vm_hl13.cpp | 33 ------------------------------- src/surf/vm_hl13.hpp | 5 ----- 6 files changed, 43 insertions(+), 88 deletions(-) diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 2987833074..24f3f38ff0 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -72,44 +72,5 @@ void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){ return; } -Action *HostCLM03Model::executeParallelTask(int host_nb, - sg_host_t *host_list, - double *flops_amount, - double *bytes_amount, - double rate){ -#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) - Action *action =NULL; - if ((host_nb == 1) - && (cost_or_zero(bytes_amount, 0) == 0.0)){ - action = host_list[0]->pimpl_cpu->execute(flops_amount[0]); - } else if ((host_nb == 1) - && (cost_or_zero(flops_amount, 0) == 0.0)) { - action = surf_network_model->communicate(host_list[0]->pimpl_netcard, - host_list[0]->pimpl_netcard, - bytes_amount[0], rate); - } else if ((host_nb == 2) - && (cost_or_zero(flops_amount, 0) == 0.0) - && (cost_or_zero(flops_amount, 1) == 0.0)) { - int i,nb = 0; - double value = 0.0; - - for (i = 0; i < host_nb * host_nb; i++) { - if (cost_or_zero(bytes_amount, i) > 0.0) { - nb++; - value = cost_or_zero(bytes_amount, i); - } - } - if (nb == 1){ - action = surf_network_model->communicate(host_list[0]->pimpl_netcard, - host_list[1]->pimpl_netcard, - value, rate); - } - } else - THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks for more than 2 hosts */ -#undef cost_or_zero - xbt_free(host_list); - return action; -} - } } diff --git a/src/surf/host_clm03.hpp b/src/surf/host_clm03.hpp index 9c9c12339f..74bff01ee6 100644 --- a/src/surf/host_clm03.hpp +++ b/src/surf/host_clm03.hpp @@ -34,14 +34,7 @@ public: double shareResources(double now) override; void updateActionsState(double now, double delta) override; - - Action *executeParallelTask(int host_nb, - sg_host_t *host_list, - double *flops_amount, - double *bytes_amount, - double rate) override; }; - } } diff --git a/src/surf/host_interface.cpp b/src/surf/host_interface.cpp index dfaaa49184..34db01bf0f 100644 --- a/src/surf/host_interface.cpp +++ b/src/surf/host_interface.cpp @@ -75,6 +75,45 @@ void HostModel::adjustWeightOfDummyCpuActions() } } +Action *HostModel::executeParallelTask(int host_nb, + sg_host_t *host_list, + double *flops_amount, + double *bytes_amount, + double rate){ +#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) + Action *action =NULL; + if ((host_nb == 1) + && (cost_or_zero(bytes_amount, 0) == 0.0)){ + action = host_list[0]->pimpl_cpu->execute(flops_amount[0]); + } else if ((host_nb == 1) + && (cost_or_zero(flops_amount, 0) == 0.0)) { + action = surf_network_model->communicate(host_list[0]->pimpl_netcard, + host_list[0]->pimpl_netcard, + bytes_amount[0], rate); + } else if ((host_nb == 2) + && (cost_or_zero(flops_amount, 0) == 0.0) + && (cost_or_zero(flops_amount, 1) == 0.0)) { + int i,nb = 0; + double value = 0.0; + + for (i = 0; i < host_nb * host_nb; i++) { + if (cost_or_zero(bytes_amount, i) > 0.0) { + nb++; + value = cost_or_zero(bytes_amount, i); + } + } + if (nb == 1){ + action = surf_network_model->communicate(host_list[0]->pimpl_netcard, + host_list[1]->pimpl_netcard, + value, rate); + } + } else + THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks for more than 2 hosts */ +#undef cost_or_zero + xbt_free(host_list); + return action; +} + /************ * Resource * ************/ diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index 6ffdfa31cf..d861c9bb1b 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -57,10 +57,10 @@ public: virtual void adjustWeightOfDummyCpuActions(); virtual Action *executeParallelTask(int host_nb, - sg_host_t *host_list, - double *flops_amount, - double *bytes_amount, - double rate)=0; + sg_host_t *host_list, + double *flops_amount, + double *bytes_amount, + double rate); bool shareResourcesIsIdempotent() override {return true;} }; diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 2c25d80a71..55eaefdfd6 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -127,39 +127,6 @@ double VMHL13Model::shareResources(double now) return ret; } -Action *VMHL13Model::executeParallelTask(int host_nb, - sg_host_t *host_list, - double *flops_amount, - double *bytes_amount, - double rate){ -#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) - if ((host_nb == 1) - && (cost_or_zero(bytes_amount, 0) == 0.0)) - return host_list[0]->pimpl_cpu->execute(flops_amount[0]); - else if ((host_nb == 1) - && (cost_or_zero(flops_amount, 0) == 0.0)) - return surf_network_model_communicate(surf_network_model, host_list[0], host_list[0],bytes_amount[0], rate); - else if ((host_nb == 2) - && (cost_or_zero(flops_amount, 0) == 0.0) - && (cost_or_zero(flops_amount, 1) == 0.0)) { - int i,nb = 0; - double value = 0.0; - - for (i = 0; i < host_nb * host_nb; i++) { - if (cost_or_zero(bytes_amount, i) > 0.0) { - nb++; - value = cost_or_zero(bytes_amount, i); - } - } - if (nb == 1) - return surf_network_model_communicate(surf_network_model, host_list[0], host_list[1], value, rate); - } -#undef cost_or_zero - - THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks for more than 2 hosts. */ - return NULL; -} - /************ * Resource * ************/ diff --git a/src/surf/vm_hl13.hpp b/src/surf/vm_hl13.hpp index 04075eb8a6..1ed2fa0300 100644 --- a/src/surf/vm_hl13.hpp +++ b/src/surf/vm_hl13.hpp @@ -36,11 +36,6 @@ public: VirtualMachine *createVM(const char *name, sg_host_t host_PM) override; double shareResources(double now); void adjustWeightOfDummyCpuActions() override {}; - Action *executeParallelTask(int host_nb, - sg_host_t *host_list, - double *flops_amount, - double *bytes_amount, - double rate) override; void updateActionsState(double /*now*/, double /*delta*/) override; }; -- 2.20.1