starpu_send_recv_data_use.py 4.6 KB

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