source: Sophya/trunk/Poubelle/DPC:FitsIOServer/Blitz/blitz/bench.h@ 1036

Last change on this file since 1036 was 658, checked in by ansari, 26 years ago

no message

File size: 3.8 KB
Line 
1/***************************************************************************
2 * blitz/bench.h Benchmark classes
3 *
4 * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * Suggestions: blitz-suggest@cybervision.com
17 * Bugs: blitz-bugs@cybervision.com
18 *
19 * For more information, please see the Blitz++ Home Page:
20 * http://seurat.uwaterloo.ca/blitz/
21 *
22 ***************************************************************************
23 * $Log: not supported by cvs2svn $
24 * Revision 1.1.1.1 1999/04/09 17:58:58 ansari
25 * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
26 *
27 * Revision 1.4 1998/03/14 00:04:47 tveldhui
28 * 0.2-alpha-05
29 *
30 * Revision 1.3 1997/07/16 14:51:20 tveldhui
31 * Update: Alpha release 0.2 (Arrays)
32 *
33 * Revision 1.2 1997/01/24 14:30:34 tveldhui
34 * Prior to rewrite of Bench class; in this version, Bench contains
35 * each benchmark implementation.
36 *
37 */
38
39#ifndef BZ_BENCH_H
40#define BZ_BENCH_H
41
42#ifndef BZ_MATRIX_H
43 #include <blitz/matrix.h>
44#endif
45
46#ifndef BZ_TIMER_H
47 #include <blitz/timer.h>
48#endif
49
50#include <math.h>
51
52BZ_NAMESPACE(blitz)
53
54// Forward declaration
55template<class P_parameter = unsigned>
56class BenchmarkImplementation;
57
58
59// Declaration of class Benchmark<T>
60// The template parameter T is the parameter type which is varied in
61// the benchmark. Typically T will be an unsigned, and will represent
62// the length of a vector, size of an array, etc.
63
64template<class P_parameter = unsigned>
65class Benchmark {
66
67public:
68 typedef P_parameter T_parameter;
69
70 Benchmark(unsigned numImplementations);
71
72 ~Benchmark();
73
74 void addImplementation(BenchmarkImplementation<T_parameter>*
75 implementation);
76
77 void run(ostream& log = cout);
78
79 double getMflops(unsigned implementation, unsigned setting) const;
80
81 double getRate(unsigned implementation, unsigned setting) const;
82
83 void saveMatlabGraph(const char* filename) const;
84
85public:
86 // Virtual functions
87
88 virtual const char* description() const
89 { return ""; }
90
91 virtual const char* parameterDescription() const
92 { return "Vector length"; }
93
94 virtual unsigned numParameterSettings() const
95 { return 19; }
96
97 virtual T_parameter getParameterSetting(unsigned i) const
98 { return ::pow(10.0, (i+1)/4.0); }
99
100 virtual long getIterationSetting(unsigned i) const
101 { return 1000000L / getParameterSetting(i); }
102
103private:
104 Benchmark(const Benchmark<P_parameter>&) { }
105 void operator=(const Benchmark<P_parameter>&) { }
106
107 enum { uninitialized, initialized, running, done } state_;
108
109 unsigned numImplementations_;
110 unsigned numStoredImplementations_;
111
112 BenchmarkImplementation<T_parameter>** implementations_;
113
114 Matrix<double,RowMajor> rates_; // Iterations per second array
115 Matrix<double,RowMajor> Mflops_;
116};
117
118template<class P_parameter>
119class BenchmarkImplementation {
120
121public:
122 typedef P_parameter T_parameter;
123
124 virtual void initialize(P_parameter parameter) { }
125
126 virtual void done() { }
127
128 virtual const char* implementationName() const
129 { return ""; }
130
131 virtual void run(long iterations) = 0;
132
133 virtual void runOverhead(long iterations)
134 {
135 for (long i=0; i < iterations; ++i)
136 {
137 }
138 };
139
140 virtual void tickle() { }
141
142 virtual long flopsPerIteration() const
143 { return 0; }
144};
145
146BZ_NAMESPACE_END
147
148#include <blitz/bench.cc>
149
150#endif // BZ_BENCH_H
Note: See TracBrowser for help on using the repository browser.