Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into mc-process
[simgrid.git] / src / simdag / sd_dotloader.c
index 8b5ee8a..e40a053 100644 (file)
@@ -1,11 +1,11 @@
-/* Copyright (c) 2009-2013. The SimGrid Team.
+/* Copyright (c) 2009-2014. 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>
@@ -40,17 +40,11 @@ static xbt_dict_t computers;
 static Agraph_t *dag_dot;
 static bool schedule = true;
 
-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);
 }
 
-#ifdef HAVE_TRACING
 static void TRACE_sd_dotloader (SD_task_t task, const char *category) {
   if (category && strlen (category)){
     if (task->category)
@@ -62,7 +56,6 @@ static void TRACE_sd_dotloader (SD_task_t task, const char *category) {
     TRACE_sd_set_task_category(task, category);
   }
 }
-#endif
 
 /** @brief loads a DOT file describing a DAG
  * 
@@ -122,8 +115,6 @@ xbt_dynar_t SD_dotload_with_sched(const char *filename) {
   }else{
     XBT_WARN("The scheduling is ignored");
   }
-  SD_task_t task;
-  unsigned int count;
   xbt_dynar_t computer = NULL;
   xbt_dict_cursor_t dict_cursor;
   char *computer_name;
@@ -131,9 +122,7 @@ xbt_dynar_t SD_dotload_with_sched(const char *filename) {
     xbt_dynar_free(&computer);
   }
   xbt_dict_free(&computers);
-  xbt_dynar_foreach(result,count,task){
-     SD_task_destroy(task);
-  }
+  xbt_dynar_free(&result);
   return NULL;
 }
 
@@ -148,6 +137,15 @@ xbt_dynar_t SD_PTG_dotload(const char * filename) {
   return result;
 }
 
+#ifdef HAVE_CGRAPH_H
+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
+
 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;
@@ -166,7 +164,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par){
 
     char *name = agnameof(node);
     double amount = atof(agget(node, (char *) "size"));
-    double alpha;
+    double alpha = 0.0;
 
     if (seq_or_par == sequential){
       XBT_DEBUG("See <job id=%s amount =%.0f>", name, amount);
@@ -192,9 +190,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par){
       } else {
         task = SD_task_create_comp_par_amdahl(name, NULL , amount, alpha);
       }
-#ifdef HAVE_TRACING
       TRACE_sd_dotloader (task, agget (node, (char*)"category"));
-#endif
       xbt_dict_set(jobs, name, task, NULL);
       if (!strcmp(name, "root")){
       /* by design the root task is always SCHEDULABLE */
@@ -295,10 +291,27 @@ xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par){
   /*
    * Create edges
    */
-  node = NULL;
+  xbt_dynar_t edges = xbt_dynar_new(sizeof(Agedge_t*), NULL);
   for (node = agfstnode(dag_dot); node; node = agnxtnode(dag_dot, node)) {
-    Agedge_t * edge = NULL;
-    for (edge = agfstout(dag_dot, node); edge; edge = agnxtout(dag_dot, edge)) {
+    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
+    /* 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
+    xbt_dynar_foreach(edges, cursor, edge) {
       SD_task_t src, dst;
       char *src_name=agnameof(agtail(edge));
       char *dst_name=agnameof(aghead(edge));
@@ -317,9 +330,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par){
             task = SD_task_create_comm_e2e(name, NULL , size);
           else
             task = SD_task_create_comm_par_mxn_1d_block(name, NULL , size);
-#ifdef HAVE_TRACING
           TRACE_sd_dotloader (task, agget (node, (char*)"category"));
-#endif
           SD_task_dependency_add(NULL, NULL, src, task);
           SD_task_dependency_add(NULL, NULL, task, dst);
           xbt_dict_set(jobs, name, task, NULL);
@@ -333,6 +344,7 @@ xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par){
       }
     }
   }
+  xbt_dynar_free(&edges);
 
   /* all compute and transfer tasks have been created, put the "end" node at
    * the end of dynar