#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");
#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);
static double dot_parse_double(const char *string)
{
- if (string == NULL)
- return -1;
- double value = -1;
- char *err;
-
- //ret = sscanf(string, "%lg", &value);
- errno = 0;
- value = strtod(string,&err);
- if(errno)
- {
- XBT_WARN("Failed to convert string to double: %s\n",strerror(errno));
- return -1;
- }
- return value;
+ if (string == NULL)
+ return -1;
+ double value = -1;
+ char *err;
+
+ //ret = sscanf(string, "%lg", &value);
+ errno = 0;
+ value = strtod(string,&err);
+ if(errno)
+ {
+ XBT_WARN("Failed to convert string to double: %s\n",strerror(errno));
+ return -1;
+ }
+ return value;
}
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){
}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;
+ xbt_dict_foreach(computers,dict_cursor,computer_name,computer){
+ xbt_dynar_free(&computer);
+ }
+ xbt_dict_free(&computers);
+ xbt_dynar_foreach(result,count,task){
+ SD_task_destroy(task);
+ }
return NULL;
}
xbt_dynar_t SD_dotload_generic(const char * filename)
{
xbt_assert(filename, "Unable to use a null file descriptor\n");
-//dag_dot = agopen((char*)filename,Agstrictdirected,0);
+ //dag_dot = agopen((char*)filename,Agstrictdirected,0);
FILE *in_file = fopen(filename, "r");
dag_dot = agread(in_file, NIL(Agdisc_t *));
- result = xbt_dynar_new(sizeof(SD_task_t), dot_task_free);
+ result = xbt_dynar_new(sizeof(SD_task_t), dot_task_p_free);
files = xbt_dict_new_homogeneous(&dot_task_free);
jobs = xbt_dict_new_homogeneous(NULL);
computers = xbt_dict_new_homogeneous(NULL);
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)
-#endif
- ) {
-
- dot_add_task(dag_node);
+ for (dag_node = agfstnode(dag_dot); dag_node; dag_node = agnxtnode(dag_dot, dag_node)) {
+ dot_add_task(dag_node);
}
agclose(dag_dot);
xbt_dict_free(&jobs);
/* Free previous copy of the files */
xbt_dict_free(&files);
fclose(in_file);
- if(acyclic_graph_detail(result))
- return result;
- acyclic_graph_detail(result);
- free(dag_dot);
- return NULL;
+ 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;
}
/* dot_add_task create a sd_task and all transfers required for this
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++;
+ for (e = agfstin(dag_dot, dag_node); e; e = agnxtin(dag_dot, e)) {
+ 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);
}
count = 0;
-#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))
-#endif
- {
-
+ for (e = agfstout(dag_dot, dag_node); e; e = agnxtout(dag_dot, e)) {
dot_add_output_dependencies(current_job, e);
count++;
}
else {
//one of necessary parameters are not given
schedule = false;
- XBT_VERB("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 scheduled", current_job->name);
}
}
}
* edge. */
void dot_add_input_dependencies(SD_task_t current_job, Agedge_t * edge)
{
- SD_task_t file;
+ SD_task_t file = NULL;
char *name_tail=agnameof(agtail(edge));
char *name_head=agnameof(aghead(edge));
- char *name = malloc((strlen(name_head)+strlen(name_tail)+3)*sizeof(char));
+ char *name = xbt_malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char));
sprintf(name, "%s->%s", name_tail, name_head);
double size = dot_parse_double(agget(edge, (char *) "size"));
XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size"));
}
SD_task_dependency_add(NULL, NULL, file, current_job);
} else {
- file = xbt_dict_get_or_null(jobs, agnameof(agtail(edge)));
+ file = xbt_dict_get_or_null(jobs, name_tail);
if (file != NULL) {
SD_task_dependency_add(NULL, NULL, file, current_job);
}
SD_task_t file;
char *name_tail=agnameof(agtail(edge));
char *name_head=agnameof(aghead(edge));
- char *name = malloc((strlen(name_head)+strlen(name_tail)+3)*sizeof(char));
+ char *name = xbt_malloc((strlen(name_head)+strlen(name_tail)+6)*sizeof(char));
sprintf(name, "%s->%s", name_tail, name_head);
double size = dot_parse_double(agget(edge, (char *) "size"));
XBT_DEBUG("size : %e, get size : %s", size, agget(edge, (char *) "size"));
XBT_WARN("File %s created at more than one location...", file->name);
}
} else {
- file = xbt_dict_get_or_null(jobs, agnameof(aghead(edge)));
+ file = xbt_dict_get_or_null(jobs, name_head);
if (file != NULL) {
SD_task_dependency_add(NULL, NULL, current_job, file);
}