* [gentoo-commits] proj/auto-numerical-bench:master commit in: numbench/, numbench/modules/
@ 2012-08-10 18:15 Andrea Arteaga
0 siblings, 0 replies; 2+ messages in thread
From: Andrea Arteaga @ 2012-08-10 18:15 UTC (permalink / raw
To: gentoo-commits
commit: 341e7af63620ecd909ac04d7dec846a1d6c63914
Author: Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
AuthorDate: Sat Aug 11 06:11:11 2012 +0000
Commit: Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
CommitDate: Sat Aug 11 06:11:11 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=341e7af6
Code for loading module placed in package module. Removed useless
functions in main.
---
numbench/main.py | 63 +++++++++++++++--------------------------
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)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-commits] proj/auto-numerical-bench:master commit in: numbench/, numbench/modules/
@ 2012-08-11 14:32 Andrea Arteaga
0 siblings, 0 replies; 2+ messages in thread
From: Andrea Arteaga @ 2012-08-11 14:32 UTC (permalink / raw
To: gentoo-commits
commit: 490f1e0cb69e5faf2055be71f18584b99e624c76
Author: Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
AuthorDate: Sat Aug 11 16:32:12 2012 +0000
Commit: Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
CommitDate: Sat Aug 11 16:32:12 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=490f1e0c
Insert static modules list and check is requested module exists.
---
numbench/main.py | 15 ++++++---------
numbench/modules/__init__.py | 16 ++++++++++++++--
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/numbench/main.py b/numbench/main.py
index a7f752b..0e98b41 100644
--- a/numbench/main.py
+++ b/numbench/main.py
@@ -57,15 +57,6 @@ def print_help():
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"
@@ -108,6 +99,12 @@ parser = Parser(cfg.inputfile)
cfg.modulename = parser.getModuleName()
cfg.moduleargs = parser.getModuleArguments()
+# Check whether the given module exists
+if not cfg.modulename in modules.getAllModulesNames():
+ print "Error: module " + cfg.modulename + " does not exist.\n\n"
+ print_help()
+ exit(2)
+
# Set-up directories
cfg.setDirs()
diff --git a/numbench/modules/__init__.py b/numbench/modules/__init__.py
index fdd704e..9696252 100644
--- a/numbench/modules/__init__.py
+++ b/numbench/modules/__init__.py
@@ -18,12 +18,25 @@
import os
from os.path import basename, dirname, realpath
+# List here the "stable" modules in a static and ordered list
+modnames = [
+ 'blas',
+ 'cblas',
+ 'lapack',
+ 'lapacke',
+ 'scalapack',
+ 'fftw'
+]
+
class ModuleNotFoundException(RuntimeError):
pass
def getModulesNames():
+ return modnames
+
+def getAllModulesNames():
files = os.listdir(dirname(realpath(__file__)))
me = basename(__file__)
modnames = []
@@ -32,7 +45,6 @@ def getModulesNames():
modnames.append(f[:-3])
return modnames
-
def loadModule(modname, args=None):
if not modname in getModulesNames():
raise ModuleNotFoundException("module " + modname + " not found")
@@ -42,5 +54,5 @@ def loadModule(modname, args=None):
args = args if type(args) == type('') else ' '.join(args)
# Load the module
- tmp = __import__(modname, fromlist=["Module"])
+ tmp = __import__('numbench.modules.' + modname, fromlist=["Module"])
return tmp.Module(args)
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-08-11 14:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-11 14:32 [gentoo-commits] proj/auto-numerical-bench:master commit in: numbench/, numbench/modules/ Andrea Arteaga
-- strict thread matches above, loose matches on Subject: below --
2012-08-10 18:15 Andrea Arteaga
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox