Commit 22831b41 authored by lhausamm's avatar lhausamm
Browse files

Dependency graph is now well implemented

parent aac3e3c5
...@@ -2640,6 +2640,12 @@ void engine_maketasks(struct engine *e) { ...@@ -2640,6 +2640,12 @@ void engine_maketasks(struct engine *e) {
/* Set the tasks age. */ /* Set the tasks age. */
e->tasks_age = 0; e->tasks_age = 0;
#ifdef SWIFT_DEBUG_CHECKS
if (e->ti_current == 0)
scheduler_write_dependency(sched);
#endif
if (e->verbose) if (e->verbose)
message("took %.3f %s (including reweight).", message("took %.3f %s (including reweight).",
clocks_from_ticks(getticks() - tic), clocks_getunit()); clocks_from_ticks(getticks() - tic), clocks_getunit());
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "space.h" #include "space.h"
#include "task.h" #include "task.h"
#include "timers.h" #include "timers.h"
#include "tools.h"
/** /**
* @brief Re-set the list of active tasks. * @brief Re-set the list of active tasks.
...@@ -110,62 +111,82 @@ void scheduler_addunlock(struct scheduler *s, struct task *ta, ...@@ -110,62 +111,82 @@ void scheduler_addunlock(struct scheduler *s, struct task *ta,
s->unlock_ind[ind] = ta - s->tasks; s->unlock_ind[ind] = ta - s->tasks;
atomic_inc(&s->completed_unlock_writes); atomic_inc(&s->completed_unlock_writes);
scheduler_write_dependency(ta,tb);
} }
void scheduler_write_dependency(struct task *ta, struct task *tb) { void scheduler_write_dependency(struct scheduler *s) {
int test = ta->ci->ti_end_min == 0 && tb->ci->ti_end_min == 0;
test = test && ta->ci->parent == NULL && tb->ci->parent == NULL; message("Writing dependencies");
if (test)
char filename[200] = "dependency_graph.dot";
char tmp[200]; /* text to write */
char *line = NULL; /* buff for reading line */
size_t len = 0;
ssize_t read;
FILE *f; /* file containing the output */
int test;
int i,j;
struct task *ta, *tb;
/* create file */
f = open_and_check_file(filename, "w");
/* write header */
fprintf(f, "digraph task_dep {\n");
fprintf(f, "\t compound=true;\n");
fprintf(f, "\t ratio=0.66;\n");
fprintf(f, "\t node[nodesep=0.15];\n");
fclose(f);
/* loop over all tasks */
for(i=0; i < s->nr_tasks; i++)
{ {
char tmp[200]; ta = &s->tasks[i];
char *line = NULL;
size_t len = 0; /* and theirs dependencies */
ssize_t read; for(j=0; j < ta->nr_unlock_tasks; j++)
FILE *f;
sprintf(tmp, "\t%s_%s->%s_%s;\n",
taskID_names[ta->type],
subtaskID_names[ta->subtype],
taskID_names[tb->type],
subtaskID_names[tb->subtype]
);
f = fopen("test_graph.viz", "r");
if (f != NULL)
{ {
tb = ta->unlock_tasks[j];
/* construct line */
sprintf(tmp, "\t %s_%s->%s_%s;\n",
taskID_names[ta->type],
subtaskID_names[ta->subtype],
taskID_names[tb->type],
subtaskID_names[tb->subtype]
);
f = open_and_check_file(filename, "r");
/* check if dependency already written */
test = 1; test = 1;
/* loop over all lines */
while (test && (read = getline(&line, &len, f)) != -1) while (test && (read = getline(&line, &len, f)) != -1)
{ {
/* check if line == dependency word */
if (strcmp(tmp, line) == 0) if (strcmp(tmp, line) == 0)
{ test = 0;
test = 0;
}
} }
fclose(f);
}
else
{
f = fopen("test_graph.viz", "w");
fprintf(f,"digraph task_dep {\n\tcompound=true;\n\tratio=0.66;\n\tnode[nodesep=0.15];\n");
fclose(f);
}
if (test)
{
f = fopen("test_graph.viz", "a");
fprintf(f, tmp);
fclose(f); fclose(f);
}
/* Not written yet => write it */
if (test)
{
f = open_and_check_file(filename, "a");
fprintf(f, tmp);
fclose(f);
}
}
} }
f = open_and_check_file(filename, "a");
fprintf(f, "}");
fclose(f);
} }
/** /**
* @brief Split a hydrodynamic task if too large. * @brief Split a hydrodynamic task if too large.
* *
......
...@@ -168,6 +168,6 @@ void scheduler_dump_queue(struct scheduler *s); ...@@ -168,6 +168,6 @@ void scheduler_dump_queue(struct scheduler *s);
void scheduler_print_tasks(const struct scheduler *s, const char *fileName); void scheduler_print_tasks(const struct scheduler *s, const char *fileName);
void scheduler_clean(struct scheduler *s); void scheduler_clean(struct scheduler *s);
void scheduler_free_tasks(struct scheduler *s); void scheduler_free_tasks(struct scheduler *s);
void scheduler_write_dependency(struct task *ta, struct task *tb); void scheduler_write_dependency(struct scheduler *s);
#endif /* SWIFT_SCHEDULER_H */ #endif /* SWIFT_SCHEDULER_H */
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
/* This object's header. */ /* This object's header. */
#include "tools.h" #include "tools.h"
...@@ -694,3 +695,16 @@ int compare_particles(struct part a, struct part b, double threshold) { ...@@ -694,3 +695,16 @@ int compare_particles(struct part a, struct part b, double threshold) {
#endif #endif
} }
/**
* @brief Open a file and verify if it was correctly opened
*
* @param filename Name of the file
* @param mode Opening mode (e.g. 'a', 'w', ..)
*/
FILE *open_and_check_file(const char *filename, const char *mode) {
FILE *f = fopen(filename, mode);
if (f == NULL)
error("Unable to open file '%s' in mode %s, error: %i", filename, mode, errno);
return f;
}
...@@ -52,4 +52,7 @@ int compare_values(double a, double b, double threshold, double *absDiff, ...@@ -52,4 +52,7 @@ int compare_values(double a, double b, double threshold, double *absDiff,
double *absSum, double *relDiff); double *absSum, double *relDiff);
int compare_particles(struct part a, struct part b, double threshold); int compare_particles(struct part a, struct part b, double threshold);
FILE *open_and_check_file(const char *filename, const char *mode);
#endif /* SWIFT_TOOL_H */ #endif /* SWIFT_TOOL_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment