X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b7333fdbe0f12c6c61ec63e09babcd480647e009..5d4ddd2bba5d37272aefa3108883a526b645be78:/src/simdag/sd_daxloader.cpp diff --git a/src/simdag/sd_daxloader.cpp b/src/simdag/sd_daxloader.cpp index 2cbfc81c4a..543cb63ce3 100644 --- a/src/simdag/sd_daxloader.cpp +++ b/src/simdag/sd_daxloader.cpp @@ -4,12 +4,12 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "src/simdag/simdag_private.h" #include "simgrid/simdag.h" #include "xbt/misc.h" #include "xbt/log.h" #include "xbt/str.h" #include "xbt/file.h" /* xbt_basename() */ +#include "simdag_private.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_daxparse, sd, "Parsing DAX files"); @@ -56,109 +56,83 @@ static bool parents_are_marked(SD_task_t task){ } bool acyclic_graph_detail(xbt_dynar_t dag){ - unsigned int count, count_current=0; + unsigned int count; bool all_marked = true; SD_task_t task = nullptr; - xbt_dynar_t next = nullptr, current = xbt_dynar_new(sizeof(SD_task_t),nullptr); - + std::vector current; xbt_dynar_foreach(dag,count,task){ - if(task->kind == SD_TASK_COMM_E2E) - continue; - task->marked = 0; - if(task->successors->empty() && task->outputs->empty()) - xbt_dynar_push(current, &task); + if(task->kind != SD_TASK_COMM_E2E){ + task->marked = 0; + if(task->successors->empty() && task->outputs->empty()) + current.push_back(task); + } } - //test if something has to be done for the next iteration - while(!xbt_dynar_is_empty(current)){ - next = xbt_dynar_new(sizeof(SD_task_t),nullptr); - //test if the current iteration is done - xbt_dynar_foreach(current,count_current,task){ - if (task == nullptr) - continue; - //push task in next - task->marked = 1; - for (SD_task_t it : *task->inputs){ - it->marked = 1; + while(!current.empty()){ + std::vector next; + for (auto t: current){ + //Mark task + t->marked = 1; + for (SD_task_t input : *t->inputs){ + input->marked=1; // Inputs are communication, hence they can have only one predecessor - SD_task_t input_pred = *(it->predecessors->begin()); + SD_task_t input_pred = *(input->predecessors->begin()); if (children_are_marked(input_pred)) - xbt_dynar_push(next, &input_pred); + next.push_back(input_pred); } - for (SD_task_t it : *task->predecessors) { - if (children_are_marked(it)) - xbt_dynar_push(next, &it); + for (SD_task_t pred : *t->predecessors) { + if (children_are_marked(pred)) + next.push_back(pred); } } - xbt_dynar_free(¤t); + current.clear(); current = next; - next = nullptr; } - xbt_dynar_free(¤t); + all_marked = true; + //test if all tasks are marked xbt_dynar_foreach(dag,count,task){ - if(task->kind == SD_TASK_COMM_E2E) - continue; - //test if all tasks are marked - if(task->marked == 0){ + if(task->kind != SD_TASK_COMM_E2E && task->marked == 0){ XBT_WARN("the task %s is not marked",task->name); all_marked = false; break; } } + if(!all_marked){ XBT_VERB("there is at least one cycle in your task graph"); - - current = xbt_dynar_new(sizeof(SD_task_t),nullptr); - xbt_dynar_foreach(dag,count,task){ - if(task->kind == SD_TASK_COMM_E2E) - continue; - if(task->predecessors->empty() && task->inputs->empty()){ - xbt_dynar_push(current, &task); - } - } - xbt_dynar_foreach(dag,count,task){ - if(task->kind == SD_TASK_COMM_E2E) - continue; - if(task->predecessors->empty() && task->inputs->empty()){ - task->marked = 1; - xbt_dynar_push(current, &task); + if(task->kind != SD_TASK_COMM_E2E && task->predecessors->empty() && task->inputs->empty()){ + task->marked = 1; + current.push_back(task); } } //test if something has to be done for the next iteration - while(!xbt_dynar_is_empty(current)){ - next = xbt_dynar_new(sizeof(SD_task_t),nullptr); + while(!current.empty()){ + std::vector next; //test if the current iteration is done - xbt_dynar_foreach(current,count_current,task){ - if (task == nullptr) - continue; - //push task in next - task->marked = 1; - for (SD_task_t it : *task->outputs) { - it->marked = 1; + for (auto t: current){ + t->marked = 1; + for (SD_task_t output : *t->outputs) { + output->marked = 1; // outputs are communication, hence they can have only one successor - SD_task_t output_succ = *(it->successors->begin()); + SD_task_t output_succ = *(output->successors->begin()); if (parents_are_marked(output_succ)) - xbt_dynar_push(next, &output_succ); + next.push_back(output_succ); } - for (SD_task_t it : *task->predecessors) { - if (parents_are_marked(it)) - xbt_dynar_push(next, &it); + for (SD_task_t succ : *t->successors) { + if (parents_are_marked(succ)) + next.push_back(succ); } - xbt_dynar_free(¤t); + current.clear(); current = next; - next = nullptr; } - xbt_dynar_free(¤t); - all_marked = true; - xbt_dynar_foreach(dag,count,task){ - if(task->kind == SD_TASK_COMM_E2E) - continue; - //test if all tasks are marked - if(task->marked == 0){ - XBT_WARN("the task %s is in a cycle",task->name); - all_marked = false; - } + } + + all_marked = true; + xbt_dynar_foreach(dag,count,task){ + if(task->kind != SD_TASK_COMM_E2E && task->marked == 0){ + XBT_WARN("the task %s is in a cycle",task->name); + all_marked = false; } } } @@ -263,12 +237,14 @@ xbt_dynar_t SD_daxload(const char *filename) /* 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->inputs->empty()) - SD_task_dependency_add(nullptr, nullptr, root_task, file); - if ((file != end_task) && file->outputs->empty()) - SD_task_dependency_add(nullptr, nullptr, file, end_task); + if ((file != root_task) && (file != end_task)) { + if (file->inputs->empty()) + SD_task_dependency_add(nullptr, nullptr, root_task, file); + if (file->outputs->empty()) + SD_task_dependency_add(nullptr, nullptr, file, end_task); + } } else { - THROW_IMPOSSIBLE; + THROW_IMPOSSIBLE; } } @@ -305,7 +281,7 @@ void STag_dax__job() xbt_dynar_push(result, ¤t_job); } -void STag_dax__uses(void) +void STag_dax__uses() { double size = xbt_str_parse_double(A_dax__uses_size, "Parse error: %s is not a double"); int is_input = (A_dax__uses_link == A_dax__uses_link_input);