-/* Copyright (c) 2006-2016. The SimGrid Team.
+/* Copyright (c) 2006-2017. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "simdag_private.hpp"
#include "src/surf/HostImpl.hpp"
#include "src/surf/surf_interface.hpp"
+#include <algorithm>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_task, sd, "Logging specific to SimDag (task)");
task->successors = new std::set<SD_task_t>();
task->data = data;
- task->name = std::string(name);
+ task->name = xbt_strdup(name);
task->amount = amount;
task->allocation = new std::vector<sg_host_t>();
task->rate = -1;
/** @brief create a complex data redistribution task that can then be auto-scheduled
*
- * Auto-scheduling mean that the task can be used with SD_task_schedulev().
+ * Auto-scheduling mean that the task can be used with SD_task_schedulev().
* This allows to specify the task costs at creation, and decouple them from the scheduling process where you just
* specify which resource should communicate.
*
XBT_DEBUG("Destroying task %s...", SD_task_get_name(task));
/* First Remove all dependencies associated with the task. */
- while (!task->predecessors->empty())
+ while (not task->predecessors->empty())
SD_task_dependency_remove(*(task->predecessors->begin()), task);
- while (!task->inputs->empty())
+ while (not task->inputs->empty())
SD_task_dependency_remove(*(task->inputs->begin()), task);
- while (!task->successors->empty())
+ while (not task->successors->empty())
SD_task_dependency_remove(task, *(task->successors->begin()));
- while (!task->outputs->empty())
- SD_task_dependency_remove(task, *(task->outputs->begin()));
+ while (not task->outputs->empty())
+ SD_task_dependency_remove(task, *(task->outputs->begin()));
if (task->state == SD_SCHEDULED || task->state == SD_RUNNABLE)
__SD_task_destroy_scheduling_data(task);
+ xbt_free(task->name);
+
if (task->surf_action != nullptr)
task->surf_action->unref();
void SD_task_set_state(SD_task_t task, e_SD_task_state_t new_state)
{
std::set<SD_task_t>::iterator idx;
- XBT_DEBUG("Set state of '%s' to %d", task->name.c_str(), new_state);
+ XBT_DEBUG("Set state of '%s' to %d", task->name, new_state);
if ((new_state == SD_NOT_SCHEDULED || new_state == SD_SCHEDULABLE) && task->state == SD_FAILED){
sd_global->completed_tasks->erase(task);
sd_global->initial_tasks->insert(task);
task->start_time = task->surf_action->getStartTime();
if (new_state == SD_DONE){
task->finish_time = task->surf_action->getFinishTime();
-#if HAVE_JEDULE
+#if SIMGRID_HAVE_JEDULE
jedule_log_sd_event(task);
#endif
} else
task->state = new_state;
if (task->watch_points & new_state) {
- XBT_VERB("Watch point reached with task '%s'!", task->name.c_str());
+ XBT_VERB("Watch point reached with task '%s'!", task->name);
sd_global->watch_point_reached = true;
SD_task_unwatch(task, new_state); /* remove the watch point */
}
*/
const char *SD_task_get_name(SD_task_t task)
{
- return task->name.c_str();
+ return task->name;
}
/** @brief Allows to change the name of a task */
void SD_task_set_name(SD_task_t task, const char *name)
{
- task->name = std::string(name);
+ xbt_free(task->name);
+ task->name = xbt_strdup(name);
}
/** @brief Returns the dynar of the parents of a task
{
xbt_dynar_t parents = xbt_dynar_new(sizeof(SD_task_t), nullptr);
- for (auto it : *task->predecessors)
+ for (auto const& it : *task->predecessors)
xbt_dynar_push(parents, &it);
- for (auto it : *task->inputs)
+ for (auto const& it : *task->inputs)
xbt_dynar_push(parents, &it);
return parents;
{
xbt_dynar_t children = xbt_dynar_new(sizeof(SD_task_t), nullptr);
- for (auto it : *task->successors)
+ for (auto const& it : *task->successors)
xbt_dynar_push(children, &it);
- for (auto it : *task->outputs)
+ for (auto const& it : *task->outputs)
xbt_dynar_push(children, &it);
return children;
*/
sg_host_t *SD_task_get_workstation_list(SD_task_t task)
{
- return &(*(task->allocation))[0];
+ return task->allocation->data();
}
/**
XBT_INFO(" - Dependencies to satisfy: %zu", task->inputs->size()+ task->predecessors->size());
if ((task->inputs->size()+ task->predecessors->size()) > 0) {
XBT_INFO(" - pre-dependencies:");
- for (auto it : *task->predecessors)
- XBT_INFO(" %s", it->name.c_str());
+ for (auto const& it : *task->predecessors)
+ XBT_INFO(" %s", it->name);
- for (auto it: *task->inputs)
- XBT_INFO(" %s", it->name.c_str());
+ for (auto const& it : *task->inputs)
+ XBT_INFO(" %s", it->name);
}
if ((task->outputs->size() + task->successors->size()) > 0) {
XBT_INFO(" - post-dependencies:");
- for (auto it : *task->successors)
- XBT_INFO(" %s", it->name.c_str());
- for (auto it : *task->outputs)
- XBT_INFO(" %s", it->name.c_str());
+ for (auto const& it : *task->successors)
+ XBT_INFO(" %s", it->name);
+ for (auto const& it : *task->outputs)
+ XBT_INFO(" %s", it->name);
}
}
void SD_task_dotty(SD_task_t task, void *out)
{
FILE *fout = static_cast<FILE*>(out);
- fprintf(fout, " T%p [label=\"%.20s\"", task, task->name.c_str());
+ fprintf(fout, " T%p [label=\"%.20s\"", task, task->name);
switch (task->kind) {
case SD_TASK_COMM_E2E:
case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
xbt_die("Unknown task type!");
}
fprintf(fout, "];\n");
- for (auto it : *task->predecessors)
+ for (auto const& it : *task->predecessors)
fprintf(fout, " T%p -> T%p;\n", it, task);
- for (auto it : *task->inputs)
+ for (auto const& it : *task->inputs)
fprintf(fout, " T%p -> T%p;\n", it, task);
}
if (src->state == SD_DONE || src->state == SD_FAILED)
THROWF(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNABLE, or SD_RUNNING",
- src->name.c_str());
+ src->name);
if (dst->state == SD_DONE || dst->state == SD_FAILED || dst->state == SD_RUNNING)
THROWF(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, or SD_RUNNABLE",
- dst->name.c_str());
+ dst->name);
if (dst->inputs->find(src) != dst->inputs->end() || src->outputs->find(dst) != src->outputs->end() ||
src->successors->find(dst) != src->successors->end() || dst->predecessors->find(src) != dst->predecessors->end())
- THROWF(arg_error, 0, "A dependency already exists between task '%s' and task '%s'", src->name.c_str(), dst->name.c_str());
+ THROWF(arg_error, 0, "A dependency already exists between task '%s' and task '%s'", src->name, dst->name);
- XBT_DEBUG("SD_task_dependency_add: src = %s, dst = %s", src->name.c_str(), dst->name.c_str());
+ XBT_DEBUG("SD_task_dependency_add: src = %s, dst = %s", src->name, dst->name);
if (src->kind == SD_TASK_COMM_E2E || src->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
if (dst->kind == SD_TASK_COMP_SEQ || dst->kind == SD_TASK_COMP_PAR_AMDAHL)
/* if the task was runnable, the task goes back to SD_SCHEDULED because of the new dependency*/
if (dst->state == SD_RUNNABLE) {
- XBT_DEBUG("SD_task_dependency_add: %s was runnable and becomes scheduled!", dst->name.c_str());
+ XBT_DEBUG("SD_task_dependency_add: %s was runnable and becomes scheduled!", dst->name);
SD_task_set_state(dst, SD_SCHEDULED);
}
}
if (src->successors->find(dst) == src->successors->end() && src->outputs->find(dst) == src->outputs->end())
THROWF(arg_error, 0, "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'",
- src->name.c_str(), dst->name.c_str(), dst->name.c_str(), src->name.c_str());
+ src->name, dst->name, dst->name, src->name);
if (src->kind == SD_TASK_COMM_E2E || src->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){
if (dst->kind == SD_TASK_COMP_SEQ || dst->kind == SD_TASK_COMP_PAR_AMDAHL)
for (int i = 0; i < host_count; i++) {
double time = 0.0;
if (flops_amount != nullptr)
- time = flops_amount[i] / host_list[i]->speed();
+ time = flops_amount[i] / host_list[i]->getSpeed();
if (bytes_amount != nullptr)
for (int j = 0; j < host_count; j++)
if (bytes_amount[i * host_count + j] != 0)
- time += (SD_route_get_latency(host_list[i], host_list[j]) +
- bytes_amount[i * host_count + j] / SD_route_get_bandwidth(host_list[i], host_list[j]));
+ time += (sg_host_route_latency(host_list[i], host_list[j]) +
+ bytes_amount[i * host_count + j] / sg_host_route_bandwidth(host_list[i], host_list[j]));
if (time > max_time)
max_time = time;
*
* \param task the task you want to schedule
* \param host_count number of hosts on which the task will be executed
- * \param workstation_list the hosts on which the task will be executed
+ * \param host_list the hosts on which the task will be executed
* \param flops_amount computation amount for each hosts (i.e., an array of host_count doubles)
* \param bytes_amount communication amount between each pair of hosts (i.e., a matrix of host_count*host_count doubles)
* \param rate task execution speed rate
void SD_task_unschedule(SD_task_t task)
{
if (task->state == SD_NOT_SCHEDULED || task->state == SD_SCHEDULABLE)
- THROWF(arg_error, 0, "Task %s: the state must be SD_SCHEDULED, SD_RUNNABLE, SD_RUNNING or SD_FAILED", task->name.c_str());
+ THROWF(arg_error, 0, "Task %s: the state must be SD_SCHEDULED, SD_RUNNABLE, SD_RUNNING or SD_FAILED", task->name);
if ((task->state == SD_SCHEDULED || task->state == SD_RUNNABLE) /* if the task is scheduled or runnable */
&& ((task->kind == SD_TASK_COMP_PAR_AMDAHL) || (task->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK))) {
/* Runs a task. */
void SD_task_run(SD_task_t task)
{
- xbt_assert(task->state == SD_RUNNABLE, "Task '%s' is not runnable! Task state: %d", task->name.c_str(), (int) task->state);
- xbt_assert(task->allocation != nullptr, "Task '%s': host_list is nullptr!", task->name.c_str());
+ xbt_assert(task->state == SD_RUNNABLE, "Task '%s' is not runnable! Task state: %d", task->name, (int) task->state);
+ xbt_assert(task->allocation != nullptr, "Task '%s': host_list is nullptr!", task->name);
- XBT_VERB("Executing task '%s'", task->name.c_str());
+ XBT_VERB("Executing task '%s'", task->name);
/* Copy the elements of the task into the action */
int host_nb = task->allocation->size();
- sg_host_t *hosts = xbt_new(sg_host_t, host_nb);
- int i =0;
- for (auto host: *task->allocation){
- hosts[i] = host;
- i++;
- }
+ sg_host_t* hosts = new sg_host_t[host_nb];
+ std::copy_n(task->allocation->begin(), host_nb, hosts);
- double *flops_amount = xbt_new0(double, host_nb);
- double *bytes_amount = xbt_new0(double, host_nb * host_nb);
+ double* flops_amount = new double[host_nb]();
+ double* bytes_amount = new double[host_nb * host_nb]();
if(task->flops_amount)
- memcpy(flops_amount, task->flops_amount, sizeof(double) * host_nb);
+ std::copy_n(task->flops_amount, host_nb, flops_amount);
if(task->bytes_amount)
- memcpy(bytes_amount, task->bytes_amount, sizeof(double) * host_nb * host_nb);
+ std::copy_n(task->bytes_amount, host_nb * host_nb, bytes_amount);
task->surf_action = surf_host_model->executeParallelTask(host_nb, hosts, flops_amount, bytes_amount, task->rate);
void SD_task_distribute_comp_amdahl(SD_task_t task, int count)
{
xbt_assert(task->kind == SD_TASK_COMP_PAR_AMDAHL, "Task %s is not a SD_TASK_COMP_PAR_AMDAHL typed task."
- "Cannot use this function.", task->name.c_str());
+ "Cannot use this function.", task->name);
task->flops_amount = xbt_new0(double, count);
task->bytes_amount = xbt_new0(double, count * count);
void SD_task_build_MxN_1D_block_matrix(SD_task_t task, int src_nb, int dst_nb){
xbt_assert(task->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK, "Task %s is not a SD_TASK_COMM_PAR_MXN_1D_BLOCK typed task."
- "Cannot use this function.", task->name.c_str());
+ "Cannot use this function.", task->name);
xbt_free(task->bytes_amount);
task->bytes_amount = xbt_new0(double,task->allocation->size() * task->allocation->size());
for(int i =0; i<count; i++)
task->allocation->push_back(list[i]);
- XBT_VERB("Schedule computation task %s on %zu host(s)", task->name.c_str(), task->allocation->size());
+ XBT_VERB("Schedule computation task %s on %zu host(s)", task->name, task->allocation->size());
if (task->kind == SD_TASK_COMP_SEQ) {
- if (!task->flops_amount){ /*This task has failed and is rescheduled. Reset the flops_amount*/
+ if (not task->flops_amount) { /*This task has failed and is rescheduled. Reset the flops_amount*/
task->flops_amount = xbt_new0(double, 1);
task->flops_amount[0] = task->amount;
}
SD_task_do_schedule(task);
/* Iterate over all inputs and outputs to say where I am located (and start them if runnable) */
- for (auto input : *task->inputs){
+ for (auto const& input : *task->inputs) {
int src_nb = input->allocation->size();
int dst_nb = count;
if (input->allocation->empty())
- XBT_VERB("Sender side of '%s' not scheduled. Set receiver side to '%s''s allocation", input->name.c_str(), task->name.c_str());
+ XBT_VERB("Sender side of '%s' not scheduled. Set receiver side to '%s''s allocation", input->name, task->name);
for (int i=0; i<count;i++)
input->allocation->push_back(task->allocation->at(i));
SD_task_do_schedule(input);
XBT_VERB ("Auto-Schedule Communication task '%s'. Send %.f bytes from %d hosts to %d hosts.",
- input->name.c_str(),input->amount, src_nb, dst_nb);
+ input->name,input->amount, src_nb, dst_nb);
}
}
- for (auto output : *task->outputs){
+ for (auto const& output : *task->outputs) {
int src_nb = count;
int dst_nb = output->allocation->size();
if (output->allocation->empty())
- XBT_VERB("Receiver side of '%s' not scheduled. Set sender side to '%s''s allocation", output->name.c_str(), task->name.c_str());
+ XBT_VERB("Receiver side of '%s' not scheduled. Set sender side to '%s''s allocation", output->name, task->name);
for (int i=0; i<count;i++)
output->allocation->insert(output->allocation->begin()+i, task->allocation->at(i));
SD_task_do_schedule(output);
XBT_VERB ("Auto-Schedule Communication task %s. Send %.f bytes from %d hosts to %d hosts.",
- output->name.c_str(), output->amount, src_nb, dst_nb);
+ output->name, output->amount, src_nb, dst_nb);
}
}
}
void SD_task_schedulel(SD_task_t task, int count, ...)
{
va_list ap;
- sg_host_t *list = xbt_new(sg_host_t, count);
+ sg_host_t* list = new sg_host_t[count];
va_start(ap, count);
for (int i=0; i<count; i++)
list[i] = va_arg(ap, sg_host_t);
va_end(ap);
SD_task_schedulev(task, count, list);
- xbt_free(list);
+ delete[] list;
}