starpu_send_recv_data_use.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # StarPU --- Runtime system for heterogeneous multicore architectures.
  4. #
  5. # Copyright (C) 2019 Inria
  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. import sys
  19. PROGNAME = sys.argv[0]
  20. def usage():
  21. print("Offline tool to draw graph showing elapsed time between sent or received data and their use by tasks")
  22. print("")
  23. print("Usage: %s <folder containing comms.rec and tasks.rec files>" % PROGNAME)
  24. if len(sys.argv) != 2:
  25. usage()
  26. sys.exit(1)
  27. import re
  28. import numpy as np
  29. import matplotlib.pyplot as plt
  30. from matplotlib.gridspec import GridSpec
  31. import os
  32. def convert_rec_file(filename):
  33. lines = []
  34. item = dict()
  35. with open(filename, "r") as f:
  36. for l in f.readlines():
  37. if l == "\n":
  38. lines.append(item)
  39. item = dict()
  40. else:
  41. ls = l.split(":")
  42. key = ls[0].lower()
  43. value = ls[1].strip()
  44. if key in item:
  45. print("Warning: duplicated key '" + key + "'")
  46. else:
  47. if re.match('^\d+$', value) != None:
  48. item[key] = int(value)
  49. elif re.match("^\d+\.\d+$", value) != None:
  50. item[key] = float(value)
  51. else:
  52. item[key] = value
  53. return lines
  54. working_directory = sys.argv[1]
  55. comms = convert_rec_file(os.path.join(working_directory, "comms.rec"))
  56. tasks = [t for t in convert_rec_file(os.path.join(working_directory, "tasks.rec")) if "control" not in t and "starttime" in t]
  57. def plot_graph(comm_type, match, filename, title, xlabel):
  58. delays = []
  59. workers = dict()
  60. nb = 0
  61. durations = []
  62. min_time = 0.
  63. max_time = 0.
  64. for c in comms:
  65. if c["type"] == comm_type:
  66. t_matched = None
  67. for t in tasks:
  68. if match(t, c):
  69. t_matched = t
  70. break
  71. if t_matched is None:
  72. if comm_type == "recv":
  73. print("No match found")
  74. else:
  75. worker = str(t_matched['mpirank']) + "-" + str(t_matched['workerid'])
  76. if worker not in workers:
  77. workers[worker] = []
  78. eps = t["starttime"] - c["time"]
  79. assert(eps > 0)
  80. durations.append(eps)
  81. workers[worker].append((c["time"], eps))
  82. if min_time == 0 or c["time"] < min_time:
  83. min_time = c["time"]
  84. if max_time == 0 or c["time"] > max_time:
  85. max_time = c["time"]
  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. axs[2].hist(durations, bins=np.logspace(np.log10(1), np.log10(max(durations)), 50), rwidth=0.8)
  104. axs[2].set_xscale("log")
  105. axs[2].set(xlabel=xlabel, ylabel="Number of occurences", title="Histogramm")
  106. fig.set_size_inches(15, 9)
  107. plt.savefig(os.path.join(working_directory, filename), dpi=100)
  108. plt.show()
  109. plot_graph("recv", lambda t, c: (t["mpirank"] == c["dst"] and t["starttime"] >= c["time"] and c["handle"] in t["handles"]), "recv_use.png", "Elapsed time between recv and use (ms)", "Time between data reception and its use by a task")
  110. plot_graph("send", lambda t, c: (t["mpirank"] == c["src"] and t["starttime"] >= c["time"] and c["handle"] in t["handles"]), "send_use.png", "Elapsed time between send and use (ms)", "Time between data sending and its use by a task")