diff --git a/examples/main.c b/examples/main.c
index 88fddc955b244ef259f77899d15b9ec5db1680b0..15431838a359b81b5eb50caa3a5d4358fc735a3e 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -59,9 +59,6 @@ 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.");
@@ -174,9 +171,6 @@ 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;
@@ -202,11 +196,6 @@ 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;
@@ -702,10 +691,6 @@ int main(int argc, char *argv[]) {
   engine_dump_snapshot(&e);
   engine_print_stats(&e);
 
-#ifdef SWIFT_DEBUG_CHECKS
-  if (write_dependencies) scheduler_write_dependency(&e.sched);
-#endif
-
   /* Legend */
   if (myrank == 0)
     printf("# %6s %14s %14s %10s %10s %10s %16s [%s]\n", "Step", "Time",
diff --git a/src/engine.c b/src/engine.c
index 35efcb1dafb1e50cfae9f418905d08715c171bbf..6a709db36759a9de292265d6077fa0d059e9751d 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -3587,6 +3587,9 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
     gravity_exact_force_compute(e->s, e);
 #endif
 
+  if(e->nodeID == 0)
+    scheduler_write_dependencies(&e->sched, e->verbose);
+
   /* Run the 0th time-step */
   engine_launch(e);
 
diff --git a/src/scheduler.c b/src/scheduler.c
index 867bb2f1335a2a81c57ece0578d614feaa1f1b48..045c93e2a00d4e3ac641f2270d3f33f41d620743 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -115,57 +115,54 @@ void scheduler_addunlock(struct scheduler *s, struct task *ta,
 /**
  * @brief Write a dot file with the task dependencies.
  *
- * See examples/task_graph for an example of how to use it
+ * Run plot_task_dependencies.sh for an example of how to use it
+ * to generate the figure.
+ *
  * @param s The #scheduler we are working in.
+ * @param verbose Are we verbose about this?
  */
-void scheduler_write_dependency(struct scheduler *s) {
-#ifdef WITH_MPI
-  if (engine_rank != 0) return;
-#endif
-  int i, j;
+void scheduler_write_dependencies(struct scheduler *s, int verbose) {
+ 
+  const ticks tic = getticks();
 
-  int max_nber_dep = 5;
-  /* 2 => we need 1 int for type and 1 for subtype */
-  int nber_relation = 2 * task_type_count * task_subtype_count * max_nber_dep;
-  /* For each type/subtype, a table of 2*max_nber_dep int is available =>
-     max_nber_dep task with subtype available
+  /* Conservative number of dependencies per task type */
+  const int max_nber_dep = 128;
 
-     -1 means that it is not set yet
+  /* Number of possibble relations between tasks */
+  const int nber_relation = 2 * task_type_count * task_subtype_count * max_nber_dep;
 
-     to get the table of max_nber_dep for a task:
-     ind = (ta * task_subtype_count + sa) * max_nber_dep * 2
-     where ta is the value of task_type and sa is the value of
-     task_subtype
-   */
+  /* To get the table of max_nber_dep for a task:
+   * ind = (ta * task_subtype_count + sa) * max_nber_dep * 2
+   * where ta is the value of task_type and sa is the value of
+   * task_subtype  */
   int *table = malloc(nber_relation * sizeof(int));
-  for (i = 0; i < nber_relation; i++) table[i] = -1;
+  if(table == NULL) error("Error allocating memory for task-dependency graph.");
 
-  message("Writing dependencies");
+  /* Reset everything */
+  for (int i = 0; i < nber_relation; i++) table[i] = -1;
 
-  /* create file */
+  /* Create file */
   char filename[200] = "dependency_graph.dot";
-  FILE *f; /* file containing the output */
-  f = open_and_check_file(filename, "w");
+  FILE *f = open_and_check_file(filename, "w");
 
-  /* write header */
+  /* 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");
 
   /* loop over all tasks */
-  for (i = 0; i < s->nr_tasks; i++) {
-    struct task *ta;
-    ta = &s->tasks[i];
+  for (int i = 0; i < s->nr_tasks; i++) {
+    const struct task *ta = &s->tasks[i];
 
     /* and theirs dependencies */
-    for (j = 0; j < ta->nr_unlock_tasks; j++) {
-      struct task *tb;
-      tb = ta->unlock_tasks[j];
+    for (int j = 0; j < ta->nr_unlock_tasks; j++) {
+      const struct task *tb = ta->unlock_tasks[j];
 
       char tmp[200]; /* text to write */
       char ta_name[200];
       char tb_name[200];
+
       /* construct line */
       if (ta->subtype == task_subtype_none)
         sprintf(ta_name, "%s", taskID_names[ta->type]);
@@ -190,6 +187,7 @@ void scheduler_write_dependency(struct scheduler *s) {
       int k = 0;
       int *cur = &table[ind];
       while (k < max_nber_dep) {
+
         /* not written yet */
         if (cur[0] == -1) {
           cur[0] = tb->type;
@@ -218,9 +216,14 @@ void scheduler_write_dependency(struct scheduler *s) {
     }
   }
 
+  /* Be clean */
   fprintf(f, "}");
   fclose(f);
   free(table);
+
+  if(verbose)
+    message("Printing task graph took %.3f %s.",
+	    clocks_from_ticks(getticks() - tic), clocks_getunit());
 }
 
 /**
diff --git a/src/scheduler.h b/src/scheduler.h
index dfcc33b9841b0a0e7c55793387dbf72abf51d48e..1ef43f101a3f0b058893f6ee9e178b2e3eda2553 100644
--- a/src/scheduler.h
+++ b/src/scheduler.h
@@ -168,6 +168,6 @@ void scheduler_dump_queue(struct scheduler *s);
 void scheduler_print_tasks(const struct scheduler *s, const char *fileName);
 void scheduler_clean(struct scheduler *s);
 void scheduler_free_tasks(struct scheduler *s);
-void scheduler_write_dependency(struct scheduler *s);
+void scheduler_write_dependencies(struct scheduler *s, int verbose);
 
 #endif /* SWIFT_SCHEDULER_H */