Skip to content
Snippets Groups Projects
Commit f05d9856 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Add a time range and automatically handle all ranks

This is so that we can compare ranks directly as they all use the same relative times
parent e275cf4d
No related branches found
No related tags found
2 merge requests!136Master,!70Include parallel sort tasks in task dump and add support for MPI dumps
...@@ -28,17 +28,19 @@ import pylab as pl ...@@ -28,17 +28,19 @@ import pylab as pl
import numpy as np import numpy as np
import sys import sys
# CPU ticks per second.
CPU_CLOCK = 2.7e9
# Handle command-line. # Handle command-line.
if len( sys.argv ) != 4: if len( sys.argv ) != 3 and len( sys.argv ) != 4:
print "Usage: ", sys.argv[0], "input.dat rank output.png" print "Usage: ", sys.argv[0], "input.dat png-output-prefix [time-range-ms]"
sys.exit(1) sys.exit(1)
infile = sys.argv[1] infile = sys.argv[1]
rank = int(sys.argv[2]) outbase = sys.argv[2]
outpng = sys.argv[3] delta_t = 0
if len( sys.argv ) == 4:
# CPU ticks per second. delta_t = int(sys.argv[3]) * CPU_CLOCK / 1000
CPU_CLOCK = 2.7e9
params = {"axes.labelsize": 10, params = {"axes.labelsize": 10,
"axes.titlesize": 10, "axes.titlesize": 10,
...@@ -59,9 +61,9 @@ params = {"axes.labelsize": 10, ...@@ -59,9 +61,9 @@ params = {"axes.labelsize": 10,
pl.rcParams.update(params) pl.rcParams.update(params)
# Tasks and subtypes. Indexed as in tasks.h. # Tasks and subtypes. Indexed as in tasks.h.
types = ["none", "sort", "self", "pair", "sub", "ghost", "kick1", "kick2", tasktypes = ["none", "sort", "self", "pair", "sub", "ghost", "kick1", "kick2",
"send", "recv", "grav_pp", "grav_mm", "grav_up", "grav_down", "send", "recv", "grav_pp", "grav_mm", "grav_up", "grav_down",
"psort", "split_cell", "rewait", "count"] "psort", "split_cell", "rewait", "count"]
taskcolours = {"none": "black", taskcolours = {"none": "black",
"sort": "lightblue", "sort": "lightblue",
...@@ -84,108 +86,118 @@ taskcolours = {"none": "black", ...@@ -84,108 +86,118 @@ taskcolours = {"none": "black",
subtypes = ["none", "density", "force", "grav", "count"] subtypes = ["none", "density", "force", "grav", "count"]
subtypecolours = {"none": "black", subcolours = {"none": "black",
"density": "red", "density": "red",
"force": "blue", "force": "blue",
"grav": "indigo", "grav": "indigo",
"count": "purple"} "count": "purple"}
# Read input. # Read input.
data = pl.loadtxt( infile ) data = pl.loadtxt( infile )
nranks = int(max(data[:,0])) + 1 nranks = int(max(data[:,0])) + 1
print "Number of ranks:", nranks print "Number of ranks:", nranks
if rank < 0 or rank >= nranks:
print "Cannot read rank: ", rank, ", out of range"
sys.exit(1)
print "Processing rank:", rank
nthread = int(max(data[:,1])) + 1 nthread = int(max(data[:,1])) + 1
print "Number of threads:", nthread print "Number of threads:", nthread
tasks = {} # Avoid start and end times of zero.
tasks[-1] = []
for i in range(nthread):
tasks[i] = []
# Pick data for our rank, and avoid start and end times of zero.
sdata = data[data[:,5] != 0] sdata = data[data[:,5] != 0]
sdata = sdata[sdata[:,6] != 0] sdata = sdata[sdata[:,6] != 0]
sdata = sdata[sdata[:,0] == rank]
# Each rank can have different clock (compute node), but we want to use the
start_t = min(sdata[:,5]) # same delta times range for comparisons, so we suck it up and take the hit of
end_t = max(sdata[:,6]) # precalculating this, unless the user knows better.
sdata[:,5] -= start_t if delta_t == 0:
sdata[:,6] -= start_t for rank in range(nranks):
data = sdata[sdata[:,0] == rank]
#np.savetxt("dump.txt", sdata, fmt="%d") dt = max(data[:,6]) - min(data[:,5])
if dt > delta_t:
num_lines = pl.size(sdata) / 10 delta_t = dt
for line in range(num_lines):
thread = int(sdata[line,1]) # Once more doing the real gather and plots this time.
tasks[thread].append({}) for rank in range(nranks):
tasks[thread][-1]["type"] = types[int(sdata[line,2])] data = sdata[sdata[:,0] == rank]
tasks[thread][-1]["subtype"] = subtypes[int(sdata[line,3])]
tic = int(sdata[line,5]) / CPU_CLOCK * 1000 start_t = min(data[:,5])
toc = int(sdata[line,6]) / CPU_CLOCK * 1000 data[:,5] -= start_t
tasks[thread][-1]["tic"] = tic data[:,6] -= start_t
tasks[thread][-1]["toc"] = toc
tasks[thread][-1]["t"] = (toc + tic)/ 2 tasks = {}
tasks[-1] = []
print "Collection done..." for i in range(nthread):
tasks[i] = []
combtasks = {}
combtasks[-1] = [] num_lines = pl.size(data) / 10
for i in range(nthread): for line in range(num_lines):
combtasks[i] = [] thread = int(data[line,1])
tasks[thread].append({})
for thread in range(nthread): tasks[thread][-1]["type"] = tasktypes[int(data[line,2])]
tasks[thread] = sorted(tasks[thread], key=lambda l: l["t"]) tasks[thread][-1]["subtype"] = subtypes[int(data[line,3])]
lasttype = "" tic = int(data[line,5]) / CPU_CLOCK * 1000
types = [] toc = int(data[line,6]) / CPU_CLOCK * 1000
for task in tasks[thread]: tasks[thread][-1]["tic"] = tic
if task["type"] not in types: tasks[thread][-1]["toc"] = toc
types.append(task["type"]) tasks[thread][-1]["t"] = (toc + tic)/ 2
if lasttype == "" or not lasttype == task["type"]:
combtasks[thread].append({}) print "Collection done..."
combtasks[thread][-1]["type"] = task["type"]
combtasks[thread][-1]["subtype"] = task["subtype"] combtasks = {}
combtasks[thread][-1]["tic"] = task["tic"] combtasks[-1] = []
combtasks[thread][-1]["toc"] = task["toc"] for i in range(nthread):
if task["type"] == "self" or task["type"] == "pair" or task["type"] == "sub": combtasks[i] = []
combtasks[thread][-1]["colour"] = subtypecolours[task["subtype"]]
for thread in range(nthread):
tasks[thread] = sorted(tasks[thread], key=lambda l: l["t"])
lasttype = ""
types = []
for task in tasks[thread]:
if task["type"] not in types:
types.append(task["type"])
if lasttype == "" or not lasttype == task["type"]:
combtasks[thread].append({})
combtasks[thread][-1]["type"] = task["type"]
combtasks[thread][-1]["subtype"] = task["subtype"]
combtasks[thread][-1]["tic"] = task["tic"]
combtasks[thread][-1]["toc"] = task["toc"]
if task["type"] == "self" or task["type"] == "pair" or task["type"] == "sub":
combtasks[thread][-1]["colour"] = subcolours[task["subtype"]]
else:
combtasks[thread][-1]["colour"] = taskcolours[task["type"]]
lasttype = task["type"]
else:
combtasks[thread][-1]["toc"] = task["toc"]
print "Combination done..."
typesseen = []
pl.figure()
for i in range(nthread):
for task in combtasks[i]:
pl.fill_between([task["tic"], task["toc"]], i+0.05, i+0.95,
facecolor=task["colour"], linewidths=0)
if task["subtype"] != "none":
qtask = task["type"] + "/" + task["subtype"]
else: else:
combtasks[thread][-1]["colour"] = taskcolours[task["type"]] qtask = task["type"]
lasttype = task["type"] if qtask not in typesseen:
else: pl.plot([], [], color=task["colour"], label=qtask)
combtasks[thread][-1]["toc"] = task["toc"] typesseen.append(qtask)
print "Combination done..." # Legend and room for it.
nrow = len(typesseen) / 5
typesseen = [] if len(typesseen) * 5 < nrow:
for i in range(nthread): nrow = nrow + 1
for task in combtasks[i]: pl.fill_between([0, 0], nthread+0.5, nthread + nrow + 0.5, facecolor="white")
pl.fill_between([task["tic"], task["toc"]], i+0.05, i+0.95, pl.legend(loc=1, shadow=True, mode="expand", ncol=5)
facecolor=task["colour"], linewidths=0)
if task["subtype"] != "none": pl.xlabel("Wall clock time [ms]")
qtask = task["type"] + "/" + task["subtype"] pl.xlim(0, delta_t * 1.03 * 1000 / CPU_CLOCK)
else: pl.ylabel("Thread ID for MPI Rank " + str(rank) )
qtask = task["type"] pl.yticks(pl.array(range(nthread)) + 0.5, pl.array(range(nthread)))
if qtask not in typesseen:
pl.plot([], [], color=task["colour"], label=qtask) pl.show()
typesseen.append(qtask) outpng = outbase + str(rank) + ".png"
pl.savefig(outpng)
# Legend and room for it. print "Graphics done, output written to", outpng
pl.fill_between([0, 0], nthread, nthread+len(typesseen)/3, facecolor="white")
pl.legend(loc=1, shadow=True, mode="expand", ncol=3)
pl.xlabel("Wall clock time [ms]")
pl.xlim(0, (end_t - start_t)*1.03 * 1000 / CPU_CLOCK)
pl.ylabel("Thread ID for MPI Rank " + str(rank) )
pl.yticks(pl.array(range(nthread)) + 0.5, pl.array(range(nthread)))
pl.show()
pl.savefig(outpng)
print "Graphics done, output written to", outpng
sys.exit(0) sys.exit(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment