Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright notices
[simgrid.git] / src / simdag / sd_dotloader.c
index f62679a..fc32b26 100644 (file)
@@ -1,14 +1,16 @@
-/* Copyright (c) 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2009-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* 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 "private.h"
-#include "simdag/simdag.h"
+#include "simgrid/simdag.h"
 #include "xbt/misc.h"
 #include "xbt/log.h"
 #include <stdbool.h>
+#include <string.h>
+#include <libgen.h>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_dotparse, sd, "Parsing DOT files");
 
@@ -18,157 +20,40 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_dotparse, sd, "Parsing DOT files");
 #include <graphviz/cgraph.h>
 #elif HAVE_AGRAPH_H
 #include <graphviz/agraph.h>
+#define agnxtnode(dot, node)    agnxtnode(node)
+#define agfstin(dot, node)      agfstin(node)
+#define agnxtin(dot, edge)      agnxtin(edge)
+#define agfstout(dot, node)     agfstout(node)
+#define agnxtout(dot, edge)     agnxtout(edge)
 #endif
 
-void dot_add_task(Agnode_t * dag_node);
-void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge);
-void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge);
-bool child_are_marked(SD_task_t task);
-xbt_dynar_t SD_dotload_FILE(FILE * in_file);
+typedef enum {
+  sequential =0,
+  parallel
+} seq_par_t;
 
-static double dot_parse_double(const char *string)
-{
-  if (string == NULL)
-    return -1;
-  int ret = 0;
-  double value = -1;
-
-  ret = sscanf(string, "%lg", &value);
-  if (ret != 1)
-    WARN1("%s is not a double", string);
-  return value;
-}
-
-static int dot_parse_int(const char *string)
-{
-  if (string == NULL)
-    return -10;
-  int ret = 0;
-  int value = -1;
-
-  ret = sscanf(string, "%d", &value);
-  if (ret != 1)
-    WARN1("%s is not an integer", string);
-  return value;
-}
+xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par);
 
 static xbt_dynar_t result;
 static xbt_dict_t jobs;
-static xbt_dict_t files;
 static xbt_dict_t computers;
-static SD_task_t root_task, end_task;
 static Agraph_t *dag_dot;
 static bool schedule = true;
 
-static void dump_res()
-{
-  unsigned int cursor;
-  SD_task_t task;
-  xbt_dynar_foreach(result, cursor, task) {
-    INFO1("Task %d", cursor);
-    SD_task_dump(task);
-  }
-}
-
-bool child_are_marked(SD_task_t task){
-  SD_task_t child_task = NULL;
-  bool all_marked = true;
-  SD_dependency_t depafter = NULL;
-  unsigned int count;
-  xbt_dynar_foreach(task->tasks_after,count,depafter){
-    child_task = depafter->dst;
-    //test marked
-    if(child_task->marked == 0) {
-      all_marked = false;
-      break;
-    }
-    child_task = NULL;
-  }
-  return all_marked;
-}
-
-bool acyclic_graph_detection(xbt_dynar_t dag){
-  unsigned int count=0, count_current=0;
-  bool all_marked = true;
-  SD_task_t task = NULL, parent_task = NULL;
-  SD_dependency_t depbefore = NULL;
-  xbt_dynar_t next = NULL, current = xbt_dynar_new(sizeof(SD_task_t),NULL);
-
-  xbt_dynar_foreach(dag,count,task){
-    if(task->kind == SD_TASK_COMM_E2E) continue;
-    task->marked = 0;
-    if(xbt_dynar_length(task->tasks_after) == 0){
-      xbt_dynar_push(current, &task);
-    }
-  }
-  task = NULL;
-  count = 0;
-  //test if something has to be done for the next iteration
-  while(xbt_dynar_length(current) != 0){
-    next = xbt_dynar_new(sizeof(SD_task_t),NULL);
-    //test if the current iteration is done
-    count_current=0;
-    xbt_dynar_foreach(current,count_current,task){
-      if (task == NULL) continue;
-      count = 0;
-      //push task in next
-      task->marked = 1;
-      count = 0;
-      xbt_dynar_foreach(task->tasks_before,count,depbefore){
-        parent_task = depbefore->src;
-        if(parent_task->kind == SD_TASK_COMM_E2E){
-          unsigned int j=0;
-          parent_task->marked = 1;
-          xbt_dynar_foreach(parent_task->tasks_before,j,depbefore){
-            parent_task = depbefore->src;
-            if(child_are_marked(parent_task))
-              xbt_dynar_push(next, &parent_task);
-          }
-        } else{
-          if(child_are_marked(parent_task))
-            xbt_dynar_push(next, &parent_task);
-        }
-        parent_task = NULL;
-      }
-      task = NULL;
-      count = 0;
-    }
-    xbt_dynar_free(&current);
-    current = next;
-    next = NULL;
-  }
-  xbt_dynar_free(&current);
-  current = NULL;
-  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){
-      WARN1("test %s",task->name);
-      all_marked = false;
-      break;
-    }
-  }
-  task = NULL;
-  if(!all_marked){
-    DEBUG0("there are a cycle in your DAG");
-  }
-  return all_marked;
-}
-
-static void dot_task_free(void *task)
-{
-  SD_task_t t = task;
-  SD_task_destroy(t);
+static void dot_task_p_free(void *task) {
+  SD_task_t *t = task;
+  SD_task_destroy(*t);
 }
 
-static void TRACE_sd_dotloader (SD_task_t task, const char *category)
-{
-  if (category){
-    if (strlen (category) != 0){
-      TRACE_category (category);
-      TRACE_sd_set_task_category (task, category);
-    }
+static void TRACE_sd_dotloader (SD_task_t task, const char *category) {
+  if (category && strlen (category)){
+    if (task->category)
+      XBT_DEBUG("Change the category of %s from %s to %s",
+          task->name, task->category, category);
+    else
+      XBT_DEBUG("Set the category of %s to %s",task->name, category);
+    TRACE_category (category);
+    TRACE_sd_set_task_category(task, category);
   }
 }
 
@@ -181,12 +66,10 @@ static void TRACE_sd_dotloader (SD_task_t task, const char *category)
  * (the amount of data transfer in bit).
  * if they aren't here, there choose to be equal to zero.
  */
