starpu_mpi_comm_matrix.py.in 4.0 KB

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