VMS/2__runs_and_data

changeset 7:adac95f01c6f

move scripts for counter treatment here
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Tue, 20 Dec 2011 10:07:28 +0100
parents 0fb514d583de
children 6652d0313656
files scripts/ucc_and_loop_graph_treatment/parse_ucc.py scripts/ucc_and_loop_graph_treatment/run_graph.py
diffstat 2 files changed, 105 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/ucc_and_loop_graph_treatment/parse_ucc.py	Tue Dec 20 10:07:28 2011 +0100
     1.3 @@ -0,0 +1,30 @@
     1.4 +#!/usr/bin/python
     1.5 +
     1.6 +import sys
     1.7 +import csv
     1.8 +
     1.9 +
    1.10 +def read_from_file(filename):
    1.11 +	d = {}
    1.12 +	reader = csv.reader(filename)
    1.13 +	for row in reader:
    1.14 +		try:
    1.15 +			if row[0] == "unit":
    1.16 +				if not d.has_key("unit"): # not key in d:
    1.17 +					d["unit"] = []
    1.18 +				d["unit"].append( ( int(row[1]),int(row[2]) ) )
    1.19 +			if row[0] == "ctlDep":
    1.20 +				if not d.has_key("ctlDep"):
    1.21 +					d["ctlDep"] = []
    1.22 +				d["ctlDep"].append( ( (int(row[1]),int(row[2])) , (int(row[3]),int(row[4])) ) )
    1.23 +			if row[0] == "commDep":
    1.24 +				if not d.has_key("commDep"):
    1.25 +					d["commDep"] = []
    1.26 +				d["commDep"].append(( (int(row[1]),int(row[2])) , (int(row[3]),int(row[4])) ))
    1.27 +			if row[0] == "NtoN":
    1.28 +				if not d.has_key("NtoN"):
    1.29 +					d["NtoN"] = []
    1.30 +				d["NtoN"].append((row[2:2+row[1]],row[2+row[1]:2+2*row[1]]))
    1.31 +		except Exception:
    1.32 +			continue
    1.33 +	return d
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/scripts/ucc_and_loop_graph_treatment/run_graph.py	Tue Dec 20 10:07:28 2011 +0100
     2.3 @@ -0,0 +1,75 @@
     2.4 +#!/usr/bin/python
     2.5 +
     2.6 +import sys
     2.7 +import pygraph
     2.8 +
     2.9 +if len(sys.argv)<3 :
    2.10 +	print "Usage:",sys.argv[0],"dependencyfile.dot counterfile.csv"
    2.11 +	sys.exit()
    2.12 +
    2.13 +try:
    2.14 +	dependencyfile = open(sys.argv[1])
    2.15 +	dependencystring = dependencyfile.read()
    2.16 +except IOError as (errno, strerror):
    2.17 +	print "Error {0}: {1}".format(errno, strerror)
    2.18 +	sys.exit()
    2.19 +	
    2.20 +try:
    2.21 +	counterfile = open(sys.argv[2])
    2.22 +except IOError as (errno, strerror):
    2.23 +	print (("Error {0}: {1}".format)(errno, strerror))
    2.24 +	sys.exit()	
    2.25 +	
    2.26 +from pygraph.readwrite.dot import read,write
    2.27 +
    2.28 +dependencygraph = read(dependencystring)
    2.29 +
    2.30 +import csv
    2.31 +
    2.32 +counterreader = (csv.reader)(counterfile)
    2.33 +
    2.34 +
    2.35 +
    2.36 +for row in counterreader:
    2.37 +	dependencygraph.add_node_attribute('VP_{0}_{1}'.format(row[0],row[1]),('suspend_point',row[2]))
    2.38 +	dependencygraph.add_node_attribute('VP_{0}_{1}'.format(row[0],row[1]),('schedule_check_cycles',int(row[4])-int(row[19])))
    2.39 +	dependencygraph.add_node_attribute('VP_{0}_{1}'.format(row[0],row[1]),('sync_cycles',int(row[25])-int(row[24])))
    2.40 +	dependencygraph.add_node_attribute('VP_{0}_{1}'.format(row[0],row[1]),('assign_cycles',int(row[10])-int(row[7])))
    2.41 +	dependencygraph.add_node_attribute('VP_{0}_{1}'.format(row[0],row[1]),('work_comm_cycles',int(row[16])-int(row[13])))
    2.42 +	dependencygraph.add_node_attribute('VP_{0}_{1}'.format(row[0],row[1]),('status_cycles',int(row[22])-int(row[16])))
    2.43 +
    2.44 +	
    2.45 +def path_length(path):
    2.46 +	length = 0
    2.47 +	for node in path:
    2.48 +		attrd = dict(dependencygraph.node_attributes(node))
    2.49 +		length += attrd['schedule_check_cycles']
    2.50 +		length += attrd['sync_cycles']
    2.51 +		length += attrd['assign_cycles']
    2.52 +		length += attrd['work_comm_cycles']
    2.53 +		length += attrd['status_cycles']
    2.54 +	return length
    2.55 +	
    2.56 +	
    2.57 +def find_critical_path(graph, start, end, path=[]):
    2.58 +	path = path + [end]
    2.59 +	if start == end:
    2.60 +		return path
    2.61 +	if not graph.has_node(end):
    2.62 +		return None
    2.63 +	longest = None
    2.64 +	for node in graph.incidents(end):
    2.65 +		if node not in path:
    2.66 +			newpath = find_critical_path(graph, start, node, path)
    2.67 +			if newpath:
    2.68 +				if not longest or path_length(newpath) > path_length(longest):
    2.69 +					longest = newpath
    2.70 +	return longest
    2.71 +
    2.72 +cr= find_critical_path(dependencygraph, 'VP_2_0', 'VP_2_97')
    2.73 +
    2.74 +for node in cr:
    2.75 +	dependencygraph.add_node_attribute(node,('color','red'))
    2.76 +	dependencygraph.add_node_attribute(node,('style','bold'))
    2.77 +
    2.78 +print write(dependencygraph)