Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bugfix: do not assume that request of different type are independent, as it is wrong.
[simgrid.git] / src / simdag / sd_dotloader.c
index f62679a..c9c34ce 100644 (file)
@@ -23,8 +23,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_dotparse, sd, "Parsing DOT files");
 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);
+xbt_dynar_t SD_dotload_generic(const char * filename);
 
 static double dot_parse_double(const char *string)
 {
@@ -70,91 +69,6 @@ static void dump_res()
   }
 }
 
-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)
 {
@@ -183,10 +97,7 @@ static void TRACE_sd_dotloader (SD_task_t task, const char *category)
  */
 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);
+  SD_dotload_generic(filename);
   xbt_dynar_t computer = NULL;
   xbt_dict_cursor_t dict_cursor;
   char *computer_name;
@@ -198,10 +109,7 @@ xbt_dynar_t SD_dotload(const char *filename)
 }
 
 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);
+  SD_dotload_generic(filename);
 
   if(schedule == true){
     xbt_dynar_t computer = NULL;
@@ -227,20 +135,20 @@ 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");
+      WARN0("There is at least one cycle in the provided task graph");
   }else{
-    WARN0("No scheduling provided");
+    WARN0("The scheduling is ignored");
   }
   return NULL;
 }
 
-xbt_dynar_t SD_dotload_FILE(FILE * in_file)
+xbt_dynar_t SD_dotload_generic(const char * filename)
 {
-  xbt_assert0(in_file, "Unable to use a null file descriptor\n");
-  dag_dot = agread(in_file, NIL(Agdisc_t *));
+  xbt_assert0(filename, "Unable to use a null file descriptor\n");
+  dag_dot =  agopen((char*)filename,Agstrictdirected,0);
 
   result = xbt_dynar_new(sizeof(SD_task_t), dot_task_free);
   files = xbt_dict_new();
@@ -320,8 +228,10 @@ xbt_dynar_t SD_dotload_FILE(FILE * in_file)
 
   /* Free previous copy of the files */
   xbt_dict_free(&files);
-  if(acyclic_graph_detection(result))
+  if(acyclic_graph_detail(result))
     return result;
+  acyclic_graph_detail(result);
+  free(dag_dot);
   return NULL;
 }
 
@@ -376,7 +286,7 @@ void dot_add_task(Agnode_t * dag_node)
     SD_task_dependency_add(NULL, NULL, current_job, end_task);
   }
 
-  if(schedule){
+  if(schedule || XBT_LOG_ISENABLED(sd_dotparse, xbt_log_priority_verbose)){
     /* try to take the information to schedule the task only if all is
      * right*/
     // performer is the computer which execute the task
@@ -407,8 +317,8 @@ void dot_add_task(Agnode_t * dag_node)
         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");
+          VERB4("The task %s starts on the computer %s at the position : %s like the task %s",
+                 (*task_test)->name, char_performer, char_order, current_job->name);
         }else{
           //the parameter seems to be ok
           xbt_dynar_set_as(computer, order, SD_task_t, current_job);
@@ -417,17 +327,13 @@ void dot_add_task(Agnode_t * dag_node)
         /*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");
+        VERB0("The schedule is ignored, there are not enough computers");
       }
     }
-    else if((performer == -1 && order != -1) ||
-            (performer != -1 && order == -1)){
+    else {
       //one of necessary parameters are not given
       schedule = false;
-      DEBUG0("scheduling does not take into account");
-    } else {
-      //No schedule available
-      schedule = false;
+      VERB1("The schedule is ignored, the task %s is not correctly schedule", current_job->name);
     }
   }
 }