diff scripts/overhead_data_generation.py @ 4:ef2b8d975a99

exec time vs task size data generation and calculation splited in two scripts
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 12 Dec 2011 20:26:28 +0100
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/overhead_data_generation.py	Mon Dec 12 20:26:28 2011 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +#! /usr/bin/env python
     1.5 +# -*- coding: utf-8 -*-
     1.6 +
     1.7 +import sys
     1.8 +from re import match, search
     1.9 +from pprint import pformat
    1.10 +from datetime import datetime
    1.11 +from subprocess import call,Popen,PIPE
    1.12 +
    1.13 +"""
    1.14 +This script generates a graph that represents the overhead
    1.15 +
    1.16 +involved in synchronisation operations
    1.17 +This script generates results for 5 runs per threads and iteration in
    1.18 +TOTAL_THREADS_TABLE and ITER_PER_TASK_TABLE
    1.19 +"""
    1.20 +
    1.21 +usage="""
    1.22 +	This runs the exec time vs task size in three levels of loop nest.  The outer most iterates through 
    1.23 +	a selection of numbers-of-thread.  For each of those, the next lever iterates over a number of work-loops-per-task
    1.24 +	values.  The innermost repeats several times and chooses the best.
    1.25 +	Finally, it generates an output file for each value of number-of-threads that give the number of all runs.
    1.26 +	It is expected that the output directory's path is meaningful, such as machine-name, date, and so on
    1.27 +	Usage:
    1.28 +		%s [executable binary] [path to output dir]
    1.29 +""" % sys.argv[0]
    1.30 +
    1.31 +NUM_CORES = 4 #Number of Cores the code was compiled for
    1.32 +ITERS_PER_TASK_TABLE = [2, 5, 10, 20, 40, 80, 160, 320, 640] #Number of iterations of inner loop
    1.33 +TASKS_PER_THREAD = 30000 #Number of interations of outer loop 
    1.34 +TOTAL_THREADS_TABLE = [8, 32, 128, 512]
    1.35 +
    1.36 +def getNumber(line):
    1.37 +	match_obj = search("(\d+\.?\d*)", line)
    1.38 +	if match_obj != None:
    1.39 +		return match_obj.groups()[0]
    1.40 +	else:
    1.41 +		raise ValueError
    1.42 +
    1.43 +if len(sys.argv) != 3:
    1.44 +	print usage
    1.45 +	sys.exit(0)
    1.46 +    
    1.47 +cmd=sys.argv[1]
    1.48 +try:
    1.49 +	f = open(cmd)
    1.50 +except IOError:
    1.51 +	print "Please provide a valid executable."
    1.52 +	f.close()
    1.53 +	sys.exit(1)
    1.54 +finally:
    1.55 +	f.close()
    1.56 +
    1.57 +output_dir_path = sys.argv[2]
    1.58 +
    1.59 +#===================================================================
    1.60 +#  Done with parsing cmd line inputs, start doing the runs 
    1.61 +#
    1.62 +
    1.63 +for totalThreads in TOTAL_THREADS_TABLE:
    1.64 +	print "\nDoing run with %d threads" % totalThreads
    1.65 +	output = "%s/%d_thds__o%d__perfCtrs.meas" % (output_dir_path, totalThreads, TASKS_PER_THREAD)
    1.66 +	print "output file: %s" % output
    1.67 +	threadsPerCore = totalThreads/NUM_CORES
    1.68 +	array_of_results = {}
    1.69 +	for workload_iterations_in_task in ITERS_PER_TASK_TABLE:
    1.70 +		print "Run for %s workload iterations in a task" % workload_iterations_in_task
    1.71 +		results = []
    1.72 +		for run in range(5):
    1.73 +			print "Run %d" % run,
    1.74 +			program_output = Popen("%s -t %d -i %d -o %d" % (cmd,
    1.75 +												totalThreads,
    1.76 +												workload_iterations_in_task,
    1.77 +												TASKS_PER_THREAD),
    1.78 +								stdout=PIPE, stderr=None, shell=True).stdout.read()
    1.79 +			#parse arguments for
    1.80 +			for line in program_output.split("\n"):
    1.81 +				if match("^Sum across threads of work cycles:", line) != None:
    1.82 +					total_workcycles = int(getNumber(line))
    1.83 +				if match("^Total Execution Cycles:", line) != None:
    1.84 +					total_exe_cycles = int(getNumber(line))
    1.85 +				if match("^ExeCycles/WorkCycles Ratio", line) != None:
    1.86 +					exeCycles_workCycles_ratio = float(getNumber(line))
    1.87 +			results.append({"total_workcycles"            : total_workcycles,
    1.88 +						"total_exe_cycles"            : total_exe_cycles,
    1.89 +						"exeCycles_workCycles_ratio" : exeCycles_workCycles_ratio})
    1.90 +			print "ratio %f" % exeCycles_workCycles_ratio
    1.91 +		array_of_results[workload_iterations_in_task] = results
    1.92 +		
    1.93 +	#open file to output data
    1.94 +	try:
    1.95 +		data_output = open(output,"w")
    1.96 +	except IOError:
    1.97 +		print "Cannot open output file %s" % output
    1.98 +		sys.exit(1)
    1.99 +	
   1.100 +	#output relevant data to file
   1.101 +	data_output.write(";\n".join(["# This is a output of the overhead_data_generation.py script, run the overhead_result_calc.py script to get the calculated results",
   1.102 +					  "data_filename = " + pformat(output),
   1.103 +					  "NUM_CORES = " + pformat(NUM_CORES),					  
   1.104 +					  "ITERS_PER_TASK_TABLE = " + pformat(ITERS_PER_TASK_TABLE),
   1.105 +					  "TASKS_PER_THREAD = " + pformat(TASKS_PER_THREAD),
   1.106 +					  "date_of_run = " + pformat(datetime.now()),
   1.107 +					  "threads_per_core = " + pformat(threadsPerCore),
   1.108 +					  "totalThreads = " + pformat(totalThreads),
   1.109 +					  "# array_of_results: hash key is the number of iterations per task(inner iterations)",
   1.110 +					  "array_of_results = " + pformat(array_of_results)]))
   1.111 +	
   1.112 +							
   1.113 +	data_output.close()
   1.114 +