#!/usr/bin/python # # xpp.py # # Determines the performance profiles. # # Copyright (c) 2006 Marco Colombo # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # See http://www.gnu.org/licenses/gpl.txt for a copy of the license. # import sys, string, re, fileinput taustp = 0.05 maxtau = 5.0 # # main # def main(argv = None): global maxtau # change argv if we are not running from the interactive prompt if argv is None: argv = sys.argv # check if we have the correct number of arguments if len(argv) < 3 or len(argv) > 4: print "Usage: xpp.py [maxtau]" return 1 # take the parameters from the command line ncols = int(argv[2]) try: maxtau = float(argv[3]) except: pass # remove the arguments that fileinput should not see del sys.argv[2:] # compute and print the performance profiles perfProfiles(ncols) # # perfRatios: compute the performance ratios # def perfRatios(ncols): # global list of performance ratios pr = [] try: # go through the input file for line in fileinput.input(): prob = [] # skip empty lines if re.match("^\s*$", line): continue # split the output line = string.split(line) # convert each number to floats line = map(float, line[1:]) # find the minimum numerical argument in the line minimum = min(line) # performance ratios for this problem for i in range(ncols): prob.append(line[i] / minimum) # append to the global list pr.append(prob) except IOError: print "Could not open file '" + fileinput.filename() + "'." raise return pr # # perfProfiles: compute the performance profiles # def perfProfiles(ncols): try: # compute the performance ratios pr = perfRatios(ncols) except IOError: return 1 tau = 1.0 nprobs = len(pr) while (tau < maxtau + 0.001): # print the current tau print "%5.3f " % tau, for col in range(ncols): nn = 0 # number of problems solved within tau times of the best for prob in range(nprobs): if (pr[prob][col] <= tau): nn += 1 # print the proportions for this problem print " %5.3f" % (float(nn)/nprobs), # increase tau tau += taustp # go to a new line print if __name__ == "__main__": sys.exit(main())