starpu_mpi_comm_matrix.py.in 4.0 KB

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