diff options
author | Andrea Arteaga <andyspiros@gmail.com> | 2012-08-11 08:11:11 +0200 |
---|---|---|
committer | Andrea Arteaga <andyspiros@gmail.com> | 2012-08-11 08:11:11 +0200 |
commit | 341e7af63620ecd909ac04d7dec846a1d6c63914 (patch) | |
tree | f074410acbae54eacbfd01fba9a6a9c4c8ea402c /numbench | |
parent | Updated openblas sample. (diff) | |
download | auto-numerical-bench-341e7af63620ecd909ac04d7dec846a1d6c63914.tar.gz auto-numerical-bench-341e7af63620ecd909ac04d7dec846a1d6c63914.tar.bz2 auto-numerical-bench-341e7af63620ecd909ac04d7dec846a1d6c63914.zip |
Code for loading module placed in package module. Removed useless
functions in main.
Diffstat (limited to 'numbench')
-rw-r--r-- | numbench/main.py | 63 | ||||
-rw-r--r-- | numbench/modules/__init__.py | 46 |
2 files changed, 69 insertions, 40 deletions
diff --git a/numbench/main.py b/numbench/main.py index 3b22701..a7f752b 100644 --- a/numbench/main.py +++ b/numbench/main.py @@ -20,28 +20,23 @@ import os, sys, signal import benchchildren +import modules # Set the signal handler def close(*args): benchchildren.terminate() - Print._level = 0 - Print() - Print(80 * '-') - Print("INTERRUPT TRIGGERED") - Print("Exiting") + print + print 80 * '-' + print "INTERRUPT TRIGGERED" + print "Exiting" exit(0) signal.signal(signal.SIGINT, close) -def print_usage(): - print "Usage: numbench [blas|cblas|lapack|scalapack|fftw|metis|" \ - "blas_accuracy|lapack_accuracy] file args" - - def print_help(): print "Usage: numbench conffile [options]" print " numbench [ -h | --help ]" - print " numbench module [ -h | --help ]" +# print " numbench module [ -h | --help ]" print print "Options:" print " [ -h | --help ] - Displays an help message." @@ -55,32 +50,27 @@ def print_help(): print " resulting images. Available are png, svg, eps, ps, pdf." print " Default is svg." print + + modnames = modules.getModulesNames() + print "Modules:" - print " blas - Test BLAS implementations" - print " cblas - Test CBLAS implementations" - print " lapack - Test LAPACK implementations" - print " lapacke - Test LAPACK implementations" - print " scalapack - Test the ScaLAPACK library" - #print " blas_accuracy - Test BLAS implementations for accuracy" - #print " lapack_accuracy - Test LAPACK implementations for accuracy" - print " fftw - Test the FFTW library" - #print " metis - Test the METIS tools" + for m in modnames: + M = modules.loadModule(m) + print " %s - %s" % (m, M.descr) +# print " blas - Test BLAS implementations" +# print " cblas - Test CBLAS implementations" +# print " lapack - Test LAPACK implementations" +# print " lapacke - Test LAPACK implementations" +# print " scalapack - Test the ScaLAPACK library" +# #print " blas_accuracy - Test BLAS implementations for accuracy" +# #print " lapack_accuracy - Test LAPACK implementations for accuracy" +# print " fftw - Test the FFTW library" +# #print " metis - Test the METIS tools" print print "More information about a module is available through the command:" print " numbench module --help" -def loadModule(modulename): - tmp = __import__('numbench.modules.' + modulename, fromlist=['Module']) -# try: -# tmp = __import__('numbench.modules.'+modulename, fromlist = ['Module']) -# except ImportError as e: -# sys.stderr.write('Module ' + modulename + ' not found') -# exit(1) - - return tmp - - ## PRINT HELP IF NEEDED @@ -89,13 +79,6 @@ if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'): print_help() exit(0) -# If requested, print the module help -# TODO: print module's help -#if sys.argv[2] in ('-h', '--help'): -# tmp = loadModule(sys.argv[1]) -# tmp.Module.printHelp() -# exit(0) - ## BEGIN THE TRUE SCRIPT @@ -117,7 +100,7 @@ cfg.parseArguments() # Start configuration parser if not os.path.exists(cfg.inputfile): sys.stderr.write("File not found: " + cfg.inputfile) - print_usage() + print_help() exit(1) parser = Parser(cfg.inputfile) @@ -135,7 +118,7 @@ cfg.tests = parser.getTestCases() Print = benchprint.initializePrint() # Import the module -cfg.module = loadModule(cfg.modulename).Module(cfg.moduleargs) +cfg.module = modules.loadModule(cfg.modulename, cfg.moduleargs) ## Write summary diff --git a/numbench/modules/__init__.py b/numbench/modules/__init__.py index e69de29..fdd704e 100644 --- a/numbench/modules/__init__.py +++ b/numbench/modules/__init__.py @@ -0,0 +1,46 @@ +#===================================================== +# Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com> +#===================================================== +# +# 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +import os +from os.path import basename, dirname, realpath + + +class ModuleNotFoundException(RuntimeError): + pass + + +def getModulesNames(): + files = os.listdir(dirname(realpath(__file__))) + me = basename(__file__) + modnames = [] + for f in files: + if f[-3:] == '.py' and f != me: + modnames.append(f[:-3]) + return modnames + + +def loadModule(modname, args=None): + if not modname in getModulesNames(): + raise ModuleNotFoundException("module " + modname + " not found") + + # Get the arguments string + args = "" if args is None else args + args = args if type(args) == type('') else ' '.join(args) + + # Load the module + tmp = __import__(modname, fromlist=["Module"]) + return tmp.Module(args) |