starpu_send_recv_data_use.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/env python3
  2. # StarPU --- Runtime system for heterogeneous multicore architectures.
  3. #
  4. # Copyright (C) 2019-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  5. #
  6. # StarPU is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU Lesser General Public License as published by
  8. # the Free Software Foundation; either version 2.1 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # StarPU is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. #
  15. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. #
  17. import sys
  18. PROGNAME = sys.argv[0]
  19. def usage():
  20. print("Offline tool to draw graph showing elapsed time between sent or received data and their use by tasks")
  21. print("")
  22. print("Usage: %s <folder containing comms.rec and tasks.rec files>" % PROGNAME)
  23. if len(sys.argv) != 2:
  24. usage()
  25. sys.exit(1)
  26. import re
  27. import numpy as np
  28. import matplotlib.pyplot as plt
  29. from matplotlib.gridspec import GridSpec
  30. import os
  31. def convert_rec_file(filename):
  32. lines = []
  33. item = dict()
  34. with open(filename, "r") as f:
  35. for l in f.readlines():
  36. if l == "\n":
  37. lines.append(item)
  38. item = dict()
  39. else:
  40. ls = l.split(":")
  41. key = ls[0].lower()
  42. value = ls[1].strip()
  43. if key in item:
  44. print("Warning: duplicated key '" + key + "'")
  45. else:
  46. if re.match('^\d+$', value) != None:
  47. item[key] = int(value)
  48. elif re.match("^\d+\.\d+$", value) != None:
  49. item[key] = float(value)
  50. else:
  51. item[key] = value
  52. return lines
  53. working_directory = sys.argv[1]
  54. comms = convert_rec_file(os.path.join(working_directory, "comms.rec"))
  55. tasks = [t for t in convert_rec_file(os.path.join(working_directory, "tasks.rec")) if "control" not in t and "starttime" in t]
  56. if len(tasks) == 0:
  57. print("There is no task using data after communication.")
  58. sys.exit(0)
  59. def plot_graph(comm_time_key, match, filename, title, xlabel):
  60. delays = []
  61. workers = dict()
  62. nb = 0
  63. durations = []
  64. min_time = 0.
  65. max_time = 0.
  66. for c in comms:
  67. t_matched = None
  68. for t in tasks:
  69. if match(t, c):
  70. t_matched = t
  71. break
  72. if t_matched is not None:
  73. worker = str(t_matched['mpirank']) + "-" + str(t_matched['workerid'])
  74. if worker not in workers:
  75. workers[worker] = []
  76. eps = t["starttime"] - c[comm_time_key]
  77. assert(eps > 0)
  78. durations.append(eps)
  79. workers[worker].append((c[comm_time_key], eps))
  80. if min_time == 0 or c[comm_time_key] < min_time:
  81. min_time = c[comm_time_key]
  82. if max_time == 0 or c[comm_time_key] > max_time:
  83. max_time = c[comm_time_key]
  84. nb += 1
  85. fig = plt.figure(constrained_layout=True)
  86. gs = GridSpec(2, 2, figure=fig)
  87. axs = [fig.add_subplot(gs[0, :-1]), fig.add_subplot(gs[1, :-1]), fig.add_subplot(gs[0:, -1])]
  88. i = 0
  89. for y, x in workers.items():
  90. # print(y, x)
  91. axs[0].broken_barh(x, [i*10, 8], facecolors=(0.1, 0.2, 0.5, 0.2))
  92. i += 1
  93. i = 0
  94. for y, x in workers.items():
  95. for xx in x:
  96. axs[1].broken_barh([xx], [i, 1])
  97. i += 1
  98. axs[0].set_yticks([i*10+4 for i in range(len(workers))])
  99. axs[0].set_yticklabels(list(workers))
  100. axs[0].set(xlabel="Time (ms) - Duration: " + str(max_time - min_time) + "ms", ylabel="Worker [mpi]-[*pu]", title=title)
  101. if len(durations) != 0:
  102. axs[2].hist(durations, bins=np.logspace(np.log10(1), np.log10(max(durations)), 50), rwidth=0.8)
  103. axs[2].set_xscale("log")
  104. axs[2].set(xlabel=xlabel, ylabel="Number of occurences", title="Histogramm")
  105. fig.set_size_inches(15, 9)
  106. plt.savefig(os.path.join(working_directory, filename), dpi=100)
  107. plt.show()
  108. plot_graph("recvtime", lambda t, c: (t["mpirank"] == c["dst"] and t["starttime"] >= c["recvtime"] and str(c["recvhandle"]) in t["handles"]), "recv_use.png", "Elapsed time between recv and use (ms)", "Time between data reception and its use by a task")
  109. plot_graph("sendtime", lambda t, c: (t["mpirank"] == c["src"] and t["starttime"] >= c["sendtime"] and str(c["sendhandle"]) in t["handles"]), "send_use.png", "Elapsed time between send and use (ms)", "Time between data sending and its use by a task")