-xbt_dynar_t SD_dotload(const char *filename)
-{
-  FILE *in_file = fopen(filename, "r");
-  xbt_assert1(in_file, "Unable to open \"%s\"\n", filename);
-  SD_dotload_FILE(in_file);
-  fclose(in_file);
+xbt_dynar_t SD_dotload(const char *filename) {
+  computers = xbt_dict_new_homogeneous(NULL);
+  schedule = false;
+  SD_dotload_generic(filename, sequential);
   xbt_dynar_t computer = NULL;
   xbt_dict_cursor_t dict_cursor;
   char *computer_name;
@@ -197,25 +80,23 @@ xbt_dynar_t SD_dotload(const char *filename)
   return result;
 }
 
-xbt_dynar_t SD_dotload_with_sched(const char *filename){
-  FILE *in_file = fopen(filename, "r");
-  xbt_assert1(in_file, "Unable to open \"%s\"\n", filename);
-  SD_dotload_FILE(in_file);
-  fclose(in_file);
+xbt_dynar_t SD_dotload_with_sched(const char *filename) {
+  computers = xbt_dict_new_homogeneous(NULL);
+  SD_dotload_generic(filename, sequential);
 
-  if(schedule == true){
+  if(schedule){
     xbt_dynar_t computer = NULL;
     xbt_dict_cursor_t dict_cursor;
     char *computer_name;
     const SD_workstation_t *workstations = SD_workstation_get_list ();
     xbt_dict_foreach(computers,dict_cursor,computer_name,computer){
-      int count_computer = dot_parse_int(computer_name);
+      int count_computer = atoi(computer_name);
       unsigned int count=0;
       SD_task_t task;
       SD_task_t task_previous = NULL;
       xbt_dynar_foreach(computer,count,task){
-        // add dependency between the previous and the task to avoid
-        // parallel execution
+        /* add dependency between the previous and the task to avoid
+         * parallel execution */
         if(task != NULL ){
           if(task_previous != NULL &&
              !SD_task_dependency_exists(task_previous, task))
@@ -227,281 +108,276 @@ xbt_dynar_t SD_dotload_with_sched(const char *filename){
       xbt_dynar_free(&computer);
     }
     xbt_dict_free(&computers);
-    if(acyclic_graph_detection(result))
+    if(acyclic_graph_detail(result))
       return result;
     else
-      WARN0("There are a cycle in your task graph");
+      XBT_WARN("There is at least one cycle in the provided task graph");
   }else{
-    WARN0("No scheduling provided");
+    XBT_WARN("The scheduling is ignored");
   }
+  xbt_dynar_t computer = NULL;
+  xbt_dict_cursor_t dict_cursor;
+  char *computer_name;
+  xbt_dict_foreach(computers,dict_cursor,computer_name,computer){
+    xbt_dynar_free(&computer);
+  }
+  xbt_dict_free(&computers);
+  xbt_dynar_free(&result);
   return NULL;
 }
 
-xbt_dynar_t SD_dotload_FILE(FILE * in_file)
-{
-  xbt_assert0(in_file, "Unable to use a null file descriptor\n");
-  dag_dot = agread(in_file, NIL(Agdisc_t *));
+xbt_dynar_t SD_PTG_dotload(const char * filename) {
+  xbt_dynar_t result = SD_dotload_generic(filename, parallel);
+  if (!acyclic_graph_detail(result)) {
+    XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.",
+              basename((char*)filename));
+    xbt_dynar_free(&result);
+    /* (result == NULL) here */
+  }
+  return result;
+}
 
-  result = xbt_dynar_new(sizeof(SD_task_t), dot_task_free);
-  files = xbt_dict_new();
-  jobs = xbt_dict_new();
-  computers = xbt_dict_new();
-  root_task = SD_task_create_comp_seq("root", NULL, 0);
-  /* by design the root task is always SCHEDULABLE */
-  __SD_task_set_state(root_task, SD_SCHEDULABLE);
-
-  xbt_dict_set(jobs, "root", root_task, NULL);
-  xbt_dynar_push(result, &root_task);
-  end_task = SD_task_create_comp_seq("end", NULL, 0);
-  xbt_dict_set(jobs, "end", end_task, NULL);
-
-  Agnode_t *dag_node = NULL;
-  for (dag_node = agfstnode(dag_dot); dag_node;
 #ifdef HAVE_CGRAPH_H
-       dag_node = agnxtnode(dag_dot, dag_node)
-#elif HAVE_AGRAPH_H
-       dag_node = agnxtnode(dag_node)
+static int edge_compare(const void *a, const void *b)
+{
+  unsigned va = AGSEQ(*(Agedge_t **)a);
+  unsigned vb = AGSEQ(*(Agedge_t **)b);
+  return va == vb ? 0 : (va < vb ? -1 : 1);
+}
 #endif
-       ) {
-
-  dot_add_task(dag_node);
-  }
-  agclose(dag_dot);
-  xbt_dict_free(&jobs);
 
-  /* And now, post-process the files.
-   * We want a file task per pair of computation tasks exchanging the file. Duplicate on need
-   * Files not produced in the system are said to be produced by root task (top of DAG).
-   * Files not consumed in the system are said to be consumed by end task (bottom of DAG).
+xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par){
+  xbt_assert(filename, "Unable to use a null file descriptor\n");
+  unsigned int i;
+  result = xbt_dynar_new(sizeof(SD_task_t), dot_task_p_free);
+  jobs = xbt_dict_new_homogeneous(NULL);
+  FILE *in_file = fopen(filename, "r");
+  if (in_file == NULL)
+    xbt_die("Failed to open file: %s", filename);
+  dag_dot = agread(in_file, NIL(Agdisc_t *));
+  SD_task_t root, end, task;
+  /*
+   * Create all the nodes
    */
-  xbt_dict_cursor_t cursor;
-  SD_task_t file;
-  char *name;
-  xbt_dict_foreach(files, cursor, name, file) {
-    unsigned int cpt1, cpt2;
-    SD_task_t newfile = NULL;
-    SD_dependency_t depbefore, depafter;
-    if (xbt_dynar_length(file->tasks_before) == 0) {
-      xbt_dynar_foreach(file->tasks_after, cpt2, depafter) {
-        SD_task_t newfile =
-            SD_task_create_comm_e2e(file->name, NULL, file->amount);
-        SD_task_dependency_add(NULL, NULL, root_task, newfile);
-        SD_task_dependency_add(NULL, NULL, newfile, depafter->dst);
-        xbt_dynar_push(result, &newfile);
+  Agnode_t *node = NULL;
+  for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
+
+    char *name = agnameof(node);
+    double amount = atof(agget(node, (char *) "size"));
+    double alpha = 0.0;
+
+    if (seq_or_par == sequential){
+      XBT_DEBUG("See <job id=%s amount =%.0f>", name, amount);
+    } else {
+      if (!strcmp(agget(node, (char *) "alpha"), "")){
+        alpha = atof(agget(node, (char *) "alpha"));
+        if (alpha == -1.){
+          XBT_DEBUG("negative alpha value provided. Set to 0.");
+          alpha = 0.0 ;
+        }
+      } else {
+        XBT_DEBUG("no alpha value provided. Set to 0");
+        alpha = 0.0 ;
+      }
+
+      XBT_DEBUG("See <job id=%s amount =%.0f alpha = %.3f>",
+          name, amount, alpha);
+    }
+
+    if (!(task = xbt_dict_get_or_null(jobs, name))) {
+      if (seq_or_par == sequential){
+        task = SD_task_create_comp_seq(name, NULL , amount);
+      } else {
+        task = SD_task_create_comp_par_amdahl(name, NULL , amount, alpha);
       }
-    } else if (xbt_dynar_length(file->tasks_after) == 0) {
-      xbt_dynar_foreach(file->tasks_before, cpt2, depbefore) {
-        SD_task_t newfile =
-            SD_task_create_comm_e2e(file->name, NULL, file->amount);
-        SD_task_dependency_add(NULL, NULL, depbefore->src, newfile);
-        SD_task_dependency_add(NULL, NULL, newfile, end_task);
-        xbt_dynar_push(result, &newfile);
+      TRACE_sd_dotloader (task, agget (node, (char*)"category"));
+      xbt_dict_set(jobs, name, task, NULL);
+      if (!strcmp(name, "root")){
+      /* by design the root task is always SCHEDULABLE */
+      __SD_task_set_state(task, SD_SCHEDULABLE);
+      /* Put it at the beginning of the dynar */
+        xbt_dynar_insert_at(result, 0, &task);
+      } else {
+        if (!strcmp(name, "end")){
+          XBT_DEBUG("Declaration of the 'end' node, don't store it yet.");
+          end = task;
+          /* Should be inserted later in the dynar */
+        } else {
+          xbt_dynar_push(result, &task);
+        }
       }
-    } else {
-      xbt_dynar_foreach(file->tasks_before, cpt1, depbefore) {
-        xbt_dynar_foreach(file->tasks_after, cpt2, depafter) {
-          if (depbefore->src == depafter->dst) {
-            WARN2
-                ("File %s is produced and consumed by task %s. This loop dependency will prevent the execution of the task.",
-                 file->name, depbefore->src->name);
+
+      if((seq_or_par == sequential) &&
+          (schedule ||
+              XBT_LOG_ISENABLED(sd_dotparse, xbt_log_priority_verbose))){
+        /* try to take the information to schedule the task only if all is
+         * right*/
+        int performer, order;
+        char *char_performer = agget(node, (char *) "performer");
+        char *char_order = agget(node, (char *) "order");
+        /* performer is the computer which execute the task */
+        performer =
+            ((!char_performer || !strcmp(char_performer,"")) ? -1:atoi(char_performer));
+        /* order is giving the task order on one computer */
+        order = ((!char_order || !strcmp(char_order, ""))? -1:atoi(char_order));
+
+        XBT_DEBUG ("Task '%s' is scheduled on workstation '%d' in position '%d'",
+                    task->name, performer, order);
+        xbt_dynar_t computer = NULL;
+        if(performer != -1 && order != -1){
+          /* required parameters are given */
+          computer = xbt_dict_get_or_null(computers, char_performer);
+          if(computer == NULL){
+            computer = xbt_dynar_new(sizeof(SD_task_t), NULL);
+            xbt_dict_set(computers, char_performer, computer, NULL);
           }
-          newfile =
-              SD_task_create_comm_e2e(file->name, NULL, file->amount);
-          SD_task_dependency_add(NULL, NULL, depbefore->src, newfile);
-          SD_task_dependency_add(NULL, NULL, newfile, depafter->dst);
-          xbt_dynar_push(result, &newfile);
+          if(performer < xbt_lib_length(host_lib)){
+            /* the wanted computer is available */
+            SD_task_t *task_test = NULL;
+            if(order < computer->used)
+              task_test = xbt_dynar_get_ptr(computer,order);
+            if(task_test != NULL && *task_test != NULL && *task_test != task){
+              /* the user gives the same order to several tasks */
+              schedule = false;
+              XBT_VERB("The task %s starts on the computer %s at the position : %s like the task %s",
+                     (*task_test)->name, char_performer, char_order,
+                     task->name);
+            }else{
+              /* the parameter seems to be ok */
+              xbt_dynar_set_as(computer, order, SD_task_t, task);
+            }
+          }else{
+            /* the platform has not enough processors to schedule the DAG like
+             * the user wants*/
+            schedule = false;
+            XBT_VERB("The schedule is ignored, there are not enough computers");
+          }
+        }
+        else {
+          /* one of required parameters is not given */
+          schedule = false;
+          XBT_VERB("The schedule is ignored, the task %s is not correctly scheduled",
+              task->name);
         }
       }
+    } else {
+      XBT_WARN("Task '%s' is defined more than once", name);
     }
   }
 
-  /* Push end task last */
-  xbt_dynar_push(result, &end_task);
-
-  /* Free previous copy of the files */
-  xbt_dict_free(&files);
-  if(acyclic_graph_detection(result))
-    return result;
-  return NULL;
-}
-
-/* dot_add_task create a sd_task and all transfers required for this
- * task. The execution time of the task is given by the attribute size.
- * The unit of size is the Flop.*/
-void dot_add_task(Agnode_t * dag_node)
-{
-  char *name = agnameof(dag_node);
-  SD_task_t current_job;
-  double runtime = dot_parse_double(agget(dag_node, (char *) "size"));
-
-  DEBUG3("See <job id=%s runtime=%s %.0f>", name,
-        agget(dag_node, (char *) "size"), runtime);
-  current_job = xbt_dict_get_or_null(jobs, name);
-  if (current_job == NULL) {
-    current_job =
-        SD_task_create_comp_seq(name, NULL , runtime);
-#ifdef HAVE_TRACING
-   TRACE_sd_dotloader (current_job, agget (dag_node, (char*)"category"));
-#endif
-    xbt_dict_set(jobs, name, current_job, NULL);
-    xbt_dynar_push(result, &current_job);
+  /*
+   * Check if 'root' and 'end' nodes have been explicitly declared.
+   * If not, create them.
+   */
+  if (!(root = xbt_dict_get_or_null(jobs, "root"))){
+    if (seq_or_par == sequential)
+      root = SD_task_create_comp_seq("root", NULL, 0);
+    else
+      root = SD_task_create_comp_par_amdahl("root", NULL, 0, 0);
+    /* by design the root task is always SCHEDULABLE */
+    __SD_task_set_state(root, SD_SCHEDULABLE);
+    /* Put it at the beginning of the dynar */
+      xbt_dynar_insert_at(result, 0, &root);
   }
-  Agedge_t *e;
-  int count = 0;
 
-#ifdef HAVE_CGRAPH_H
-  for (e = agfstin(dag_dot, dag_node); e; e = agnxtin(dag_dot, e))
-#elif HAVE_AGRAPH_H
-  for (e = agfstin(dag_node); e; e = agnxtin(e))
-#endif
-  {
-  dot_add_input_dependencies(current_job, e);
-  count++;
-  }
-  if (count == 0 && current_job != root_task) {
-    SD_task_dependency_add(NULL, NULL, root_task, current_job);
+  if (!(end = xbt_dict_get_or_null(jobs, "end"))){
+    if (seq_or_par == sequential)
+      end = SD_task_create_comp_seq("end", NULL, 0);
+    else
+      end = SD_task_create_comp_par_amdahl("end", NULL, 0, 0);
+    /* Should be inserted later in the dynar */
   }
-  count = 0;
+
+  /*
+   * Create edges
+   */
+  xbt_dynar_t edges = xbt_dynar_new(sizeof(Agedge_t*), NULL);
+  for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
+    unsigned cursor;
+    Agedge_t * edge;
+    xbt_dynar_reset(edges);
+    for (edge = agfstout(dag_dot, node); edge; edge = agnxtout(dag_dot, edge))
+      xbt_dynar_push_as(edges, Agedge_t *, edge);
 #ifdef HAVE_CGRAPH_H
-  for (e = agfstout(dag_dot, dag_node); e; e = agnxtout(dag_dot, e))
-#elif HAVE_AGRAPH_H
-  for (e = agfstout(dag_node); e; e = agnxtout(e))
+    /* Hack: circumvent a bug in libcgraph, where the edges are not always given
+     * back in creation order.  We sort them again, according to their sequence
+     * id.  The problem appears to be solved (i.e.: I did not test it) in
+     * graphviz' mercurial repository by the following changeset:
+     *    changeset:   8431:d5f1fb7e8103
+     *    user:        Emden Gansner <erg@research.att.com>
+     *    date:        Tue Oct 11 12:38:58 2011 -0400
+     *    summary:     Make sure edges are stored in node creation order
+     * It should be fixed in graphviz 2.30 and above.
+     */
+    xbt_dynar_sort(edges, edge_compare);
 #endif
-  {
-
-    dot_add_output_dependencies(current_job, e);
-    count++;
-  }
-  if (count == 0 && current_job != end_task) {
-    SD_task_dependency_add(NULL, NULL, current_job, end_task);
-  }
-
-  if(schedule){
-    /* try to take the information to schedule the task only if all is
-     * right*/
-    // performer is the computer which execute the task
-    unsigned long performer = -1;
-    char * char_performer = agget(dag_node, (char *) "performer");
-    if (char_performer != NULL)
-      performer = (long) dot_parse_int(char_performer);
-
-    // order is giving the task order on one computer
-    unsigned long order = -1;
-    char * char_order = agget(dag_node, (char *) "order");
-    if (char_order != NULL)
-      order = (long) dot_parse_int(char_order);
-    xbt_dynar_t computer = NULL;
-    //INFO2("performer = %d, order=%d",performer,order);
-    if(performer != -1 && order != -1){
-      //necessary parameters are given
-      computer = xbt_dict_get_or_null(computers, char_performer);
-      if(computer == NULL){
-        computer = xbt_dynar_new(sizeof(SD_task_t), NULL);
-        xbt_dict_set(computers, char_performer, computer, NULL);
-      }
-      if(performer < sd_global->workstation_count){
-        // the  wanted computer is available
-        SD_task_t *task_test = NULL;
-        if(order < computer->used)
-          task_test = xbt_dynar_get_ptr(computer,order);
-        if(task_test != NULL && *task_test != NULL && *task_test != current_job){
-          /*the user gives the same order to several tasks*/
-          schedule = false;
-          DEBUG0("scheduling does not take into account, several task has\
-                the same order");
-        }else{
-          //the parameter seems to be ok
-          xbt_dynar_set_as(computer, order, SD_task_t, current_job);
+    xbt_dynar_foreach(edges, cursor, edge) {
+      SD_task_t src, dst;
+      char *src_name=agnameof(agtail(edge));
+      char *dst_name=agnameof(aghead(edge));
+      double size = atof(agget(edge, (char *) "size"));
+
+      src = xbt_dict_get_or_null(jobs, src_name);
+      dst  = xbt_dict_get_or_null(jobs, dst_name);
+
+      if (size > 0) {
+        char *name =
+            xbt_malloc((strlen(src_name)+strlen(dst_name)+6)*sizeof(char));
+        sprintf(name, "%s->%s", src_name, dst_name);
+        XBT_DEBUG("See <transfer id=%s amount = %.0f>", name, size);
+        if (!(task = xbt_dict_get_or_null(jobs, name))) {
+          if (seq_or_par == sequential)
+            task = SD_task_create_comm_e2e(name, NULL , size);
+          else
+            task = SD_task_create_comm_par_mxn_1d_block(name, NULL , size);
+          TRACE_sd_dotloader (task, agget (node, (char*)"category"));
+          SD_task_dependency_add(NULL, NULL, src, task);
+          SD_task_dependency_add(NULL, NULL, task, dst);
+          xbt_dict_set(jobs, name, task, NULL);
+          xbt_dynar_push(result, &task);
+        } else {
+          XBT_WARN("Task '%s' is defined more than once", name);
         }
-      }else{
-        /*the platform has not enough processors to schedule the DAG like
-        *the user wants*/
-        schedule = false;
-        DEBUG0("scheduling does not take into account, not enough computers");
+        xbt_free(name);
+      } else {
+        SD_task_dependency_add(NULL, NULL, src, dst);
       }
     }
-    else if((performer == -1 && order != -1) ||
-            (performer != -1 && order == -1)){
-      //one of necessary parameters are not given
-      schedule = false;
-      DEBUG0("scheduling does not take into account");
-    } else {
-      //No schedule available
-      schedule = false;
-    }
   }
-}
+  xbt_dynar_free(&edges);
 
-/* dot_add_output_dependencies create the dependencies between a task
- * and a transfers. This is given by the edges in the dot file. 
- * The amount of data transfers is given by the attribute size on the
- * edge. */
-void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge)
-{
-  SD_task_t file;
-
-  char name[80];
-  sprintf(name, "%s->%s", agnameof(agtail(edge)), agnameof(aghead(edge)));
-  double size = dot_parse_double(agget(edge, (char *) "size"));
-  DEBUG2("size : %e, get size : %s", size, agget(edge, (char *) "size"));
-
-  if (size > 0) {
-    file = xbt_dict_get_or_null(files, name);
-    if (file == NULL) {
-      file = SD_task_create_comm_e2e(name, NULL, size);
-#ifdef HAVE_TRACING
-      TRACE_sd_dotloader (file, agget (edge, (char*)"category"));
-#endif
-      xbt_dict_set(files, name, file, &dot_task_free);
-    } else {
-      if (SD_task_get_amount(file) != size) {
-        WARN3("Ignoring file %s size redefinition from %.0f to %.0f",
-              name, SD_task_get_amount(file), size);
-      }
-    }
-    SD_task_dependency_add(NULL, NULL, file, current_job);
-  } else {
-    file = xbt_dict_get_or_null(jobs, agnameof(agtail(edge)));
-    if (file != NULL) {
-      SD_task_dependency_add(NULL, NULL, file, current_job);
+  /* all compute and transfer tasks have been created, put the "end" node at
+   * the end of dynar
+   */
+  XBT_DEBUG("All tasks have been created, put %s at the end of the dynar",
+      end->name);
+  xbt_dynar_push(result, &end);
+
+  /* Connect entry tasks to 'root', and exit tasks to 'end'*/
+
+  xbt_dynar_foreach (result, i, task){
+    if (task == root || task == end)
+      continue;
+    if (xbt_dynar_is_empty(task->tasks_before)) {
+      XBT_DEBUG("file '%s' has no source. Add dependency from 'root'",
+          task->name);
+      SD_task_dependency_add(NULL, NULL, root, task);
+    } else if (xbt_dynar_is_empty(task->tasks_after)) {
+      XBT_DEBUG("file '%s' has no destination. Add dependency to 'end'",
+          task->name);
+      SD_task_dependency_add(NULL, NULL, task, end);
     }
   }
-}
 
-/* dot_add_output_dependencies create the dependencies between a
- * transfers and a task. This is given by the edges in the dot file.
- * The amount of data transfers is given by the attribute size on the
- * edge. */
-void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge)
-{
-  SD_task_t file;
-  char name[80];
-  sprintf(name, "%s->%s", agnameof(agtail(edge)), agnameof(aghead(edge)));
-  double size = dot_parse_double(agget(edge, (char *) "size"));
-  DEBUG2("size : %e, get size : %s", size, agget(edge, (char *) "size"));
-
-  if (size > 0) {
-    file = xbt_dict_get_or_null(files, name);
-    if (file == NULL) {
-      file = SD_task_create_comm_e2e(name, NULL, size);
-#ifdef HAVE_TRACING
-      TRACE_sd_dotloader (file, agget (edge, (char*)"category"));
-#endif
-      xbt_dict_set(files, name, file, &dot_task_free);
-    } else {
-      if (SD_task_get_amount(file) != size) {
-        WARN3("Ignoring file %s size redefinition from %.0f to %.0f",
-              name, SD_task_get_amount(file), size);
-      }
-    }
-    SD_task_dependency_add(NULL, NULL, current_job, file);
-    if (xbt_dynar_length(file->tasks_before) > 1) {
-      WARN1("File %s created at more than one location...", file->name);
-    }
-  } else {
-    file = xbt_dict_get_or_null(jobs, agnameof(aghead(edge)));
-    if (file != NULL) {
-      SD_task_dependency_add(NULL, NULL, current_job, file);
-    }
+  agclose(dag_dot);
+  xbt_dict_free(&jobs);
+  fclose(in_file);
+
+  if (!acyclic_graph_detail(result)) {
+    XBT_ERROR("The DOT described in %s is not a DAG. It contains a cycle.",
+              basename((char*)filename));
+    xbt_dynar_free(&result);
+    /* (result == NULL) here */
   }
+  return result;
 }