From 6891978f752ac5655597efb35ab4505f5181f572 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 20 Jul 2015 23:13:01 +0200 Subject: [PATCH 1/1] less void*, more sg_host_t --- src/include/surf/surf.h | 2 +- src/simdag/sd_task.c | 11 +++++------ src/simix/smx_host.c | 10 +++++----- src/surf/host_clm03.cpp | 12 ++++++------ src/surf/host_clm03.hpp | 8 ++++---- src/surf/host_interface.hpp | 8 ++++---- src/surf/host_ptask_L07.cpp | 17 ++++++++--------- src/surf/host_ptask_L07.hpp | 10 +++++----- src/surf/network_interface.hpp | 3 +-- src/surf/surf_c_bindings.cpp | 2 +- src/surf/vm_hl13.cpp | 14 +++++++------- src/surf/vm_hl13.hpp | 8 ++++---- 12 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index fc2a6681b7..3d2b1f7a66 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -258,7 +258,7 @@ XBT_PUBLIC(int) surf_model_running_action_set_size(surf_model_t model); */ XBT_PUBLIC(surf_action_t) surf_host_model_execute_parallel_task(surf_host_model_t model, int host_nb, - void **host_list, + sg_host_t *host_list, double *flops_amount, double *bytes_amount, double rate); diff --git a/src/simdag/sd_task.c b/src/simdag/sd_task.c index 0907c4f9e4..01b1ee639b 100644 --- a/src/simdag/sd_task.c +++ b/src/simdag/sd_task.c @@ -1090,7 +1090,7 @@ void __SD_task_really_run(SD_task_t task) { int i; - void **surf_hosts; + sg_host_t *hosts; xbt_assert(__SD_task_is_runnable_or_in_fifo(task), "Task '%s' is not runnable or in a fifo! Task state: %d", @@ -1117,12 +1117,11 @@ void __SD_task_really_run(SD_task_t task) /* start the task */ - /* we have to create a Surf workstation array instead of the SimDag - * workstation array */ - surf_hosts = xbt_new(void *, host_nb); + /* Copy the elements of the task into the action */ + hosts = xbt_new(sg_host_t, host_nb); for (i = 0; i < host_nb; i++) - surf_hosts[i] = surf_host_resource_priv(task->workstation_list[i]); + hosts[i] = task->workstation_list[i]; double *flops_amount = xbt_new0(double, host_nb); double *bytes_amount = xbt_new0(double, host_nb * host_nb); @@ -1137,7 +1136,7 @@ void __SD_task_really_run(SD_task_t task) task->surf_action = surf_host_model_execute_parallel_task((surf_host_model_t)surf_host_model, host_nb, - surf_hosts, + hosts, flops_amount, bytes_amount, task->rate); diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index bac8423183..da124c71d8 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -379,7 +379,7 @@ smx_synchro_t SIMIX_host_parallel_execute(const char *name, double *flops_amount, double *bytes_amount, double amount, double rate){ - void **surf_host_list = NULL; + sg_host_t*host_list_cpy = NULL; int i; /* alloc structures and initialize */ @@ -391,9 +391,9 @@ smx_synchro_t SIMIX_host_parallel_execute(const char *name, synchro->category = NULL; /* set surf's synchro */ - surf_host_list = xbt_new0(void *, host_nb); + host_list_cpy = xbt_new0(sg_host_t, host_nb); for (i = 0; i < host_nb; i++) - surf_host_list[i] = surf_host_resource_priv(host_list[i]); + host_list_cpy[i] = host_list[i]; /* FIXME: what happens if host_list contains VMs and PMs. If @@ -411,8 +411,8 @@ smx_synchro_t SIMIX_host_parallel_execute(const char *name, /* set surf's synchro */ if (!MC_is_active() && !MC_record_replay_is_active()) { synchro->execution.surf_exec = - surf_host_model_execute_parallel_task((surf_host_model_t)surf_host_model, - host_nb, surf_host_list, flops_amount, bytes_amount, rate); + surf_host_model_execute_parallel_task(surf_host_model, + host_nb, host_list_cpy, flops_amount, bytes_amount, rate); surf_action_set_data(synchro->execution.surf_exec, synchro); } diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 740b9ef189..22fcb9c105 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -84,7 +84,7 @@ void HostCLM03Model::updateActionsState(double /*now*/, double /*delta*/){ } Action *HostCLM03Model::executeParallelTask(int host_nb, - void **host_list, + sg_host_t *host_list, double *flops_amount, double *bytes_amount, double rate){ @@ -92,11 +92,11 @@ Action *HostCLM03Model::executeParallelTask(int host_nb, Action *action =NULL; if ((host_nb == 1) && (cost_or_zero(bytes_amount, 0) == 0.0)){ - action = static_cast(host_list[0])->execute(flops_amount[0]); + action = surf_host_execute(host_list[0],flops_amount[0]); } else if ((host_nb == 1) && (cost_or_zero(flops_amount, 0) == 0.0)) { - action = surf_network_model->communicate(static_cast(host_list[0])->p_netElm, - static_cast(host_list[0])->p_netElm, + action = surf_network_model->communicate(sg_host_edge(host_list[0]), + sg_host_edge(host_list[0]), bytes_amount[0], rate); } else if ((host_nb == 2) && (cost_or_zero(flops_amount, 0) == 0.0) @@ -111,8 +111,8 @@ Action *HostCLM03Model::executeParallelTask(int host_nb, } } if (nb == 1){ - action = surf_network_model->communicate(static_cast(host_list[0])->p_netElm, - static_cast(host_list[1])->p_netElm, + action = surf_network_model->communicate(sg_host_edge(host_list[0]), + sg_host_edge(host_list[1]), value, rate); } } else diff --git a/src/surf/host_clm03.hpp b/src/surf/host_clm03.hpp index d625716824..ef1484b720 100644 --- a/src/surf/host_clm03.hpp +++ b/src/surf/host_clm03.hpp @@ -34,10 +34,10 @@ public: void updateActionsState(double now, double delta); Action *executeParallelTask(int host_nb, - void **host_list, - double *flops_amount, - double *bytes_amount, - double rate); + sg_host_t *host_list, + double *flops_amount, + double *bytes_amount, + double rate); }; /************ diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index 71fd6887f0..685925d237 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -68,10 +68,10 @@ public: virtual void adjustWeightOfDummyCpuActions(); virtual Action *executeParallelTask(int host_nb, - void **host_list, - double *flops_amount, - double *bytes_amount, - double rate)=0; + sg_host_t *host_list, + double *flops_amount, + double *bytes_amount, + double rate)=0; bool shareResourcesIsIdempotent() {return true;} }; diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index b8a9d6f755..7212d00155 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -168,7 +168,7 @@ void HostL07Model::updateActionsState(double /*now*/, double delta) { } Action *HostL07Model::executeParallelTask(int host_nb, - void **host_list, + sg_host_t*host_list, double *flops_amount, double *bytes_amount, double rate) @@ -181,7 +181,7 @@ Action *HostL07Model::executeParallelTask(int host_nb, action->p_edgeList->reserve(host_nb); for (int i = 0; ip_edgeList->push_back(static_cast(host_list[i])->p_netElm); + action->p_edgeList->push_back(sg_host_edge(host_list[i])); if (ptask_parallel_task_link_set == NULL) ptask_parallel_task_link_set = xbt_dict_new_homogeneous(NULL); @@ -235,7 +235,7 @@ Action *HostL07Model::executeParallelTask(int host_nb, for (int i = 0; i < host_nb; i++) lmm_expand(ptask_maxmin_system, - static_cast(host_list[i])->p_cpu->getConstraint(), + sg_host_surfcpu(host_list[i])->getConstraint(), action->getVariable(), flops_amount[i]); for (int i = 0; i < host_nb; i++) { @@ -287,13 +287,13 @@ Host *HostL07Model::createHost(const char *name) Action *NetworkL07Model::communicate(RoutingEdge *src, RoutingEdge *dst, double size, double rate) { - void **host_list = xbt_new0(void *, 2); + sg_host_t*host_list = xbt_new0(sg_host_t, 2); double *flops_amount = xbt_new0(double, 2); double *bytes_amount = xbt_new0(double, 4); Action *res = NULL; - host_list[0] = xbt_lib_get_level(xbt_lib_get_elm_or_null(host_lib, src->getName()), SURF_HOST_LEVEL); - host_list[1] = xbt_lib_get_level(xbt_lib_get_elm_or_null(host_lib, dst->getName()), SURF_HOST_LEVEL); + host_list[0] = sg_host_by_name(src->getName()); + host_list[1] = sg_host_by_name(dst->getName()); bytes_amount[1] = size; res = p_hostModel->executeParallelTask(2, host_list, @@ -550,12 +550,11 @@ e_surf_resource_state_t HostL07::getState() { Action *HostL07::execute(double size) { - void **host_list = xbt_new0(void *, 1); + sg_host_t*host_list = xbt_new0(sg_host_t, 1); double *flops_amount = xbt_new0(double, 1); double *bytes_amount = xbt_new0(double, 1); - host_list[0] = this; - bytes_amount[0] = 0.0; + host_list[0] = sg_host_by_name(getName()); flops_amount[0] = size; return static_cast(getModel())->executeParallelTask(1, host_list, diff --git a/src/surf/host_ptask_L07.hpp b/src/surf/host_ptask_L07.hpp index dba86163e7..c265a522a1 100644 --- a/src/surf/host_ptask_L07.hpp +++ b/src/surf/host_ptask_L07.hpp @@ -39,10 +39,10 @@ public: void updateActionsState(double now, double delta); Host *createHost(const char *name); Action *executeParallelTask(int host_nb, - void **host_list, - double *flops_amount, - double *bytes_amount, - double rate); + sg_host_t *host_list, + double *flops_amount, + double *bytes_amount, + double rate); xbt_dynar_t getRoute(Host *src, Host *dst); void addTraces(); NetworkModel *p_networkModel; @@ -161,7 +161,7 @@ class L07Action : public HostAction { friend Action *HostL07::execute(double size); friend Action *HostL07::sleep(double duration); friend Action *HostL07Model::executeParallelTask(int host_nb, - void **host_list, + sg_host_t*host_list, double *flops_amount, double *bytes_amount, double rate); diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index e2bd2b4087..1709450819 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -264,8 +264,7 @@ public: */ class NetworkAction : public Action { public: - /** - * @brief NetworkAction constructor + /** @brief Constructor * * @param model The NetworkModel associated to this NetworkAction * @param cost The cost of this NetworkAction in [TODO] diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 9abcc61b78..260984f828 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -227,7 +227,7 @@ int surf_model_running_action_set_size(surf_model_t model){ surf_action_t surf_host_model_execute_parallel_task(surf_host_model_t model, int host_nb, - void **host_list, + sg_host_t *host_list, double *flops_amount, double *bytes_amount, double rate){ diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index 1a1777cf51..918df46b23 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -173,17 +173,17 @@ double VMHL13Model::shareResources(double now) } Action *VMHL13Model::executeParallelTask(int host_nb, - void **host_list, - double *flops_amount, - double *bytes_amount, - double rate){ + 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 static_cast(host_list[0])->execute(flops_amount[0]); + return surf_host_execute(host_list[0], flops_amount[0]); else if ((host_nb == 1) && (cost_or_zero(flops_amount, 0) == 0.0)) - return surf_network_model->communicate(static_cast(host_list[0])->p_netElm, static_cast(host_list[0])->p_netElm,bytes_amount[0], rate); + 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)) { @@ -197,7 +197,7 @@ Action *VMHL13Model::executeParallelTask(int host_nb, } } if (nb == 1) - return surf_network_model->communicate(static_cast(host_list[0])->p_netElm, static_cast(host_list[1])->p_netElm,value, rate); + return surf_network_model_communicate(surf_network_model, host_list[0], host_list[1], value, rate); } #undef cost_or_zero diff --git a/src/surf/vm_hl13.hpp b/src/surf/vm_hl13.hpp index aee4191fe2..80a6fe6bd1 100644 --- a/src/surf/vm_hl13.hpp +++ b/src/surf/vm_hl13.hpp @@ -32,10 +32,10 @@ public: double shareResources(double now); void adjustWeightOfDummyCpuActions() {}; Action *executeParallelTask(int host_nb, - void **host_list, - double *flops_amount, - double *bytes_amount, - double rate); + sg_host_t *host_list, + double *flops_amount, + double *bytes_amount, + double rate); void updateActionsState(double /*now*/, double /*delta*/); }; -- 2.20.1