X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/40bbc8645482f0b800c24b4cffd13e58d60e45fd..b08c515d1ded5726d50e3e9e11c03260e3e1546d:/src/simdag/sd_task.c diff --git a/src/simdag/sd_task.c b/src/simdag/sd_task.c index 058e3bfb25..c098fd1f73 100644 --- a/src/simdag/sd_task.c +++ b/src/simdag/sd_task.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011. The SimGrid Team. +/* Copyright (c) 2006-2013. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -91,7 +91,7 @@ SD_task_t SD_task_create(const char *name, void *data, double amount) sd_global->task_number++; #ifdef HAVE_TRACING - task->category = NULL; + TRACE_sd_task_create(task); #endif return task; @@ -125,6 +125,12 @@ SD_task_t SD_task_create_comm_e2e(const char *name, void *data, SD_task_t res = SD_task_create_sized(name, data, amount, 2); res->communication_amount[2] = amount; res->kind = SD_TASK_COMM_E2E; + +#ifdef HAVE_TRACING + TRACE_category("COMM_E2E"); + TRACE_sd_set_task_category(res, "COMM_E2E"); +#endif + return res; } @@ -149,7 +155,13 @@ SD_task_t SD_task_create_comp_seq(const char *name, void *data, SD_task_t res = SD_task_create_sized(name, data, amount, 1); res->computation_amount[0] = amount; res->kind = SD_TASK_COMP_SEQ; - return res; + +#ifdef HAVE_TRACING + TRACE_category("COMP_SEQ"); + TRACE_sd_set_task_category(res, "COMP_SEQ"); +#endif + +return res; } /** @brief create a parallel computation task that can then be auto-scheduled @@ -160,8 +172,8 @@ SD_task_t SD_task_create_comp_seq(const char *name, void *data, * mandatory power. * * A parallel computation can be scheduled on any number of host. - * The underlying speedup model is Amdahl's law. - * To be auto-scheduled, \see SD_task_distribute_comp_amdhal has to be called + * The underlying speedup model is Amdahl's law. + * To be auto-scheduled, \see SD_task_distribute_comp_amdahl has to be called * first. * \param name the name of the task (can be \c NULL) * \param data the user data you want to associate with the task (can be \c NULL) @@ -178,6 +190,12 @@ SD_task_t SD_task_create_comp_par_amdahl(const char *name, void *data, SD_task_t res = SD_task_create(name, data, amount); res->alpha = alpha; res->kind = SD_TASK_COMP_PAR_AMDAHL; + +#ifdef HAVE_TRACING + TRACE_category("COMP_PAR_AMDAHL"); + TRACE_sd_set_task_category(res, "COMP_PAR_AMDAHL"); +#endif + return res; } @@ -206,6 +224,12 @@ SD_task_t SD_task_create_comm_par_mxn_1d_block(const char *name, void *data, SD_task_t res = SD_task_create(name, data, amount); res->workstation_list=NULL; res->kind = SD_TASK_COMM_PAR_MXN_1D_BLOCK; + +#ifdef HAVE_TRACING + TRACE_category("COMM_PAR_MXN_1D_BLOCK"); + TRACE_sd_set_task_category(res, "COMM_PAR_MXN_1D_BLOCK"); +#endif + return res; } @@ -240,7 +264,7 @@ void SD_task_destroy(SD_task_t task) xbt_free(task->computation_amount); #ifdef HAVE_TRACING - if (task->category) xbt_free(task->category); + TRACE_sd_task_destroy(task); #endif xbt_mallocator_release(sd_global->task_mallocator,task); @@ -452,7 +476,27 @@ double SD_task_get_amount(SD_task_t task) } /** - * \brief Returns the alpha parameter of a SD_TASK_COMP_PAR_AMDAH task + * \brief Sets the total amount of work of a task + * For sequential typed tasks (COMP_SEQ and COMM_E2E), it also sets the + * appropriate values in the computation_amount and communication_amount arrays + * respectively. Nothing more than modifying task->amount is done for paralle + * typed tasks (COMP_PAR_AMDAHL and COMM_PAR_MXN_1D_BLOCK) as the distribution + * of the amount of work is done at scheduling time. + * + * \param task a task + * \param amount the new amount of work to execute + */ +void SD_task_set_amount(SD_task_t task, double amount) +{ + task->amount = amount; + if (task->kind == SD_TASK_COMP_SEQ) + task->computation_amount[0] = amount; + if (task->kind == SD_TASK_COMM_E2E) + task->communication_amount[2] = amount; +} + +/** + * \brief Returns the alpha parameter of a SD_TASK_COMP_PAR_AMDAHL task * * \param task a parallel task assuming Amdahl's law as speedup model * \return the alpha parameter (serial part of a task in percent) for this task @@ -525,6 +569,12 @@ void SD_task_dump(SD_task_t task) XBT_INFO(" - (unknown kind %d)", task->kind); } } + +#ifdef HAVE_TRACING + if (task->category) + XBT_INFO(" - tracing category: %s", task->category); +#endif + XBT_INFO(" - amount: %.0f", SD_task_get_amount(task)); if (task->kind == SD_TASK_COMP_PAR_AMDAHL) XBT_INFO(" - alpha: %.2f", task->alpha); @@ -591,9 +641,9 @@ void SD_task_dependency_add(const char *name, void *data, SD_task_t src, SD_task_t dst) { xbt_dynar_t dynar; - int length; + unsigned long length; int found = 0; - int i; + unsigned long i; SD_dependency_t dependency; dynar = src->tasks_after; @@ -622,7 +672,7 @@ void SD_task_dependency_add(const char *name, void *data, SD_task_t src, for (i = 0; i < length && !found; i++) { xbt_dynar_get_cpy(dynar, i, &dependency); found = (dependency->dst == dst); - XBT_DEBUG("Dependency %d: dependency->dst = %s", i, + XBT_DEBUG("Dependency %lu: dependency->dst = %s", i, SD_task_get_name(dependency->dst)); } @@ -716,9 +766,9 @@ void SD_task_dependency_remove(SD_task_t src, SD_task_t dst) { xbt_dynar_t dynar; - int length; + unsigned long length; int found = 0; - int i; + unsigned long i; SD_dependency_t dependency; /* remove the dependency from src->tasks_after */ @@ -787,9 +837,9 @@ void *SD_task_dependency_get_data(SD_task_t src, SD_task_t dst) { xbt_dynar_t dynar; - int length; + unsigned long length; int found = 0; - int i; + unsigned long i; SD_dependency_t dependency; dynar = src->tasks_after; @@ -1011,6 +1061,7 @@ void SD_task_unschedule(SD_task_t task) && ((task->kind == SD_TASK_COMP_PAR_AMDAHL) || (task->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK))) { /* Don't free scheduling data for typed tasks */ __SD_task_destroy_scheduling_data(task); + xbt_free(task->workstation_list); task->workstation_list=NULL; task->workstation_nb = 0; } @@ -1379,7 +1430,7 @@ double SD_task_get_finish_time(SD_task_t task) /** @brief Blah * */ -void SD_task_distribute_comp_amdhal(SD_task_t task, int ws_count) +void SD_task_distribute_comp_amdahl(SD_task_t task, int ws_count) { int i; xbt_assert(task->kind == SD_TASK_COMP_PAR_AMDAHL, @@ -1388,8 +1439,7 @@ void SD_task_distribute_comp_amdhal(SD_task_t task, int ws_count) SD_task_get_name(task)); task->computation_amount = xbt_new0(double, ws_count); task->communication_amount = xbt_new0(double, ws_count * ws_count); - if (task->workstation_list) - xbt_free(task->workstation_list); + xbt_free(task->workstation_list); task->workstation_nb = ws_count; task->workstation_list = xbt_new0(SD_workstation_t, ws_count); @@ -1432,7 +1482,7 @@ void SD_task_schedulev(SD_task_t task, int count, SD_task_get_name(task)); switch (task->kind) { case SD_TASK_COMP_PAR_AMDAHL: - SD_task_distribute_comp_amdhal(task, count); + SD_task_distribute_comp_amdahl(task, count); case SD_TASK_COMM_E2E: case SD_TASK_COMP_SEQ: xbt_assert(task->workstation_nb == count, @@ -1509,7 +1559,7 @@ void SD_task_schedulev(SD_task_t task, int count, * located (and start them if runnable) */ if (task->kind == SD_TASK_COMP_PAR_AMDAHL) { XBT_VERB("Schedule computation task %s on %d workstations. %.f flops" - " will be distributed following Amdahl'Law", + " will be distributed following Amdahl's Law", SD_task_get_name(task), task->workstation_nb, task->computation_amount[0]); xbt_dynar_foreach(task->tasks_before, cpt, dep) { @@ -1539,11 +1589,8 @@ void SD_task_schedulev(SD_task_t task, int count, task->workstation_list[i]; before->workstation_nb += count; - if (before->computation_amount) - xbt_free(before->computation_amount); - if (before->communication_amount) - xbt_free(before->communication_amount); - + xbt_free(before->computation_amount); + xbt_free(before->communication_amount); before->computation_amount = xbt_new0(double, before->workstation_nb); before->communication_amount = xbt_new0(double, @@ -1608,10 +1655,8 @@ void SD_task_schedulev(SD_task_t task, int count, after->workstation_nb += count; - if (after->computation_amount) - xbt_free(after->computation_amount); - if (after->communication_amount) - xbt_free(after->communication_amount); + xbt_free(after->computation_amount); + xbt_free(after->communication_amount); after->computation_amount = xbt_new0(double, after->workstation_nb); after->communication_amount = xbt_new0(double, @@ -1669,50 +1714,3 @@ void SD_task_schedulel(SD_task_t task, int count, ...) SD_task_schedulev(task, count, list); free(list); } - -/** - * \brief Sets the tracing category of a task. - * - * This function should be called after the creation of a - * SimDAG task, to define the category of that task. The first - * parameter must contain a task that was created with the - * function #SD_task_create. The second parameter must contain - * a category that was previously declared with the function - * #TRACE_category. - * - * \param task The task to be considered - * \param category the name of the category to be associated to the task - * - * \see SD_task_get_category, TRACE_category, TRACE_category_with_color - */ -void SD_task_set_category (SD_task_t task, const char *category) -{ -#ifdef HAVE_TRACING - if (!TRACE_is_enabled()) return; - if (task == NULL) return; - if (category == NULL){ - if (task->category) xbt_free (task->category); - task->category = NULL; - }else{ - task->category = xbt_strdup (category); - } -#endif -} - -/** - * \brief Gets the current tracing category of a task. - * - * \param task The task to be considered - * - * \see SD_task_set_category - * - * \return Returns the name of the tracing category of the given task, NULL otherwise - */ -const char *SD_task_get_category (SD_task_t task) -{ -#ifdef HAVE_TRACING - return task->category; -#else - return NULL; -#endif -}