starpu_mpi_comm_matrix.py.in 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/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("")
  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. outputfile=sys.argv[1]
  42. # find the number of nodes
  43. nodes=0
  44. file = open(outputfile, "r")
  45. for line in file.readlines():
  46. match = re.search('\TOTAL', line)
  47. if match:
  48. (node,stuff)=line.split(sep="[")[2].split("]")
  49. if (int(node) > nodes):
  50. nodes=int(node)
  51. file.close()
  52. nodes=nodes+1
  53. # extract volume of comm and bandwidth between all pair of nodes
  54. volumes = [[0 for x in range(nodes)] for y in range(nodes)]
  55. bandwidth = [[0 for x in range(nodes)] for y in range(nodes)]
  56. file = open(outputfile, "r")
  57. for line in file.readlines():
  58. match = re.search('\[starpu_comm_stats]', line)
  59. if match:
  60. match = re.search('TOTAL', line)
  61. if not match:
  62. (head,volB,B,volMB,MB,bwB,B,bwMB,MB) = line.split()
  63. (src,dst)=head.split(sep="[")[2].split(sep="]")[0].split(sep=":")
  64. volumes[int(src)][int(dst)] = float(volB)
  65. bandwidth[int(src)][int(dst)] = float(bwB)
  66. file.close()
  67. def writeData(filename, nodes, data):
  68. ofile=open(filename, "w")
  69. for src in range(nodes):
  70. for dst in range(nodes):
  71. ofile.write("%f "% data[src][dst])
  72. ofile.write("\n")
  73. ofile.close()
  74. def generateGnuplotScript(filename, datafilename, outputfile, nodes):
  75. ofile=open(filename, "w")
  76. srctics=""
  77. dsttics=""
  78. for node in range(nodes-1):
  79. srctics += "\"src%d\" %d, " % (node, node)
  80. dsttics += "\"dst%d\" %d, " % (node, node)
  81. ofile.write("set term pdf color\n")
  82. ofile.write("set output \"%s\"\n" % outputfile)
  83. ofile.write("set view map scale 1\nset style data lines\nset palette rgbformulae 22,13,-31\n")
  84. ofile.write("set xtics (%s\"src%d\" %d)\n" % (srctics, nodes-1, nodes-1))
  85. ofile.write("set ytics (%s\"dst%d\" %d)\n" % (dsttics, nodes-1, nodes-1))
  86. ofile.write("plot '%s' matrix with image\n" % datafilename)
  87. ofile.close()
  88. # generate gnuplot volume data and script file
  89. writeData(outputfile+"_volume.data", nodes, volumes)
  90. generateGnuplotScript(outputfile+"_volume.gp", outputfile+"_volume.data", outputfile+"_volume_heatmap.pdf", nodes)
  91. os.system("gnuplot " + outputfile+"_volume.gp")
  92. # generate gnuplot bandwidth data and script file
  93. writeData(outputfile+"_bw.data", nodes, bandwidth)
  94. generateGnuplotScript(outputfile+"_bw.gp", outputfile+"_bw.data", outputfile+"_bw_heatmap.pdf", nodes)
  95. os.system("gnuplot " + outputfile+"_bw.gp")