diff --git a/examples/main.c b/examples/main.c index b09eefdbce291888bbaa026fba867a0d34ce45b7..992cc5070b9a9688a786c8a9e7a81c31271eaf31 100644 --- a/examples/main.c +++ b/examples/main.c @@ -59,6 +59,9 @@ void print_help_message() { printf(" swift_mpi [OPTION]... PARAMFILE\n\n"); printf("Valid options are:\n"); +#ifdef SWIFT_DEBUG_CHECKS + printf(" %2s %14s %s\n", "-x", "", "Write task dependencies."); +#endif printf(" %2s %14s %s\n", "-a", "", "Pin runners using processor affinity."); printf(" %2s %14s %s\n", "-c", "", "Run with cosmological time integration."); @@ -171,6 +174,9 @@ int main(int argc, char *argv[]) { int with_fp_exceptions = 0; int with_drift_all = 0; int with_mpole_reconstruction = 0; +#ifdef SWIFT_DEBUG_CHECKS + int write_dependencies = 0; +#endif int verbose = 0; int nr_threads = 1; int with_verbose_timers = 0; @@ -181,7 +187,11 @@ int main(int argc, char *argv[]) { /* Parse the parameters */ int c; - while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:sSt:Tv:y:Y:")) != -1) + char parameters[200] = "acCdDef:FgGhMn:P:sSt:Tv:y:Y:"; +#ifdef SWIFT_DEBUG_CHECKS + strcat(parameters, "x:"); +#endif + while ((c = getopt(argc, argv, parameters)) != -1) switch (c) { case 'a': #if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA) @@ -193,6 +203,11 @@ int main(int argc, char *argv[]) { case 'c': with_cosmology = 1; break; +#ifdef SWIFT_DEBUG_CHECKS + case 'x': + write_dependencies = 1; + break; +#endif case 'C': with_cooling = 1; break; @@ -697,6 +712,11 @@ int main(int argc, char *argv[]) { /* File for the timers */ if (with_verbose_timers) timers_open_file(myrank); +#ifdef SWIFT_DEBUG_CHECKS + if (write_dependencies) + scheduler_write_dependency(&e.sched); +#endif + /* Main simulation loop */ for (int j = 0; !engine_is_done(&e) && e.step - 1 != nsteps; j++) { diff --git a/src/engine.c b/src/engine.c index 6b93830de8ca03b7b8f8c8530200487bc364e81e..35efcb1dafb1e50cfae9f418905d08715c171bbf 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2640,10 +2640,6 @@ void engine_maketasks(struct engine *e) { /* Set the tasks age. */ e->tasks_age = 0; -#ifdef SWIFT_DEBUG_CHECKS - if (e->ti_current == 0) scheduler_write_dependency(sched); -#endif - if (e->verbose) message("took %.3f %s (including reweight).", clocks_from_ticks(getticks() - tic), clocks_getunit()); diff --git a/src/scheduler.c b/src/scheduler.c index 4aec57ebb16d6e1c056a9316a086218bf98c0d50..12ff2081744d7698a3a0917ae3792c77be5eaa78 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -120,19 +120,10 @@ void scheduler_write_dependency(struct scheduler *s) { message("Writing dependencies"); + /* create file */ 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"); + f = open_and_check_file(filename, "wr"); /* write header */ fprintf(f, "digraph task_dep {\n"); @@ -140,43 +131,44 @@ void scheduler_write_dependency(struct scheduler *s) { fprintf(f, "\t ratio=0.66;\n"); fprintf(f, "\t node[nodesep=0.15];\n"); - fclose(f); - /* loop over all tasks */ + int i, j; for (i = 0; i < s->nr_tasks; i++) { + struct task *ta; ta = &s->tasks[i]; /* and theirs dependencies */ for (j = 0; j < ta->nr_unlock_tasks; j++) { + struct task *tb; tb = ta->unlock_tasks[j]; + char tmp[200]; /* text to write */ /* 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; + int test = 1; + /* loop over all lines */ + char *line = NULL; /* buff for reading line */ + size_t len = 0; + ssize_t read; + fseek(f, 0, SEEK_SET); while (test && (read = getline(&line, &len, f)) != -1) { /* check if line == dependency word */ if (strcmp(tmp, line) == 0) test = 0; } - fclose(f); - + fseek(f, 0, SEEK_END); /* 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); }