starpu_fxt_dag.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2012,2015,2017,2018 CNRS
  5. * Copyright (C) 2010-2015,2017 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. #include <common/config.h>
  21. #ifdef STARPU_USE_FXT
  22. #include "starpu_fxt.h"
  23. static FILE *out_file;
  24. static unsigned cluster_cnt;
  25. void _starpu_fxt_dag_init(char *out_path)
  26. {
  27. if (!out_path)
  28. {
  29. out_file = NULL;
  30. return;
  31. }
  32. /* create a new file */
  33. out_file = fopen(out_path, "w+");
  34. if (!out_file)
  35. {
  36. _STARPU_MSG("error while opening %s\n", out_path);
  37. perror("fopen");
  38. exit(1);
  39. }
  40. cluster_cnt = 0;
  41. fprintf(out_file, "digraph G {\n");
  42. fprintf(out_file, "\tcolor=white\n");
  43. fprintf(out_file, "\trankdir=LR;\n");
  44. /* Create a new cluster */
  45. fprintf(out_file, "subgraph cluster_%u {\n", cluster_cnt);
  46. fprintf(out_file, "\tcolor=black;\n");
  47. }
  48. void _starpu_fxt_dag_terminate(void)
  49. {
  50. if (!out_file)
  51. return;
  52. /* Close the last cluster */
  53. fprintf(out_file, "}\n");
  54. /* Close the graph */
  55. fprintf(out_file, "}\n");
  56. fclose(out_file);
  57. }
  58. void _starpu_fxt_dag_add_tag(const char *prefix, uint64_t tag, unsigned long job_id, const char *label)
  59. {
  60. if (out_file)
  61. {
  62. if (label)
  63. fprintf(out_file, "\t \"tag_%s%llx\"->\"task_%s%lu\"->\"tag_%s%llx\" [style=dashed] [label=\"%s\"]\n", prefix, (unsigned long long)tag, prefix, (unsigned long)job_id, prefix, (unsigned long long) tag, label);
  64. else
  65. fprintf(out_file, "\t \"tag_%s%llx\"->\"task_%s%lu\"->\"tag_%s%llx\" [style=dashed]\n", prefix, (unsigned long long)tag, prefix, (unsigned long)job_id, prefix, (unsigned long long) tag);
  66. }
  67. }
  68. void _starpu_fxt_dag_add_tag_deps(const char *prefix, uint64_t child, uint64_t father, const char *label)
  69. {
  70. if (out_file)
  71. {
  72. if (label)
  73. fprintf(out_file, "\t \"tag_%s%llx\"->\"tag_%s%llx\" [label=\"%s\"]\n", prefix, (unsigned long long)father, prefix, (unsigned long long)child, label);
  74. else
  75. fprintf(out_file, "\t \"tag_%s%llx\"->\"tag_%s%llx\"\n", prefix, (unsigned long long)father, prefix, (unsigned long long)child);
  76. }
  77. }
  78. void _starpu_fxt_dag_add_task_deps(const char *prefix, unsigned long dep_prev, unsigned long dep_succ, const char *label)
  79. {
  80. if (out_file)
  81. {
  82. if (label)
  83. fprintf(out_file, "\t \"task_%s%lu\"->\"task_%s%lu\" [label=\"%s\"]\n", prefix, dep_prev, prefix, dep_succ, label);
  84. else
  85. fprintf(out_file, "\t \"task_%s%lu\"->\"task_%s%lu\"\n", prefix, dep_prev, prefix, dep_succ);
  86. }
  87. }
  88. void _starpu_fxt_dag_set_tag_done(const char *prefix, uint64_t tag, const char *color)
  89. {
  90. if (out_file)
  91. fprintf(out_file, "\t \"tag_%s%llx\" [ style=filled, fillcolor=\"%s\"]\n",
  92. prefix, (unsigned long long)tag, color);
  93. }
  94. void _starpu_fxt_dag_set_task_name(const char *prefix, unsigned long job_id, const char *label, const char *color)
  95. {
  96. if (out_file)
  97. fprintf(out_file, "\t \"task_%s%lu\" [ style=filled, label=\"%s\", fillcolor=\"%s\"]\n", prefix, job_id, label, color);
  98. }
  99. void _starpu_fxt_dag_add_send(int src, unsigned long dep_prev, unsigned long tag, unsigned long id)
  100. {
  101. if (out_file)
  102. fprintf(out_file, "\t \"task_%d_%lu\"->\"mpi_%lu_%lu\"\n", src, dep_prev, tag, id);
  103. }
  104. void _starpu_fxt_dag_add_receive(int dst, unsigned long dep_prev, unsigned long tag, unsigned long id)
  105. {
  106. if (out_file)
  107. fprintf(out_file, "\t \"mpi_%lu_%lu\"->\"task_%d_%lu\"\n", tag, id, dst, dep_prev);
  108. }
  109. void _starpu_fxt_dag_add_sync_point(void)
  110. {
  111. if (!out_file)
  112. return;
  113. /* Close the previous cluster */
  114. fprintf(out_file, "}\n");
  115. cluster_cnt++;
  116. /* Create a new cluster */
  117. fprintf(out_file, "subgraph cluster_%u {\n", cluster_cnt);
  118. fprintf(out_file, "\tcolor=black;\n");
  119. }
  120. #endif /* STARPU_USE_FXT */