Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use new style logging macros.
[simgrid.git] / src / simdag / sd_dotloader.c
index 6bd182c..9da658e 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)
 {
@@ -35,7 +34,7 @@ static double dot_parse_double(const char *string)
 
   ret = sscanf(string, "%lg", &value);
   if (ret != 1)
-    WARN1("%s is not a double", string);
+    XBT_WARN("%s is not a double", string);
   return value;
 }
 
@@ -48,7 +47,7 @@ static int dot_parse_int(const char *string)
 
   ret = sscanf(string, "%d", &value);
   if (ret != 1)
-    WARN1("%s is not an integer", string);
+    XBT_WARN("%s is not an integer", string);
   return value;
 }
 
@@ -65,96 +64,11 @@ static void dump_res()
   unsigned int cursor;
   SD_task_t task;
   xbt_dynar_foreach(result, cursor, task) {
-    INFO1("Task %d", cursor);
+    XBT_INFO("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("the task %s is not marked",task->name);
-      all_marked = false;
-      break;
-    }
-  }
-  task = NULL;
-  if(!all_marked){
-    VERB0("there is at least one cycle in your task graph");
-  }
-  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 is at least one cycle in the provided task graph");
+      XBT_WARN("There is at least one cycle in the provided task graph");
   }else{
-    WARN0("The scheduling is ignored");
+    XBT_WARN("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();
@@ -301,7 +209,7 @@ xbt_dynar_t SD_dotload_FILE(FILE * in_file)
       xbt_dynar_foreach(file->tasks_before, cpt1, depbefore) {
         xbt_dynar_foreach(file->tasks_after, cpt2, depafter) {
           if (depbefore->src == depafter->dst) {
-            WARN2
+            XBT_WARN
                 ("File %s is produced and consumed by task %s. This loop dependency will prevent the execution of the task.",
                  file->name, depbefore->src->name);
           }
@@ -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;
 }
 
@@ -334,7 +244,7 @@ void dot_add_task(Agnode_t * 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,
+  XBT_DEBUG("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) {
@@ -391,7 +301,7 @@ void dot_add_task(Agnode_t * dag_node)
     if (char_order != NULL)
       order = (long) dot_parse_int(char_order);
     xbt_dynar_t computer = NULL;
-    //INFO2("performer = %d, order=%d",performer,order);
+    //XBT_INFO("performer = %d, order=%d",performer,order);
     if(performer != -1 && order != -1){
       //necessary parameters are given
       computer = xbt_dict_get_or_null(computers, char_performer);
@@ -407,7 +317,7 @@ 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;
-          VERB4("The task %s starts on the computer %s at the position : %s like the task %s",
+          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, current_job->name);
         }else{
           //the parameter seems to be ok
@@ -417,13 +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;
-        VERB0("The schedule is ignored, there are not enough computers");
+        XBT_VERB("The schedule is ignored, there are not enough computers");
       }
     }
     else {
       //one of necessary parameters are not given
       schedule = false;
-      VERB1("The schedule is ignored, the task %s is not correctly schedule", current_job->name);
+      XBT_VERB("The schedule is ignored, the task %s is not correctly schedule", current_job->name);
     }
   }
 }
@@ -439,7 +349,7 @@ void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge)
   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"));
+  XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size"));
 
   if (size > 0) {
     file = xbt_dict_get_or_null(files, name);
@@ -451,7 +361,7 @@ void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge)
       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",
+        XBT_WARN("Ignoring file %s size redefinition from %.0f to %.0f",
               name, SD_task_get_amount(file), size);
       }
     }
@@ -474,7 +384,7 @@ void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge)
   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"));
+  XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size"));
 
   if (size > 0) {
     file = xbt_dict_get_or_null(files, name);
@@ -486,13 +396,13 @@ void dot_add_output_dependencies(SD_task_t current_job, Agedge_t * edge)
       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",
+        XBT_WARN("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);
+      XBT_WARN("File %s created at more than one location...", file->name);
     }
   } else {
     file = xbt_dict_get_or_null(jobs, agnameof(aghead(edge)));