X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/48efae676c3604efffe21365b2d525e578fd22e5..45bf16f90c9dc4f28344655ccec87b26f7f3f0ba:/src/msg/msg_task.cpp diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index a3b6d203ee..e2adf779f1 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -19,25 +19,39 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_task, msg, "Logging specific to MSG (task)"); +void simdata_task::reportMultipleUse() const +{ + if (msg_global->debug_multiple_use){ + XBT_ERROR("This task is already used in there:"); + // TODO, backtrace + XBT_ERROR(""); + XBT_ERROR("And you try to reuse it from here:"); + xbt_backtrace_display_current(); + } else { + xbt_die("This task is still being used somewhere else. You cannot send it now. Go fix your code!" + "(use --cfg=msg/debug-multiple-use:on to get the backtrace of the other process)"); + } +} + /********************************* Task **************************************/ /** \ingroup m_task_management * \brief Creates a new #msg_task_t. * * A constructor for #msg_task_t taking four arguments and returning the corresponding object. - * \param name a name for the object. It is for user-level information and can be NULL. + * \param name a name for the object. It is for user-level information and can be nullptr. * \param flop_amount a value of the processing amount (in flop) needed to process this new task. * If 0, then it cannot be executed with MSG_task_execute(). This value has to be >=0. * \param message_size a value of the amount of data (in bytes) needed to transfer this new task. If 0, then it cannot * be transfered with MSG_task_send() and MSG_task_recv(). This value has to be >=0. * \param data a pointer to any data may want to attach to the new object. It is for user-level information and can - * be NULL. It can be retrieved with the function \ref MSG_task_get_data. + * be nullptr. It can be retrieved with the function \ref MSG_task_get_data. * \see msg_task_t * \return The new corresponding object. */ msg_task_t MSG_task_create(const char *name, double flop_amount, double message_size, void *data) { msg_task_t task = xbt_new(s_msg_task_t, 1); - simdata_task_t simdata = xbt_new(s_simdata_task_t, 1); + simdata_task_t simdata = new s_simdata_task_t(); task->simdata = simdata; /* Task structure */ @@ -45,23 +59,23 @@ msg_task_t MSG_task_create(const char *name, double flop_amount, double message_ task->data = data; /* Simulator Data */ - simdata->compute = NULL; - simdata->comm = NULL; + simdata->compute = nullptr; + simdata->comm = nullptr; simdata->bytes_amount = message_size; simdata->flops_amount = flop_amount; - simdata->sender = NULL; - simdata->receiver = NULL; - simdata->source = NULL; + simdata->sender = nullptr; + simdata->receiver = nullptr; + simdata->source = nullptr; simdata->priority = 1.0; simdata->bound = 0; - simdata->affinity_mask_db = xbt_dict_new_homogeneous(NULL); + simdata->affinity_mask_db = xbt_dict_new_homogeneous(nullptr); simdata->rate = -1.0; simdata->isused = 0; simdata->host_nb = 0; - simdata->host_list = NULL; - simdata->flops_parallel_amount = NULL; - simdata->bytes_parallel_amount = NULL; + simdata->host_list = nullptr; + simdata->flops_parallel_amount = nullptr; + simdata->bytes_parallel_amount = nullptr; TRACE_msg_task_create(task); return task; @@ -71,14 +85,14 @@ msg_task_t MSG_task_create(const char *name, double flop_amount, double message_ * \brief Creates a new #msg_task_t (a parallel one....). * * A constructor for #msg_task_t taking six arguments and returning the corresponding object. - * \param name a name for the object. It is for user-level information and can be NULL. + * \param name a name for the object. It is for user-level information and can be nullptr. * \param host_nb the number of hosts implied in the parallel task. * \param host_list an array of \p host_nb msg_host_t. * \param flops_amount an array of \p host_nb doubles. * flops_amount[i] is the total number of operations that have to be performed on host_list[i]. * \param bytes_amount an array of \p host_nb* \p host_nb doubles. * \param data a pointer to any data may want to attach to the new object. - * It is for user-level information and can be NULL. + * It is for user-level information and can be nullptr. * It can be retrieved with the function \ref MSG_task_get_data. * \see msg_task_t * \return The new corresponding object. @@ -109,7 +123,7 @@ msg_task_t MSG_parallel_task_create(const char *name, int host_nb, const msg_hos */ void *MSG_task_get_data(msg_task_t task) { - xbt_assert((task != NULL), "Invalid parameter"); + xbt_assert((task != nullptr), "Invalid parameter"); return (task->data); } @@ -120,7 +134,7 @@ void *MSG_task_get_data(msg_task_t task) */ void MSG_task_set_data(msg_task_t task, void *data) { - xbt_assert((task != NULL), "Invalid parameter"); + xbt_assert((task != nullptr), "Invalid parameter"); task->data = data; } @@ -147,7 +161,7 @@ void MSG_task_set_copy_callback(void (*callback) (msg_task_t task, msg_process_t msg_process_t MSG_task_get_sender(msg_task_t task) { xbt_assert(task, "Invalid parameters"); - return ((simdata_task_t) task->simdata)->sender; + return (static_cast (task->simdata)->sender); } /** \ingroup m_task_management @@ -158,7 +172,7 @@ msg_process_t MSG_task_get_sender(msg_task_t task) msg_host_t MSG_task_get_source(msg_task_t task) { xbt_assert(task, "Invalid parameters"); - return ((simdata_task_t) task->simdata)->source; + return (static_cast (task->simdata)->source); } /** \ingroup m_task_management @@ -196,7 +210,7 @@ void MSG_task_set_name(msg_task_t task, const char *name) */ msg_error_t MSG_task_destroy(msg_task_t task) { - xbt_assert((task != NULL), "Invalid parameter"); + xbt_assert((task != nullptr), "Invalid parameter"); if (task->simdata->isused) { /* the task is being sent or executed: cancel it first */ @@ -206,16 +220,8 @@ msg_error_t MSG_task_destroy(msg_task_t task) xbt_free(task->name); - if (task->simdata->compute) - task->simdata->compute->unref(); - - /* parallel tasks only */ - xbt_free(task->simdata->host_list); - - xbt_dict_free(&task->simdata->affinity_mask_db); - /* free main structures */ - xbt_free(task->simdata); + delete task->simdata; xbt_free(task); return MSG_OK; @@ -227,7 +233,7 @@ msg_error_t MSG_task_destroy(msg_task_t task) */ msg_error_t MSG_task_cancel(msg_task_t task) { - xbt_assert((task != NULL), "Cannot cancel a NULL task"); + xbt_assert((task != nullptr), "Cannot cancel a nullptr task"); if (task->simdata->compute) { simcall_execution_cancel(task->simdata->compute); @@ -235,9 +241,7 @@ msg_error_t MSG_task_cancel(msg_task_t task) else if (task->simdata->comm) { simdata_task_t simdata = task->simdata; simcall_comm_cancel(simdata->comm); - if (msg_global->debug_multiple_use && simdata->isused!=0) - xbt_ex_free(*(xbt_ex_t*)simdata->isused); - simdata->isused = 0; + simdata->setNotUsed(); } return MSG_OK; } @@ -294,7 +298,7 @@ double MSG_task_get_remaining_communication(msg_task_t task) */ double MSG_task_get_bytes_amount(msg_task_t task) { - xbt_assert((task != NULL) && (task->simdata != NULL), "Invalid parameter"); + xbt_assert((task != nullptr) && (task->simdata != nullptr), "Invalid parameter"); return task->simdata->bytes_amount; } @@ -304,7 +308,7 @@ double MSG_task_get_bytes_amount(msg_task_t task) */ void MSG_task_set_priority(msg_task_t task, double priority) { - xbt_assert((task != NULL) && (task->simdata != NULL), "Invalid parameter"); + xbt_assert((task != nullptr) && (task->simdata != nullptr), "Invalid parameter"); task->simdata->priority = 1 / priority; if (task->simdata->compute) simcall_execution_set_priority(task->simdata->compute, @@ -322,7 +326,7 @@ void MSG_task_set_bound(msg_task_t task, double bound) xbt_assert(task, "Invalid parameter"); xbt_assert(task->simdata, "Invalid parameter"); - if (bound == 0) + if (bound < 1e-12) /* close enough to 0 without any floating precision surprise */ XBT_INFO("bound == 0 means no capping (i.e., unlimited)."); task->simdata->bound = bound; @@ -372,10 +376,10 @@ void MSG_task_set_affinity(msg_task_t task, msg_host_t host, unsigned long mask) /* 0 means clear */ /* We need remove_ext() not throwing exception. */ void *ret = xbt_dict_get_or_null_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(msg_host_t)); - if (ret != NULL) + if (ret != nullptr) xbt_dict_remove_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(host)); } else - xbt_dict_set_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(host), (void *)(uintptr_t) mask, NULL); + xbt_dict_set_ext(task->simdata->affinity_mask_db, (char *) host, sizeof(host), (void *)(uintptr_t) mask, nullptr); /* We set affinity data of this task. If the task is being executed, we actually change the affinity setting of the * task. Otherwise, this change will be applied when the task is executed. */ @@ -386,24 +390,19 @@ void MSG_task_set_affinity(msg_task_t task, msg_host_t host, unsigned long mask) return; } - { - simgrid::simix::Exec *compute = task->simdata->compute; - msg_host_t host_now = compute->host; // simix_private.h is necessary - if (host_now != host) { - /* task is not yet executed on this host */ - XBT_INFO("set affinity(0x%04lx@%s) for %s (not active now)", mask, MSG_host_get_name(host), - MSG_task_get_name(task)); - return; - } - - /* task is being executed on this host. so change the affinity now */ - { - /* check it works. remove me if it works. */ - xbt_assert((unsigned long)(uintptr_t) xbt_dict_get_or_null_ext(task->simdata->affinity_mask_db, - (char *) host, sizeof(msg_host_t)) == mask); - } - - XBT_INFO("set affinity(0x%04lx@%s) for %s", mask, MSG_host_get_name(host), MSG_task_get_name(task)); - simcall_execution_set_affinity(task->simdata->compute, host, mask); + simgrid::kernel::activity::Exec *compute = task->simdata->compute; + msg_host_t host_now = compute->host; // simix_private.h is necessary + if (host_now != host) { + /* task is not yet executed on this host */ + XBT_INFO("set affinity(0x%04lx@%s) for %s (not active now)", mask, MSG_host_get_name(host), + MSG_task_get_name(task)); + return; } + + /* task is being executed on this host. so change the affinity now */ + /* check it works. remove me if it works. */ + xbt_assert(static_cast((uintptr_t) xbt_dict_get_or_null_ext(task->simdata->affinity_mask_db, + (char*)(host), sizeof(msg_host_t))) == mask); + XBT_INFO("set affinity(0x%04lx@%s) for %s", mask, MSG_host_get_name(host), MSG_task_get_name(task)); + simcall_execution_set_affinity(task->simdata->compute, host, mask); }