From 76c04d71c8291e609107f81e5d3a3c4e4adbbef7 Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 3 Mar 2010 16:06:23 +0000 Subject: [PATCH] SD_SCHED_NO_COST: Constant to use as cost in SD_task_schedule() git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7174 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 3 +++ examples/simdag/sd_test2.c | 9 ++++---- include/simdag/simdag.h | 12 ++++++++++ src/simdag/sd_task.c | 45 ++++++++++++++++++++++++-------------- 4 files changed, 48 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcb6a2c547..5aec950fd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,9 @@ SimGrid (3.3.5-svn) unstable; urgency=low * Kill the useless "rate" argument of SD_task_get_execution_time() Everyone used to provide -1 as a value, it was not used, and the semantic of a possible use wasn't even clear. + * SD_SCHED_NO_COST: Constant to use as cost in SD_task_schedule() + either as comm costs or compute costs to mean that there is no + such thing for that specific task. MSG: * In trace replay, allow to have one trace file per process. Give the specific trace file as argument of each process, diff --git a/examples/simdag/sd_test2.c b/examples/simdag/sd_test2.c index 893654c3c0..99a85c7cf0 100644 --- a/examples/simdag/sd_test2.c +++ b/examples/simdag/sd_test2.c @@ -31,7 +31,6 @@ int main(int argc, char **argv) SD_task_t InterRedist; SD_task_t taskFinal; SD_task_t ParComp_wcomm2; - const double no_cost[] = { 1.0, 1.0 }; SD_workstation_t PtoPcomm1_hosts[2]; SD_workstation_t PtoPcomm2_hosts[2]; double PtoPcomm1_table[] = { 0, 12500000, 0, 0 }; /* 100Mb */ @@ -171,10 +170,10 @@ int main(int argc, char **argv) /* scheduling the tasks */ - SD_task_schedule(taskInit, 1, hosts, no_cost, no_cost, -1.0); - SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, no_cost, PtoPcomm1_table, + SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST, -1.0); + SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST, PtoPcomm1_table, -1.0); - SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, no_cost, PtoPcomm2_table, + SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST, PtoPcomm2_table, -1.0); SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts, ParComp_wocomm_cost, ParComp_wocomm_table, -1.0); @@ -186,7 +185,7 @@ int main(int argc, char **argv) InterRedist_table, -1.0); SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts, ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0); - SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, no_cost, -1.0); + SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, SD_SCHED_NO_COST, -1.0); /* let's launch the simulation! */ changed_tasks = SD_simulate(-1.0); diff --git a/include/simdag/simdag.h b/include/simdag/simdag.h index 9b48418df2..8dcf5fb17f 100644 --- a/include/simdag/simdag.h +++ b/include/simdag/simdag.h @@ -145,6 +145,18 @@ XBT_PUBLIC(SD_task_t) SD_task_create_comm_e2e(const char*name,void *data,double XBT_PUBLIC(void) SD_task_schedulev(SD_task_t task, int count, const SD_workstation_t*list); XBT_PUBLIC(void) SD_task_schedulel(SD_task_t task, int count, ...); +/** @brief A constant to use in SD_task_schedule to mean that there is no cost. + * + * For example, create a pure computation task (no comm) like this: + * + * SD_task_schedule(task, my_workstation_nb, + * my_workstation_list, + * my_computation_amount, + * SD_TASK_SCHED_NO_COST, + * my_rate); + */ +#define SD_SCHED_NO_COST NULL + /** @} */ diff --git a/src/simdag/sd_task.c b/src/simdag/sd_task.c index 959eebdcf0..b5728f14be 100644 --- a/src/simdag/sd_task.c +++ b/src/simdag/sd_task.c @@ -711,14 +711,22 @@ void SD_task_schedule(SD_task_t task, int workstation_count, task->workstation_nb = workstation_count; task->rate = rate; - task->computation_amount = xbt_new(double, workstation_count); - memcpy(task->computation_amount, computation_amount, - sizeof(double) * workstation_count); + if (computation_amount) { + task->computation_amount = xbt_new(double, workstation_count); + memcpy(task->computation_amount, computation_amount, + sizeof(double) * workstation_count); + } else { + task->computation_amount = NULL; + } communication_nb = workstation_count * workstation_count; - task->communication_amount = xbt_new(double, communication_nb); - memcpy(task->communication_amount, communication_amount, - sizeof(double) * communication_nb); + if (communication_amount) { + task->communication_amount = xbt_new(double, communication_nb); + memcpy(task->communication_amount, communication_amount, + sizeof(double) * communication_nb); + } else { + task->communication_amount = NULL; + } task->workstation_list = xbt_new(SD_workstation_t, workstation_count); memcpy(task->workstation_list, workstation_list, @@ -816,31 +824,34 @@ void __SD_task_really_run(SD_task_t task) /* we have to create a Surf workstation array instead of the SimDag workstation array */ surf_workstations = xbt_new(void *, task->workstation_nb); - for (i = 0; i < task->workstation_nb; i++) { + for (i = 0; i < task->workstation_nb; i++) surf_workstations[i] = task->workstation_list[i]->surf_workstation; - } + + /* It's allowed to pass a NULL vector as cost to mean vector of 0.0 (easing user's life). Let's deal with it */ +#define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) task->surf_action = NULL; - if ((task->workstation_nb == 1) && (task->communication_amount[0] == 0.0)) { + if ((task->workstation_nb == 1) && (cost_or_zero(task->communication_amount,0) == 0.0)) { task->surf_action = surf_workstation_model->extension. - workstation.execute(surf_workstations[0], task->computation_amount[0]); + workstation.execute(surf_workstations[0], cost_or_zero(task->computation_amount,0)); } else if ((task->workstation_nb == 1) - && (task->computation_amount[0] == 0.0)) { + && (cost_or_zero(task->computation_amount,0) == 0.0)) { + task->surf_action = surf_workstation_model->extension. workstation.communicate(surf_workstations[0], surf_workstations[0], - task->communication_amount[0], task->rate); + cost_or_zero(task->communication_amount,0), task->rate); } else if ((task->workstation_nb == 2) - && (task->computation_amount[0] == 0.0) - && (task->computation_amount[1] == 0.0)) { + && (cost_or_zero(task->computation_amount,0) == 0.0) + && (cost_or_zero(task->computation_amount,1) == 0.0)) { int nb = 0; double value = 0.0; for (i = 0; i < task->workstation_nb * task->workstation_nb; i++) { - if (task->communication_amount[i] > 0.0) { + if (cost_or_zero(task->communication_amount,i) > 0.0) { nb++; - value = task->communication_amount[i]; + value = cost_or_zero(task->communication_amount,i); } } if (nb == 1) { @@ -850,6 +861,8 @@ void __SD_task_really_run(SD_task_t task) value, task->rate); } } +#undef cost_or_zero + if (!task->surf_action) { double *computation_amount = xbt_new(double, task->workstation_nb); double *communication_amount = xbt_new(double, task->workstation_nb * -- 2.20.1