* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simdag_private.hpp"
+#include "simgrid/s4u/Comm.hpp"
+#include "simgrid/s4u/Exec.hpp"
#include "simgrid/simdag.h"
#include "xbt/file.hpp"
#include "xbt/log.h"
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()) {
- input->mark();
- // Inputs are communication, hence they can have only one predecessor
- SD_task_t input_pred = *(input->get_predecessors().begin());
- if (children_are_marked(input_pred))
- next.push_back(input_pred);
+ for (auto const& input : t->get_predecessors()) {
+ if (input->get_kind() == SD_TASK_COMM_E2E || input->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK) {
+ input->mark();
+ // Inputs are communication, hence they can have only one predecessor
+ 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);
}
//test if the current iteration is done
for (auto const& t : current) {
t->mark();
- for (SD_task_t const& output : t->get_outputs()) {
- output->mark();
- // outputs are communication, hence they can have only one successor
- SD_task_t output_succ = *(output->get_successors().begin());
- if (parents_are_marked(output_succ))
- next.push_back(output_succ);
+ for (auto const& output : t->get_successors()) {
+ if (output->get_kind() == SD_TASK_COMM_E2E || output->get_kind() == SD_TASK_COMM_PAR_MXN_1D_BLOCK) {
+ output->mark();
+ // outputs are communication, hence they can have only one successor
+ SD_task_t output_succ = output->get_successors().front();
+ if (parents_are_marked(output_succ))
+ next.push_back(output_succ);
+ }
}
for (SD_task_t const& succ : t->get_successors()) {
if (parents_are_marked(succ))
return all_marked;
}
+bool check_for_cycle(const std::vector<simgrid::s4u::ActivityPtr>& dag)
+{
+ std::vector<simgrid::s4u::ActivityPtr> current;
+
+ for (const auto& a : dag)
+ if (dynamic_cast<simgrid::s4u::Exec*>(a.get()) != nullptr && a->is_waited_by() == 0)
+ current.push_back(a);
+
+ while (not current.empty()) {
+ std::vector<simgrid::s4u::ActivityPtr> next;
+ for (auto const& a : current) {
+ a->mark();
+ for (auto const& pred : a->get_dependencies()) {
+ if (dynamic_cast<simgrid::s4u::Comm*>(pred.get()) != nullptr) {
+ pred->mark();
+ // Comms have only one predecessor
+ auto pred_pred = *(pred->get_dependencies().begin());
+ if (std::none_of(pred_pred->get_successors().begin(), pred_pred->get_successors().end(),
+ [](const simgrid::s4u::ActivityPtr& a) { return not a->is_marked(); }))
+ next.push_back(pred_pred);
+ } else {
+ if (std::none_of(pred->get_successors().begin(), pred->get_successors().end(),
+ [](const simgrid::s4u::ActivityPtr& a) { return not a->is_marked(); }))
+ next.push_back(pred);
+ }
+ }
+ }
+ current.clear();
+ current = next;
+ }
+
+ return not std::any_of(dag.begin(), dag.end(), [](const simgrid::s4u::ActivityPtr& a) { return not a->is_marked(); });
+}
+
static YY_BUFFER_STATE input_buffer;
static xbt_dynar_t result;
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) +