void uniq_transfer_task_name(SD_task_t task)
{
const_SD_task_t child = *(task->get_successors().begin());
- const_SD_task_t parent = *(task->get_predecessors().begin());
+ const_SD_task_t parent = *(task->get_dependencies().begin());
- std::string new_name =
- std::string(SD_task_get_name(parent)) + "_" + SD_task_get_name(task) + "_" + SD_task_get_name(child);
+ std::string new_name = parent->get_name() + "_" + task->get_name() + "_" + child->get_name();
- SD_task_set_name(task, new_name.c_str());
+ task->set_name(new_name);
}
static bool children_are_marked(const_SD_task_t task)
{
return std::none_of(task->get_successors().begin(), task->get_successors().end(),
- [](const SD_task_t& elm) { return not elm->is_marked(); }) &&
- std::none_of(task->get_outputs().begin(), task->get_outputs().end(),
[](const SD_task_t& elm) { return not elm->is_marked(); });
}
static bool parents_are_marked(const_SD_task_t task)
{
- return std::none_of(task->get_predecessors().begin(), task->get_predecessors().end(),
- [](const SD_task_t& elm) { return not elm->is_marked(); }) &&
- std::none_of(task->get_inputs().begin(), task->get_inputs().end(),
+ return std::none_of(task->get_dependencies().begin(), task->get_dependencies().end(),
[](const SD_task_t& elm) { return not elm->is_marked(); });
}
SD_task_t task = nullptr;
std::vector<SD_task_t> current;
xbt_dynar_foreach (dag, count, task)
- if (task->get_kind() != SD_TASK_COMM_E2E && task->get_successors().empty() && task->get_outputs().empty())
+ if (task->get_kind() != SD_TASK_COMM_E2E && task->is_waited_by() == 0)
current.push_back(task);
while (not current.empty()) {
for (auto const& t : current) {
//Mark task
t->mark();
- for (SD_task_t const& input : t->get_inputs()) {
+ for (auto const& input : t->get_inputs()) {
input->mark();
// Inputs are communication, hence they can have only one predecessor
- SD_task_t input_pred = *(input->get_predecessors().begin());
+ auto input_pred = *(input->get_dependencies().begin());
if (children_are_marked(input_pred))
next.push_back(input_pred);
}
- for (SD_task_t const& pred : t->get_predecessors()) {
+ for (auto const& pred : t->get_dependencies()) {
if (children_are_marked(pred))
next.push_back(pred);
}
if (not all_marked) {
XBT_VERB("there is at least one cycle in your task graph");
xbt_dynar_foreach(dag,count,task){
- if (task->get_kind() != SD_TASK_COMM_E2E && task->get_predecessors().empty() && task->get_inputs().empty()) {
+ if (task->get_kind() != SD_TASK_COMM_E2E && task->has_unsolved_dependencies() == 0) {
task->mark();
current.push_back(task);
}
for (auto const& elm : files) {
file = elm.second;
SD_task_t newfile;
- if (file->get_predecessors().empty()) {
+ if (file->has_unsolved_dependencies() == 0) {
for (SD_task_t const& it : file->get_successors()) {
newfile = SD_task_create_comm_e2e(file->get_cname(), nullptr, file->get_amount());
- SD_task_dependency_add(root_task, newfile);
- SD_task_dependency_add(newfile, it);
+ root_task->dependency_add(newfile);
+ newfile->dependency_add(it);
xbt_dynar_push(result, &newfile);
}
}
- if (file->get_successors().empty()) {
- for (SD_task_t const& it : file->get_predecessors()) {
+ if (file->is_waited_by() == 0) {
+ for (SD_task_t const& it : file->get_dependencies()) {
newfile = SD_task_create_comm_e2e(file->get_cname(), nullptr, file->get_amount());
- SD_task_dependency_add(it, newfile);
- SD_task_dependency_add(newfile, end_task);
+ it->dependency_add(newfile);
+ newfile->dependency_add(end_task);
xbt_dynar_push(result, &newfile);
}
}
- for (SD_task_t const& it : file->get_predecessors()) {
+ for (SD_task_t const& it : file->get_dependencies()) {
for (SD_task_t const& it2 : file->get_successors()) {
if (it == it2) {
XBT_WARN("File %s is produced and consumed by task %s."
file->get_cname(), it->get_cname());
}
newfile = SD_task_create_comm_e2e(file->get_cname(), nullptr, file->get_amount());
- SD_task_dependency_add(it, newfile);
- SD_task_dependency_add(newfile, it2);
+ it->dependency_add(newfile);
+ newfile->dependency_add(it2);
xbt_dynar_push(result, &newfile);
}
}
/* Free previous copy of the files */
- SD_task_destroy(file);
+ file->destroy();
}
/* Push end task last */
unsigned int cpt;
xbt_dynar_foreach(result, cpt, file) {
- if (SD_task_get_kind(file) == SD_TASK_COMM_E2E) {
+ if (file->get_kind() == SD_TASK_COMM_E2E) {
uniq_transfer_task_name(file);
} else {
/* If some tasks do not take files as input, connect them to the root
* if they don't produce files, connect them to the end node.
*/
if ((file != root_task) && (file != end_task)) {
- if (file->get_inputs().empty())
- SD_task_dependency_add(root_task, file);
- if (file->get_outputs().empty())
- SD_task_dependency_add(file, end_task);
+ if (file->has_unsolved_dependencies() == 0)
+ root_task->dependency_add(file);
+ if (file->is_waited_by() == 0)
+ file->dependency_add(end_task);
}
}
}
XBT_ERROR("The DAX described in %s is not a DAG. It contains a cycle.",
simgrid::xbt::Path(filename).get_base_name().c_str());
xbt_dynar_foreach(result, cpt, file)
- SD_task_destroy(file);
+ file->destroy();
xbt_dynar_free_container(&result);
result = nullptr;
}
}
}
if (is_input) {
- SD_task_dependency_add(file, current_job);
+ file->dependency_add(current_job);
} else {
- SD_task_dependency_add(current_job, file);
+ current_job->dependency_add(file);
if (file->has_unsolved_dependencies() > 1) {
XBT_WARN("File %s created at more than one location...", file->get_cname());
}
{
auto job = jobs.find(A_dax__parent_ref);
if (job != jobs.end()) {
- SD_task_t parent = job->second;
- SD_task_dependency_add(parent, current_child);
+ auto parent = job->second;
+ parent->dependency_add(current_child);
XBT_DEBUG("Control-flow dependency from %s to %s", current_child->get_cname(), parent->get_cname());
} else {
throw std::out_of_range(std::string("Parse error on line ") + std::to_string(dax_lineno) +
return task;
}
-void Task::distribute_comp_amdahl(int count)
+void Task::distribute_comp_amdahl(unsigned long count)
{
xbt_assert(kind_ == SD_TASK_COMP_PAR_AMDAHL,
"Task %s is not a SD_TASK_COMP_PAR_AMDAHL typed task."
"Cannot use this function.",
get_cname());
flops_amount_ = xbt_new0(double, count);
- for (int i = 0; i < count; i++)
+ for (unsigned long i = 0; i < count; i++)
flops_amount_[i] = (alpha_ + (1 - alpha_) / count) * amount_;
}
-void Task::build_MxN_1D_block_matrix(int src_nb, int dst_nb)
+void Task::build_MxN_1D_block_matrix(unsigned long src_nb, unsigned long dst_nb)
{
xbt_assert(kind_ == SD_TASK_COMM_PAR_MXN_1D_BLOCK,
"Task %s is not a SD_TASK_COMM_PAR_MXN_1D_BLOCK typed task."
xbt_free(bytes_amount_);
bytes_amount_ = xbt_new0(double, allocation_->size() * allocation_->size());
- for (int i = 0; i < src_nb; i++) {
+ for (unsigned long i = 0; i < src_nb; i++) {
double src_start = i * amount_ / src_nb;
double src_end = src_start + amount_ / src_nb;
- for (int j = 0; j < dst_nb; j++) {
+ for (unsigned long j = 0; j < dst_nb; j++) {
double dst_start = j * amount_ / dst_nb;
double dst_end = dst_start + amount_ / dst_nb;
- XBT_VERB("(%d->%d): (%.2f, %.2f)-> (%.2f, %.2f)", i, j, src_start, src_end, dst_start, dst_end);
+ XBT_VERB("(%lu->%lu): (%.2f, %.2f)-> (%.2f, %.2f)", i, j, src_start, src_end, dst_start, dst_end);
bytes_amount_[i * (src_nb + dst_nb) + src_nb + j] = 0.0;
if ((src_end > dst_start) && (dst_end > src_start)) { /* There is something to send */
bytes_amount_[i * (src_nb + dst_nb) + src_nb + j] = std::min(src_end, dst_end) - std::max(src_start, dst_start);
}
}
-bool Task::is_parent_of(Task* task) const
+void Task::dependency_add(Task* task)
+{
+ if (this == task)
+ throw std::invalid_argument(
+ simgrid::xbt::string_printf("Cannot add a dependency between task '%s' and itself", get_cname()));
+
+ if (state_ == SD_DONE || state_ == SD_FAILED)
+ throw std::invalid_argument(simgrid::xbt::string_printf(
+ "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNABLE, or SD_RUNNING", get_cname()));
+
+ if (task->get_state() == SD_DONE || task->get_state() == SD_FAILED || task->get_state() == SD_RUNNING)
+ throw std::invalid_argument(simgrid::xbt::string_printf(
+ "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, or SD_RUNNABLE", task->get_cname()));
+
+ if (dependency_exist(task))
+ throw std::invalid_argument(simgrid::xbt::string_printf(
+ "A dependency already exists between task '%s' and task '%s'", get_cname(), task->get_cname()));
+
+ successors_.push_back(task);
+ task->dependencies_.insert({this});
+
+ /* if 'task' was runnable, it goes back to the SD_SCHEDULED state because of the new dependency*/
+ if (task->get_state() == SD_RUNNABLE) {
+ XBT_DEBUG("SD_task_dependency_add: %s was runnable and becomes scheduled!", task->get_cname());
+ task->set_state(SD_SCHEDULED);
+ }
+}
+
+bool Task::dependency_exist(Task* task) const
+{
+ return (std::find(successors_.begin(), successors_.end(), task) != successors_.end() ||
+ dependencies_.find(task) != dependencies_.end());
+}
+
+void Task::dependency_remove(Task* task)
+{
+ if (this == task)
+ throw std::invalid_argument("Cannot ask to remove itself from successors");
+
+ auto p = std::find(successors_.begin(), successors_.end(), task);
+ if (p != successors_.end()) {
+ successors_.erase(p);
+ task->dependencies_.erase({this});
+ } else
+ throw std::invalid_argument(simgrid::xbt::string_printf(
+ "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'", get_cname(),
+ task->get_cname(), task->get_cname(), get_cname()));
+
+ /* if 'task' was scheduled and dependencies are satisfied, we can make it runnable */
+ if (task->has_unsolved_dependencies() == 0 && task->get_state() == SD_SCHEDULED)
+ task->set_state(SD_RUNNABLE);
+}
+
+std::set<Task*> Task::get_predecessors() const
{
- return (successors_.find(task) != successors_.end() || outputs_.find(task) != outputs_.end());
+ std::set<Task*> res;
+ for (const auto& d : dependencies_)
+ if (d->get_kind() == SD_TASK_COMP_SEQ || d->get_kind() == SD_TASK_COMP_PAR_AMDAHL)
+ res.insert(d);
+ return res;
}
-bool Task::is_child_of(Task* task) const
+std::set<Task*> Task::get_inputs() const
{
- return (inputs_.find(task) != inputs_.end() || predecessors_.find(task) != predecessors_.end());
+ std::set<Task*> res;
+ for (const auto& d : dependencies_)
+ if (d->get_kind() == SD_TASK_COMM_E2E || d->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
+ res.insert(d);
+ return res;
+}
+
+std::vector<Task*> Task::get_outputs() const
+{
+ std::vector<Task*> res;
+ for (const auto& d : successors_)
+ if (d->get_kind() == SD_TASK_COMM_E2E || d->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
+ res.push_back(d);
+ return res;
}
void Task::set_amount(double amount)
XBT_WARN("Task %p has started. Changing rate is ineffective.", this);
}
}
+
void Task::set_state(e_SD_task_state_t new_state)
{
std::set<Task*>::iterator idx;
}
}
-double Task::get_alpha() const
-{
- xbt_assert(kind_ == SD_TASK_COMP_PAR_AMDAHL, "Alpha parameter is not defined for this kind of task");
- return alpha_;
-}
-
double Task::get_remaining_amount() const
{
if (surf_action_)
double Task::get_start_time() const
{
- if (surf_action_)
- return surf_action_->get_start_time();
- else
- return start_time_;
+ return surf_action_ ? surf_action_->get_start_time() : start_time_;
}
double Task::get_finish_time() const
XBT_INFO(" - Dependencies to satisfy: %lu", has_unsolved_dependencies());
if (has_unsolved_dependencies() > 0) {
XBT_INFO(" - pre-dependencies:");
- for (auto const& it : predecessors_)
- XBT_INFO(" %s", it->get_cname());
-
- for (auto const& it : inputs_)
+ for (auto const& it : dependencies_)
XBT_INFO(" %s", it->get_cname());
}
if (is_waited_by() > 0) {
for (auto const& it : successors_)
XBT_INFO(" %s", it->get_cname());
- for (auto const& it : outputs_)
- XBT_INFO(" %s", it->get_cname());
}
}
void Task::released_by(Task* pred)
{
- predecessors_.erase(pred);
- inputs_.erase(pred);
+ dependencies_.erase(pred);
XBT_DEBUG("Release dependency on %s: %lu remain(s). Becomes schedulable if %zu=0", get_cname(),
- has_unsolved_dependencies(), predecessors_.size());
+ has_unsolved_dependencies(), get_predecessors().size());
- if (state_ == SD_NOT_SCHEDULED && predecessors_.empty())
+ if (state_ == SD_NOT_SCHEDULED && get_predecessors().empty())
set_state(SD_SCHEDULABLE);
if (state_ == SD_SCHEDULED && has_unsolved_dependencies() == 0)
void Task::produced_by(Task* pred)
{
+ if (state_ == SD_RUNNABLE)
+ return;
+
start_time_ = pred->get_finish_time();
- predecessors_.erase(pred);
+ dependencies_.erase(pred);
if (state_ == SD_SCHEDULED)
set_state(SD_RUNNABLE);
else
bytes_amount_ = nullptr;
}
- for (unsigned long i = 0; i < host_count; i++)
- allocation_->push_back(hosts[i]);
+ for (const auto& h : hosts)
+ allocation_->push_back(h);
do_schedule();
}
do_schedule();
/* Iterate over all inputs and outputs to say where I am located (and start them if runnable) */
- for (auto const& input : inputs_) {
+ for (auto const& input : get_inputs()) {
unsigned long src_nb = input->get_allocation_size();
unsigned long dst_nb = hosts.size();
if (src_nb == 0)
}
}
- for (auto const& output : outputs_) {
+ for (auto const& output : get_outputs()) {
unsigned long src_nb = hosts.size();
unsigned long dst_nb = output->get_allocation_size();
if (dst_nb == 0)
XBT_DEBUG("Destroying task %s...", get_cname());
/* First Remove all dependencies associated with the task. */
- while (not predecessors_.empty())
- SD_task_dependency_remove(*(predecessors_.begin()), this);
- while (not inputs_.empty())
- SD_task_dependency_remove(*(inputs_.begin()), this);
+ while (not dependencies_.empty())
+ (*(dependencies_.begin()))->dependency_remove(this);
while (not successors_.empty())
- SD_task_dependency_remove(this, *(successors_.begin()));
- while (not outputs_.empty())
- SD_task_dependency_remove(this, *(outputs_.begin()));
+ this->dependency_remove(successors_.front());
if (state_ == SD_SCHEDULED || state_ == SD_RUNNABLE) {
xbt_free(flops_amount_);
task->destroy();
}
-/**
- * @brief Returns the user data of a task
- *
- * @param task a task
- * @return the user data associated with this task (can be @c nullptr)
- * @see SD_task_set_data()
- */
+/** @brief Returns the user data of a task */
void* SD_task_get_data(const_SD_task_t task)
{
return task->get_data();
}
-/**
- * @brief Sets the user data of a task
- *
+/** @brief Sets the user data of a task
* The new data can be @c nullptr. The old data should have been freed first, if it was not @c nullptr.
- *
- * @param task a task
- * @param data the new data you want to associate with this task
- * @see SD_task_get_data()
*/
void SD_task_set_data(SD_task_t task, void* data)
{
task->set_data(data);
}
-/**
- * @brief Sets the rate of a task
- *
- * This will change the network bandwidth a task can use. This rate cannot be dynamically changed. Once the task has
- * started, this call is ineffective. This rate depends on both the nominal bandwidth on the route onto which the task
- * is scheduled (@see SD_task_get_current_bandwidth) and the amount of data to transfer.
- *
- * To divide the nominal bandwidth by 2, the rate then has to be :
- * rate = bandwidth/(2*amount)
- *
- * @param task a @see SD_TASK_COMM_E2E task (end-to-end communication)
- * @param rate the new rate you want to associate with this task.
- */
void SD_task_set_rate(SD_task_t task, double rate)
{
task->set_rate(rate);
{
return task->get_state();
}
-/**
- * @brief Returns the name of a task
- *
- * @param task a task
- * @return the name of this task (can be @c nullptr)
- */
+
const char* SD_task_get_name(const_SD_task_t task)
{
return task->get_cname();
}
-/** @brief Allows to change the name of a task */
void SD_task_set_name(SD_task_t task, const char* name)
{
task->set_name(name);
}
-/** @brief Returns the dynar of the parents of a task
- *
- * @param task a task
- * @return a newly allocated dynar comprising the parents of this task
- */
-
+/** @brief Returns the parents of a task ina dynar */
xbt_dynar_t SD_task_get_parents(const_SD_task_t task)
{
xbt_dynar_t parents = xbt_dynar_new(sizeof(SD_task_t), nullptr);
- for (auto const& it : task->get_predecessors())
- xbt_dynar_push(parents, &it);
- for (auto const& it : task->get_inputs())
+ for (auto const& it : task->get_dependencies())
xbt_dynar_push(parents, &it);
return parents;
}
-/** @brief Returns the dynar of the parents of a task
- *
- * @param task a task
- * @return a newly allocated dynar comprising the parents of this task
- */
+/** @brief Returns the children of a task in a dynar */
xbt_dynar_t SD_task_get_children(const_SD_task_t task)
{
xbt_dynar_t children = xbt_dynar_new(sizeof(SD_task_t), nullptr);
for (auto const& it : task->get_successors())
xbt_dynar_push(children, &it);
- for (auto const& it : task->get_outputs())
- xbt_dynar_push(children, &it);
return children;
}
+double SD_task_get_start_time(const_SD_task_t task)
+{
+ return task->get_start_time();
+}
+
+double SD_task_get_finish_time(const_SD_task_t task)
+{
+ return task->get_finish_time();
+}
+
+void SD_task_distribute_comp_amdahl(SD_task_t task, int count)
+{
+ task->distribute_comp_amdahl(count);
+}
+
+void SD_task_build_MxN_1D_block_matrix(SD_task_t task, int src_nb, int dst_nb)
+{
+ task->build_MxN_1D_block_matrix(src_nb, dst_nb);
+}
+
/**
* @brief Returns the number of workstations involved in a task
*
return task->get_amount();
}
-/** @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 flops_amount and
- * bytes_amount arrays respectively. Nothing more than modifying task->amount is done for parallel 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->set_amount(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
- */
-double SD_task_get_alpha(const_SD_task_t task)
-{
- return task->get_alpha();
-}
-
-/**
- * @brief Returns the remaining amount work to do till the completion of a task
- *
- * @param task a task
- * @return the remaining amount of work (computation or data transfer) of this task
- * @see SD_task_get_amount()
- */
double SD_task_get_remaining_amount(const_SD_task_t task)
{
return task->get_remaining_amount();
return task->get_kind();
}
-/** @brief Displays debugging information about a task */
void SD_task_dump(const_SD_task_t task)
{
task->dump();
}
-/** @brief Dumps the task in dotty formalism into the FILE* passed as second argument */
-void SD_task_dotty(const_SD_task_t task, void* out)
-{
- auto* fout = static_cast<FILE*>(out);
- fprintf(fout, " T%p [label=\"%.20s\"", task, task->get_cname());
- switch (task->get_kind()) {
- case SD_TASK_COMM_E2E:
- case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
- fprintf(fout, ", shape=box");
- break;
- case SD_TASK_COMP_SEQ:
- case SD_TASK_COMP_PAR_AMDAHL:
- fprintf(fout, ", shape=circle");
- break;
- default:
- xbt_die("Unknown task type!");
- }
- fprintf(fout, "];\n");
- for (auto const& it : task->get_predecessors())
- fprintf(fout, " T%p -> T%p;\n", it, task);
- for (auto const& it : task->get_inputs())
- fprintf(fout, " T%p -> T%p;\n", it, task);
-}
-
-/**
- * @brief Adds a dependency between two tasks
- *
- * @a dst will depend on @a src, ie @a dst will not start before @a src is finished.
- * Their @ref e_SD_task_state_t "state" must be #SD_NOT_SCHEDULED, #SD_SCHEDULED or #SD_RUNNABLE.
- *
- * @param src the task which must be executed first
- * @param dst the task you want to make depend on @a src
- * @see SD_task_dependency_remove()
- */
void SD_task_dependency_add(SD_task_t src, SD_task_t dst)
{
- if (src == dst)
- throw std::invalid_argument(
- simgrid::xbt::string_printf("Cannot add a dependency between task '%s' and itself", SD_task_get_name(src)));
-
- if (src->get_state() == SD_DONE || src->get_state() == SD_FAILED)
- throw std::invalid_argument(simgrid::xbt::string_printf(
- "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNABLE, or SD_RUNNING",
- src->get_cname()));
-
- if (dst->get_state() == SD_DONE || dst->get_state() == SD_FAILED || dst->get_state() == SD_RUNNING)
- throw std::invalid_argument(simgrid::xbt::string_printf(
- "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, or SD_RUNNABLE", dst->get_cname()));
-
- if (dst->is_child_of(src) || src->is_parent_of(dst))
- throw std::invalid_argument(simgrid::xbt::string_printf(
- "A dependency already exists between task '%s' and task '%s'", src->get_cname(), dst->get_cname()));
-
XBT_DEBUG("SD_task_dependency_add: src = %s, dst = %s", src->get_cname(), dst->get_cname());
-
- if (src->get_kind() == SD_TASK_COMM_E2E || src->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK) {
- if (dst->get_kind() == SD_TASK_COMP_SEQ || dst->get_kind() == SD_TASK_COMP_PAR_AMDAHL)
- dst->add_input(src);
- else
- dst->add_predecessor(src);
- src->add_successor(dst);
- } else {
- if (dst->get_kind() == SD_TASK_COMM_E2E || dst->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
- src->add_output(dst);
- else
- src->add_successor(dst);
- dst->add_predecessor(src);
- }
-
- /* if the task was runnable, the task goes back to SD_SCHEDULED because of the new dependency*/
- if (dst->get_state() == SD_RUNNABLE) {
- XBT_DEBUG("SD_task_dependency_add: %s was runnable and becomes scheduled!", dst->get_cname());
- dst->set_state(SD_SCHEDULED);
- }
+ src->dependency_add(dst);
+}
+void SD_task_dependency_remove(SD_task_t src, SD_task_t dst)
+{
+ XBT_DEBUG("SD_task_dependency_remove: src = %s, dst = %s", src->get_cname(), dst->get_cname());
+ src->dependency_remove(dst);
}
/**
* @brief Indicates whether there is a dependency between two tasks.
- *
- * @param src a task
- * @param dst a task depending on @a src
- *
* If src is nullptr, checks whether dst has any pre-dependency.
* If dst is nullptr, checks whether src has any post-dependency.
*/
if (src)
if (dst)
- return src->is_parent_of(dst);
+ return src->dependency_exist(dst);
else
return static_cast<int>(src->is_waited_by());
else
return static_cast<int>(dst->has_unsolved_dependencies());
}
-/**
- * @brief Remove a dependency between two tasks
- *
- * @param src a task
- * @param dst a task depending on @a src
- * @see SD_task_dependency_add()
- */
-void SD_task_dependency_remove(SD_task_t src, SD_task_t dst)
-{
- XBT_DEBUG("SD_task_dependency_remove: src = %s, dst = %s", src->get_cname(), dst->get_cname());
-
- if (not src->is_parent_of(dst))
- throw std::invalid_argument(simgrid::xbt::string_printf(
- "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'", src->get_cname(),
- dst->get_cname(), dst->get_cname(), src->get_cname()));
-
- if (src->get_kind() == SD_TASK_COMM_E2E || src->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK) {
- if (dst->get_kind() == SD_TASK_COMP_SEQ || dst->get_kind() == SD_TASK_COMP_PAR_AMDAHL)
- dst->rm_input(src);
- else
- dst->rm_predecessor(src);
- src->rm_successor(dst);
- } else {
- if (dst->get_kind() == SD_TASK_COMM_E2E || dst->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK)
- src->rm_output(dst);
- else
- src->rm_successor(dst);
- dst->rm_predecessor(src);
- }
-
- /* if the task was scheduled and dependencies are satisfied, we can make it runnable */
- if (dst->has_unsolved_dependencies() == 0 && dst->get_state() == SD_SCHEDULED)
- dst->set_state(SD_RUNNABLE);
-}
-
-/**
- * @brief Adds a watch point to a task
- *
- * SD_simulate() will stop as soon as the @ref e_SD_task_state_t "state" of this task becomes the one given in argument.
- * The watch point is then automatically removed.
- *
- * @param task a task
- * @param state the @ref e_SD_task_state_t "state" you want to watch (cannot be #SD_NOT_SCHEDULED)
- * @see SD_task_unwatch()
- */
void SD_task_watch(SD_task_t task, e_SD_task_state_t state)
{
task->watch(state);
}
-/**
- * @brief Removes a watch point from a task
- *
- * @param task a task
- * @param state the @ref e_SD_task_state_t "state" you no longer want to watch
- * @see SD_task_watch()
- */
void SD_task_unwatch(SD_task_t task, e_SD_task_state_t state)
{
task->unwatch(state);
}
+/** @brief Dumps the task in dotty formalism into the FILE* passed as second argument */
+void SD_task_dotty(const_SD_task_t task, void* out)
+{
+ auto* fout = static_cast<FILE*>(out);
+ fprintf(fout, " T%p [label=\"%.20s\"", task, task->get_cname());
+ switch (task->get_kind()) {
+ case SD_TASK_COMM_E2E:
+ case SD_TASK_COMM_PAR_MXN_1D_BLOCK:
+ fprintf(fout, ", shape=box");
+ break;
+ case SD_TASK_COMP_SEQ:
+ case SD_TASK_COMP_PAR_AMDAHL:
+ fprintf(fout, ", shape=circle");
+ break;
+ default:
+ xbt_die("Unknown task type!");
+ }
+ fprintf(fout, "];\n");
+ for (auto const& it : task->get_dependencies())
+ fprintf(fout, " T%p -> T%p;\n", it, task);
+}
+
/**
* @brief Returns an approximative estimation of the execution time of a task.
*
task->schedule(hosts, flops_amount, bytes_amount, rate);
}
-/**
- * @brief Unschedules a task
- *
- * The task state must be #SD_SCHEDULED, #SD_RUNNABLE, #SD_RUNNING or #SD_FAILED.
- * If you call this function, the task state becomes #SD_NOT_SCHEDULED.
- * Call SD_task_schedule() to schedule it again.
- *
- * @param task the task you want to unschedule
- * @see SD_task_schedule()
- */
void SD_task_unschedule(SD_task_t task)
{
task->unschedule();
}
-/**
- * @brief Returns the start time of a task
- *
- * The task state must be SD_RUNNING, SD_DONE or SD_FAILED.
- *
- * @param task: a task
- * @return the start time of this task
- */
-double SD_task_get_start_time(const_SD_task_t task)
-{
- return task->get_start_time();
-}
-
-/**
- * @brief Returns the finish time of a task
- *
- * The task state must be SD_RUNNING, SD_DONE or SD_FAILED.
- * If the state is not completed yet, the returned value is an estimation of the task finish time. This value can
- * vary until the task is completed.
- *
- * @param task: a task
- * @return the start time of this task
- */
-double SD_task_get_finish_time(const_SD_task_t task)
-{
- return task->get_finish_time();
-}
-
-void SD_task_distribute_comp_amdahl(SD_task_t task, int count)
-{
- task->distribute_comp_amdahl(count);
-}
-
-void SD_task_build_MxN_1D_block_matrix(SD_task_t task, int src_nb, int dst_nb)
-{
- task->build_MxN_1D_block_matrix(src_nb, dst_nb);
-}
-
/** @brief Auto-schedules a task.
*
* Auto-scheduling mean that the task can be used with SD_task_schedulev(). This allows one to specify the task costs at
double alpha_ = 0; /* used by typed parallel tasks */
/* dependencies */
- std::set<Task*> inputs_;
- std::set<Task*> outputs_;
- std::set<Task*> predecessors_;
- std::set<Task*> successors_;
+ std::set<Task*> dependencies_;
+ std::vector<Task*> successors_;
/* scheduling parameters (only exist in state SD_SCHEDULED) */
std::vector<s4u::Host*>* allocation_;
static Task* create_comp_par_amdahl(const std::string& name, double amount, void* userdata, double alpha);
static Task* create_comm_par_mxn_1d_block(const std::string& name, double amount, void* userdata);
- void distribute_comp_amdahl(int count);
- void build_MxN_1D_block_matrix(int src_nb, int dst_nb);
+ void distribute_comp_amdahl(unsigned long count);
+ void build_MxN_1D_block_matrix(unsigned long src_nb, unsigned long dst_nb);
- void add_input(Task* task) { inputs_.insert(task); }
- void rm_input(Task* task) { inputs_.erase(task); }
- void add_predecessor(Task* task) { predecessors_.insert(task); }
- void rm_predecessor(Task* task) { predecessors_.erase(task); }
- void add_successor(Task* task) { successors_.insert(task); }
- void rm_successor(Task* task) { successors_.erase(task); }
+ /** @brief Adds a dependency between with 'task'
+ * @a task will depend on this Task, i.e., it cannot start before this task is finished.
+ */
+ void dependency_add(Task* task);
+ bool dependency_exist(Task* task) const;
+ /** @brief Remove a dependency with 'task' */
+ void dependency_remove(Task* task);
void clear_successors() { successors_.clear(); }
- void add_output(Task* task) { outputs_.insert(task); }
- void rm_output(Task* task) { outputs_.erase(task); }
- void clear_outputs() { outputs_.clear(); }
void set_name(const std::string& name) { name_ = name; }
const std::string& get_name() const { return name_; }
const char* get_cname() const { return name_.c_str(); }
+ /** @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 flops_amount and
+ * bytes_amount arrays respectively. Nothing more than modifying task->amount is done for parallel typed tasks
+ * (COMP_PAR_AMDAHL and COMM_PAR_MXN_1D_BLOCK) as the distribution of the amount of work is done at scheduling time.
+ */
void set_amount(double amount);
double get_amount() const { return amount_; }
+ /** @brief Returns the remaining amount of work (computation or data transfer) to do before completion */
double get_remaining_amount() const;
-
+ /** @brief Returns the start time of a task */
double get_start_time() const;
+ /** @brief Returns the finish time of a task
+ * If the state is not completed yet, the returned value is an estimation of the task finish time. This value can
+ * vary until the task is completed.
+ */
double get_finish_time() const;
void set_state(e_SD_task_state_t new_state);
void unmark() { marked_ = false; }
bool is_marked() const { return marked_; }
- const std::set<Task*>& get_inputs() const { return inputs_; }
- const std::set<Task*>& get_predecessors() const { return predecessors_; }
- const std::set<Task*>& get_successors() const { return successors_; }
- const std::set<Task*>& get_outputs() const { return outputs_; }
-
- bool is_parent_of(Task* task) const;
- bool is_child_of(Task* task) const;
+ const std::set<Task*>& get_dependencies() const { return dependencies_; }
+ std::set<Task*> get_predecessors() const;
+ std::set<Task*> get_inputs() const;
+ const std::vector<Task*>& get_successors() const { return successors_; }
+ std::vector<Task*> get_outputs() const;
- unsigned long has_unsolved_dependencies() const { return (predecessors_.size() + inputs_.size()); }
- unsigned long is_waited_by() const { return (successors_.size() + outputs_.size()); }
+ unsigned long has_unsolved_dependencies() const { return dependencies_.size(); }
+ unsigned long is_waited_by() const { return successors_.size(); }
void released_by(Task* pred);
void produced_by(Task* pred);
e_SD_task_kind_t get_kind() const { return kind_; }
void set_alpha(double alpha) { alpha_ = alpha; }
- double get_alpha() const;
+ /** @brief Sets the rate of a task
+ *
+ * This will change the network bandwidth a task can use. This rate cannot be dynamically changed. Once the task has
+ * started, this call is ineffective. This rate depends on both the nominal bandwidth on the route onto which the task
+ * is scheduled (@see SD_task_get_current_bandwidth) and the amount of data to transfer.
+ *
+ * To divide the nominal bandwidth by 2, the rate then has to be :
+ * rate = bandwidth/(2*amount)
+ */
void set_rate(double rate);
- unsigned int get_allocation_size() const { return allocation_->size(); }
+ unsigned long get_allocation_size() const { return allocation_->size(); }
std::vector<s4u::Host*>* get_allocation() const { return allocation_; }
+ /** @brief Adds a watch point to a task
+ * sd::simulate() stops as soon as the @ref e_SD_task_state_t "state" of this task becomes the one given as argument.
+ * The watched state cannot be #SD_NOT_SCHEDULED
+ */
void watch(e_SD_task_state_t state);
+ /** @brief Removes a watch point on 'state' from a task */
void unwatch(e_SD_task_state_t state);
+ /** @brief Displays debugging information about a task */
void dump() const;
void do_schedule();
void schedule(const std::vector<s4u::Host*>& hosts, const double* flops_amount, const double* bytes_amount,
double rate);
void schedulev(const std::vector<s4u::Host*>& hosts);
+ /**
+ * @brief Unschedules a task. Its state becomes #SD_NOT_SCHEDULED. You can schedule it again afterwards */
void unschedule();
void run();