/[escript]/trunk/escript/py_src/benchmark.py
ViewVC logotype

Diff of /trunk/escript/py_src/benchmark.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2549 by jfenwick, Mon Jul 20 06:43:47 2009 UTC revision 2625 by jfenwick, Fri Aug 21 06:30:25 2009 UTC
# Line 25  filter# $Id:$ Line 25  filter# $Id:$
25  A simple framework to run benchmarks under OpenMP and to summarize the results  A simple framework to run benchmarks under OpenMP and to summarize the results
26  in tables for instance in HTML  in tables for instance in HTML
27    
28  @var __author__: name of author  :var __author__: name of author
29  @var __license__: licence agreement  :var __license__: licence agreement
30  @var __copyright__: copyrights  :var __copyright__: copyrights
31  @var __url__: url entry point on documentation  :var __url__: url entry point on documentation
32  @var __version__: version  :var __version__: version
33  @var __date__: date of the version  :var __date__: date of the version
34  """  """
35    
36  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
# Line 40  from esys.escript import setNumberOfThre Line 40  from esys.escript import setNumberOfThre
40    
41  class BenchmarkSuite(object):  class BenchmarkSuite(object):
42     """     """
43     Framework to run a bunch of L{Benchmark}s using the object and creating a     Framework to run a bunch of `Benchmark` s using the object and creating a
44     table of statistics.     table of statistics.
45    
46     @cvar MAX_LEVEL: maximum number of level in headers for output     :cvar MAX_LEVEL: maximum number of level in headers for output
47     """     """
48     MAX_LEVEL=5     MAX_LEVEL=5
49     def __init__(self,name=None):     def __init__(self,name=None):
50         """         """
51         Sets up a suite of benchmarks.         Sets up a suite of benchmarks.
52    
53         @param name: name of the benchmark suite. If no name is given the class         :param name: name of the benchmark suite. If no name is given the class
54                      name is used.                      name is used.
55         @type name: C{str}         :type name: ``str``
56         """         """
57         super(BenchmarkSuite,self).__init__()         super(BenchmarkSuite,self).__init__()
58         self.__benchmarks=[]         self.__benchmarks=[]
# Line 66  class BenchmarkSuite(object): Line 66  class BenchmarkSuite(object):
66         """         """
67         Returns the name of the benchmark suite.         Returns the name of the benchmark suite.
68    
69         @return: the name         :return: the name
70         @rtype: C{str}         :rtype: ``str``
71         """         """
72         return self.__name         return self.__name
73    
74     def addBenchmark(self,benchmark):     def addBenchmark(self,benchmark):
75         """         """
76         Adds a new L{Benchmark} to the suite.         Adds a new `Benchmark` to the suite.
77    
78         @param benchmark: the benchmark to add         :param benchmark: the benchmark to add
79         @type benchmark: L{Benchmark}         :type benchmark: `Benchmark`
80         """         """
81         self.__benchmarks.append(benchmark)         self.__benchmarks.append(benchmark)
82    
# Line 84  class BenchmarkSuite(object): Line 84  class BenchmarkSuite(object):
84         """         """
85         Returns the number of benchmarks in the suite.         Returns the number of benchmarks in the suite.
86    
87         @return: number of benchmarks         :return: number of benchmarks
88         @rtype: C{int}         :rtype: ``int``
89         """         """
90         return len(self.__benchmarks)         return len(self.__benchmarks)
91    
# Line 93  class BenchmarkSuite(object): Line 93  class BenchmarkSuite(object):
93         """         """
94         Returns the i-th benchmark in the suite through self[i].         Returns the i-th benchmark in the suite through self[i].
95    
96         @param i: index of the requested benchmark         :param i: index of the requested benchmark
97         @type i: C{int}         :type i: ``int``
98         @return: i-th benchmark         :return: i-th benchmark
99         @rtype: L{Benchmark}         :rtype: `Benchmark`
100    
101         """         """
102         return self.__benchmarks[i]         return self.__benchmarks[i]
# Line 105  class BenchmarkSuite(object): Line 105  class BenchmarkSuite(object):
105         """         """
106         Runs all benchmarks.         Runs all benchmarks.
107    
108         @param scale: defines the number of (OpenMP) threads to be used. If         :param scale: defines the number of (OpenMP) threads to be used. If
109                       C{scale} is a scalar all benchmarks are run with C{scale}                       ``scale`` is a scalar all benchmarks are run with ``scale``
110                       number of threads. If C{scale} is a C{list}, the p-th                       number of threads. If ``scale`` is a ``list``, the p-th
111                       problem in each of the benchmarks in the suite is run with                       problem in each of the benchmarks in the suite is run with
112                       C{scale[p]} threads. If C{scale[p]}<1 the p-th problem is                       ``scale[p]`` threads. If ``scale[p]`` <1 the p-th problem is
113                       omitted.                       omitted.
114         @type scale: C{int} or C{list} of C{int}s         :type scale: ``int`` or ``list`` of ``int``
115         """         """
116         self.__scale=scale         self.__scale=scale
117         for i in range(len(self)): self[i].run(scale=scale)         for i in range(len(self)): self[i].run(scale=scale)
# Line 120  class BenchmarkSuite(object): Line 120  class BenchmarkSuite(object):
120         """         """
121         Returns the results of the last benchmark run in HTML format.         Returns the results of the last benchmark run in HTML format.
122    
123         @param filter: filter to be applied to the results         :param filter: filter to be applied to the results
124         @type filter: L{BenchmarkFilter}         :type filter: `BenchmarkFilter`
125         @param level: level used in header <H?> tags         :param level: level used in header <H?> tags
126         @type level: C{int}         :type level: ``int``
127         @return: HTML document         :return: HTML document
128         @rtype: C{str}         :rtype: ``str``
129         """         """
130         out=""         out=""
131         if level==1: out+="<HTML><HEAD><TITLE>Benchmark: %s</TITLE></HEAD><BODY>\n"%str(self)         if level==1: out+="<HTML><HEAD><TITLE>Benchmark: %s</TITLE></HEAD><BODY>\n"%str(self)
# Line 153  class BenchmarkSuite(object): Line 153  class BenchmarkSuite(object):
153    
154  class Benchmark(object):  class Benchmark(object):
155     """     """
156     Runs a bunch of similar L{BenchmarkProblem}s with a bunch of L{Options}.     Runs a bunch of similar `BenchmarkProblem` s with a bunch of `Options`.
157     """     """
158     def __init__(self,name=None,description=None):     def __init__(self,name=None,description=None):
159         """         """
160         Sets up a benchmark.         Sets up a benchmark.
161    
162         @param name: name of the benchmark. If no name is given the class name         :param name: name of the benchmark. If no name is given the class name
163                      is used.                      is used.
164         @type name: C{str}         :type name: ``str``
165         @param description: description of the benchmark         :param description: description of the benchmark
166         @type description: C{str} or C{None}         :type description: ``str`` or ``None``
167         """         """
168         super(Benchmark,self).__init__()         super(Benchmark,self).__init__()
169         self.__options=[]         self.__options=[]
# Line 180  class Benchmark(object): Line 180  class Benchmark(object):
180         """         """
181         Returns the name of the benchmark suite.         Returns the name of the benchmark suite.
182    
183         @return: the name         :return: the name
184         @rtype: C{str}         :rtype: ``str``
185         """         """
186         return self.__name         return self.__name
187    
# Line 189  class Benchmark(object): Line 189  class Benchmark(object):
189         """         """
190         Adds a problem to the benchmark.         Adds a problem to the benchmark.
191    
192         @param problem: the problem to be added         :param problem: the problem to be added
193         @type problem: L{BenchmarkProblem}         :type problem: `BenchmarkProblem`
194         """         """
195         self.__problems.append(problem)         self.__problems.append(problem)
196    
# Line 198  class Benchmark(object): Line 198  class Benchmark(object):
198         """         """
199         Adds options to the benchmark.         Adds options to the benchmark.
200    
201         @param options: the options to be added to the benchmark. If         :param options: the options to be added to the benchmark. If
202                         options==None the options are left unchanged.                         options==None the options are left unchanged.
203         @type options: L{Options}         :type options: `Options`
204         """         """
205         if options!=None: self.__options.append(options)         if options!=None: self.__options.append(options)
206    
# Line 208  class Benchmark(object): Line 208  class Benchmark(object):
208         """         """
209         Runs all problems with all options.         Runs all problems with all options.
210    
211         @param scale: defines the number of (OpenMP) threads to be used. If         :param scale: defines the number of (OpenMP) threads to be used. If
212                       C{scale} is a scalar all benchmarks are run with C{scale}                       ``scale`` is a scalar all benchmarks are run with ``scale``
213                       number of threads. If C{scale} is a C{list}, the p-th                       number of threads. If ``scale`` is a ``list`` , the p-th
214                       problem in each of the benchmarks in the suite is run with                       problem in each of the benchmarks in the suite is run with
215                       C{scale[p]} threads. If C{scale[p]}<1 the p-th problem is                       ``scale[p]`` threads. If ``scale[p]`` <1 the p-th problem is
216                       omitted.                       omitted.
217         @type scale: C{int} or C{list} of C{int}s         :type scale: ``int`` or ``list`` of ``int`` s
218         """         """
219         if isinstance(scale,list):         if isinstance(scale,list):
220             c_max=min(len(scale),len(self.__problems))             c_max=min(len(scale),len(self.__problems))
# Line 248  class Benchmark(object): Line 248  class Benchmark(object):
248         """         """
249         Returns the results of the last benchmark run in HTML format.         Returns the results of the last benchmark run in HTML format.
250    
251         @param filter: filter to be applied to the results         :param filter: filter to be applied to the results
252         @type filter: L{BenchmarkFilter}         :type filter: `BenchmarkFilter`
253         @param level: level used in header <H?> tags         :param level: level used in header <H?> tags
254         @type level: C{int}         :type level: ``int``
255         @return: HTML document         :return: HTML document
256         @rtype: C{str}         :rtype: ``str``
257         """         """
258         out=""         out=""
259         if level==1: out+="<HTML><HEAD><TITLE>Benchmark: %s</TITLE></HEAD><BODY>\n"%str(self)         if level==1: out+="<HTML><HEAD><TITLE>Benchmark: %s</TITLE></HEAD><BODY>\n"%str(self)
# Line 316  class BenchmarkProblem(object): Line 316  class BenchmarkProblem(object):
316         """         """
317         Sets up a benchmark problem.         Sets up a benchmark problem.
318    
319         @param name: name of the problem. If no name is given the class name         :param name: name of the problem. If no name is given the class name
320                      is used.                      is used.
321         @type name: C{str}         :type name: ``str``
322         """         """
323         super(BenchmarkProblem,self).__init__()         super(BenchmarkProblem,self).__init__()
324         if name==None:         if name==None:
# Line 330  class BenchmarkProblem(object): Line 330  class BenchmarkProblem(object):
330         """         """
331         Returns the name of the benchmark suite.         Returns the name of the benchmark suite.
332    
333         @return: the name         :return: the name
334         @rtype: C{str}         :rtype: ``str``
335         """         """
336         return self.__name         return self.__name
337    
# Line 339  class BenchmarkProblem(object): Line 339  class BenchmarkProblem(object):
339         """         """
340         Runs the problem and returns a list of run characteristics.         Runs the problem and returns a list of run characteristics.
341    
342         @param options: the options that are used for the run. Note that the         :param options: the options that are used for the run. Note that the
343                         number of OpenMP threads is controlled by the                         number of OpenMP threads is controlled by the
344                         L{Benchmark} the problem is run in.                         `Benchmark` the problem is run in.
345         @type options: L{Options}         :type options: `Options`
346         @return: run characteristics         :return: run characteristics
347         @rtype: any type that can be read by the L{BenchmarkFilter} applied         :rtype: any type that can be read by the `BenchmarkFilter` applied
348                 to it                 to it
349         @note: this function has to be overwritten by a particular problem         :note: this function has to be overwritten by a particular problem
350         """         """
351         raise NotImplementedError         raise NotImplementedError
352         return []         return []
# Line 364  class BenchmarkFilter(object): Line 364  class BenchmarkFilter(object):
364    
365     def getResultNames(self):     def getResultNames(self):
366         """         """
367         Returns the names of the results produced when C{run()} is called.         Returns the names of the results produced when ``run()`` is called.
368    
369         @return: the list of the names to be used when the results of         :return: the list of the names to be used when the results of
370                  the C{run()} call are printed                  the ``run()`` call are printed
371         @rtype: C{list} of C{str}         :rtype: ``list`` of ``str``
372         @note: this function has to overwritten by a particular problem         :note: this function has to overwritten by a particular problem
373         """         """
374         raise NotImplementedError         raise NotImplementedError
375         return []         return []
# Line 378  class BenchmarkFilter(object): Line 378  class BenchmarkFilter(object):
378         """         """
379         Filters out results returned as characteristics of a problem run.         Filters out results returned as characteristics of a problem run.
380    
381         @param result: values to be filtered         :param result: values to be filtered
382         @type result: any type that is produced by the L{BenchmarkProblem}         :type result: any type that is produced by the `BenchmarkProblem`
383                       it is applied to                       it is applied to
384         @return: a list of strings selected from result         :return: a list of strings selected from result
385         @rtype: C{list} of C{str}         :rtype: ``list`` of ``str``
386         @note: this function has to be overwritten by a particular problem         :note: this function has to be overwritten by a particular problem
387         """         """
388         raise NotImplementedError         raise NotImplementedError
389         return []         return []
# Line 391  class BenchmarkFilter(object): Line 391  class BenchmarkFilter(object):
391    
392  class Options(object):  class Options(object):
393      """      """
394      Defines a set of options to be used to run a L{BenchmarkProblem}.      Defines a set of options to be used to run a `BenchmarkProblem`.
395      """      """
396      def __init__(self,name=None):      def __init__(self,name=None):
397         """         """
398         Sets up the options.         Sets up the options.
399    
400         @param name: name of the option. If no name is given the class name         :param name: name of the option. If no name is given the class name
401                      is used.                      is used.
402         @type name: C{str}         :type name: ``str``
403         """         """
404         super(Options,self).__init__()         super(Options,self).__init__()
405         if name==None:         if name==None:
# Line 411  class Options(object): Line 411  class Options(object):
411         """         """
412         Returns the name of this options object.         Returns the name of this options object.
413    
414         @return: the name         :return: the name
415         @rtype: C{str}         :rtype: ``str``
416         """         """
417         return self.__name         return self.__name
418    

Legend:
Removed from v.2549  
changed lines
  Added in v.2625

  ViewVC Help
Powered by ViewVC 1.1.26