source: Sophya/trunk/SophyaExt/Blitz/blitz/bench.h@ 3123

Last change on this file since 3123 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

File size: 3.7 KB
RevLine 
[221]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.4 1998/03/14 00:04:47 tveldhui
25 * 0.2-alpha-05
26 *
27 * Revision 1.3 1997/07/16 14:51:20 tveldhui
28 * Update: Alpha release 0.2 (Arrays)
29 *
30 * Revision 1.2 1997/01/24 14:30:34 tveldhui
31 * Prior to rewrite of Bench class; in this version, Bench contains
32 * each benchmark implementation.
33 *
34 */
35
36#ifndef BZ_BENCH_H
37#define BZ_BENCH_H
38
39#ifndef BZ_MATRIX_H
40 #include <blitz/matrix.h>
41#endif
42
43#ifndef BZ_TIMER_H
44 #include <blitz/timer.h>
45#endif
46
47#include <math.h>
48
49BZ_NAMESPACE(blitz)
50
51// Forward declaration
52template<class P_parameter = unsigned>
53class BenchmarkImplementation;
54
55
56// Declaration of class Benchmark<T>
57// The template parameter T is the parameter type which is varied in
58// the benchmark. Typically T will be an unsigned, and will represent
59// the length of a vector, size of an array, etc.
60
61template<class P_parameter = unsigned>
62class Benchmark {
63
64public:
65 typedef P_parameter T_parameter;
66
67 Benchmark(unsigned numImplementations);
68
69 ~Benchmark();
70
71 void addImplementation(BenchmarkImplementation<T_parameter>*
72 implementation);
73
74 void run(ostream& log = cout);
75
76 double getMflops(unsigned implementation, unsigned setting) const;
77
78 double getRate(unsigned implementation, unsigned setting) const;
79
80 void saveMatlabGraph(const char* filename) const;
81
82public:
83 // Virtual functions
84
85 virtual const char* description() const
86 { return ""; }
87
88 virtual const char* parameterDescription() const
89 { return "Vector length"; }
90
91 virtual unsigned numParameterSettings() const
92 { return 19; }
93
94 virtual T_parameter getParameterSetting(unsigned i) const
95 { return ::pow(10.0, (i+1)/4.0); }
96
97 virtual long getIterationSetting(unsigned i) const
98 { return 1000000L / getParameterSetting(i); }
99
100private:
101 Benchmark(const Benchmark<P_parameter>&) { }
102 void operator=(const Benchmark<P_parameter>&) { }
103
104 enum { uninitialized, initialized, running, done } state_;
105
106 unsigned numImplementations_;
107 unsigned numStoredImplementations_;
108
109 BenchmarkImplementation<T_parameter>** implementations_;
110
111 Matrix<double,RowMajor> rates_; // Iterations per second array
112 Matrix<double,RowMajor> Mflops_;
113};
114
115template<class P_parameter>
116class BenchmarkImplementation {
117
118public:
119 typedef P_parameter T_parameter;
120
121 virtual void initialize(P_parameter parameter) { }
122
123 virtual void done() { }
124
125 virtual const char* implementationName() const
126 { return ""; }
127
128 virtual void run(long iterations) = 0;
129
130 virtual void runOverhead(long iterations)
131 {
132 for (long i=0; i < iterations; ++i)
133 {
134 }
135 };
136
137 virtual void tickle() { }
138
139 virtual long flopsPerIteration() const
140 { return 0; }
141};
142
143BZ_NAMESPACE_END
144
145#include <blitz/bench.cc>
146
147#endif // BZ_BENCH_H
Note: See TracBrowser for help on using the repository browser.