starpu_mpi_comm_matrix.py.in 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. import re
  19. import os
  20. PROGNAME=sys.argv[0]
  21. def usage():
  22. print("Offline tool to draw a communication matrix")
  23. print("")
  24. print("Usage: %s <output_execution>" % PROGNAME)
  25. print("")
  26. print("Options:")
  27. print(" -h, --help display this help and exit")
  28. print(" -v, --version output version information and exit")
  29. print(" -png produce plots in png format (default is pdf)")
  30. print("")
  31. print("Report bugs to <@PACKAGE_BUGREPORT@>")
  32. sys.exit(1)
  33. if len(sys.argv) >= 2:
  34. if sys.argv[1] == '-v' or sys.argv[1] == '--version':
  35. print("%s (@PACKAGE_NAME@) @PACKAGE_VERSION@" % PROGNAME)
  36. sys.exit(0)
  37. if sys.argv[1] == '-h' or sys.argv[1] == '--help':
  38. usage()
  39. if (len(sys.argv) == 1):
  40. usage()
  41. if len(sys.argv) >= 2 and sys.argv[1] == '-png':
  42. outputformat='png'
  43. outputext='png'
  44. outputfile=sys.argv[2]
  45. else:
  46. outputformat='pdf color'
  47. outputext='pdf'
  48. outputfile=sys.argv[1]
  49. # find the number of nodes
  50. nodes=0
  51. file = open(outputfile, "r")
  52. for line in file.readlines():
  53. match = re.search('\TOTAL', line)
  54. if match:
  55. (node,stuff)=line.split(sep="[")[2].split("]")
  56. if (int(node) > nodes):
  57. nodes=int(node)
  58. file.close()
  59. nodes=nodes+1
  60. # extract volume of comm and bandwidth between all pair of nodes
  61. volumes = [[0 for x in range(nodes)] for y in range(nodes)]
  62. bandwidth = [[0 for x in range(nodes)] for y in range(nodes)]
  63. file = open(outputfile, "r")
  64. for line in file.readlines():
  65. match = re.search('\[starpu_comm_stats]', line)
  66. if match:
  67. match = re.search('TOTAL', line)
  68. if not match:
  69. (head,volB,B,volMB,MB,bwB,B,bwMB,MB) = line.split()
  70. (src,dst)=head.split(sep="[")[2].split(sep="]")[0].split(sep=":")
  71. volumes[int(src)][int(dst)] = float(volB)
  72. bandwidth[int(src)][int(dst)] = float(bwB)
  73. file.close()
  74. def writeData(filename, nodes, data):
  75. ofile=open(filename, "w")
  76. for dst in range(nodes):
  77. for src in range(nodes):
  78. ofile.write("%f "% data[src][dst])
  79. ofile.write("\n")
  80. ofile.close()
  81. def generateGnuplotScript(filename, datafilename, outputfile, nodes):
  82. ofile=open(filename, "w")
  83. srctics=""
  84. dsttics=""
  85. for node in range(nodes-1):
  86. srctics += "\"src%d\" %d, " % (node, node)
  87. dsttics += "\"dst%d\" %d, " % (node, node)
  88. ofile.write("set term %s\n" % outputformat)
  89. ofile.write("set output \"%s.%s\"\n" % (outputfile, outputext))
  90. ofile.write("set view map scale 1\nset style data lines\n")
  91. ofile.write("set palette model RGB defined ( 0 'white', 100 'black' )\n")
  92. ofile.write("set xtics (%s\"src%d\" %d)\n" % (srctics, nodes-1, nodes-1))
  93. ofile.write("set ytics (%s\"dst%d\" %d)\n" % (dsttics, nodes-1, nodes-1))
  94. ofile.write("plot '%s' matrix with image\n" % datafilename)
  95. ofile.close()
  96. # generate gnuplot volume data and script file
  97. writeData(outputfile+"_volume.data", nodes, volumes)
  98. generateGnuplotScript(outputfile+"_volume.gp", outputfile+"_volume.data", outputfile+"_volume_heatmap", nodes)
  99. os.system("gnuplot " + outputfile+"_volume.gp")
  100. # generate gnuplot bandwidth data and script file
  101. writeData(outputfile+"_bw.data", nodes, bandwidth)
  102. generateGnuplotScript(outputfile+"_bw.gp", outputfile+"_bw.data", outputfile+"_bw_heatmap", nodes)
  103. os.system("gnuplot " + outputfile+"_bw.gp")