source: XIOS/dev/dev_olga/src/extern/blitz/include/blitz/bench.h @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 3.7 KB
Line 
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/bench.h      Benchmark classes
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8 *
9 * This file is a part of Blitz.
10 *
11 * Blitz is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * Blitz is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Blitz.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Suggestions:          blitz-devel@lists.sourceforge.net
25 * Bugs:                 blitz-support@lists.sourceforge.net   
26 *
27 * For more information, please see the Blitz++ Home Page:
28 *    https://sourceforge.net/projects/blitz/
29 *
30 ***************************************************************************/
31
32#ifndef BZ_BENCH_H
33#define BZ_BENCH_H
34
35#include <blitz/matrix.h>
36#include <blitz/timer.h>
37
38#if defined(BZ_HAVE_STD)
39#include <cmath>
40#else
41#include <math.h>
42#endif
43
44BZ_NAMESPACE(blitz)
45
46// Forward declaration
47template<typename P_parameter = unsigned>
48class BenchmarkImplementation;
49
50
51// Declaration of class Benchmark<T>
52// The template parameter T is the parameter type which is varied in
53// the benchmark.  Typically T will be an unsigned, and will represent
54// the length of a vector, size of an array, etc.
55
56template<typename P_parameter = unsigned>
57class Benchmark {
58
59public:
60    typedef P_parameter T_parameter;
61
62    Benchmark(unsigned numImplementations);
63
64    ~Benchmark();
65
66    void addImplementation(BenchmarkImplementation<T_parameter>* 
67        implementation);
68
69    void run(ostream& log = cout);
70
71    double getMflops(unsigned implementation, unsigned setting) const;
72
73    double getRate(unsigned implementation, unsigned setting) const;
74
75    void saveMatlabGraph(const char* filename) const;
76    void savePylabGraph(const char* filename) const;
77
78public:
79    // Virtual functions
80
81    virtual const char* description() const
82    { return ""; }
83
84    virtual const char* parameterDescription() const
85    { return "Vector length"; }
86
87    virtual unsigned numParameterSettings() const
88    { return 19; }
89
90    virtual T_parameter getParameterSetting(unsigned i) const
91    { return BZ_MATHFN_SCOPE(pow)(10.0, (i+1)/4.0); }
92
93    virtual long getIterationSetting(unsigned i) const
94    { return 1000000L / getParameterSetting(i); }
95
96private:
97    Benchmark(const Benchmark<P_parameter>&) { }
98    void operator=(const Benchmark<P_parameter>&) { }
99
100    enum { uninitialized, initialized, running, done } state_;
101
102    unsigned numImplementations_;
103    unsigned numStoredImplementations_;
104
105    BenchmarkImplementation<T_parameter>** implementations_;
106
107    Matrix<double,RowMajor> rates_;       // Iterations per second array
108    Matrix<double,RowMajor> Mflops_;
109};
110
111template<typename P_parameter>
112class BenchmarkImplementation {
113
114public:
115    typedef P_parameter T_parameter;
116
117    virtual void initialize(P_parameter parameter) { }
118
119    virtual void done() { }
120
121    virtual const char* implementationName() const
122    { return ""; }
123
124    virtual void run(long iterations) = 0;
125
126    virtual void runOverhead(long iterations) 
127    { 
128        for (long i=0; i < iterations; ++i)
129        {
130        }
131    };
132
133    virtual void tickle() { }
134
135    virtual long flopsPerIteration() const
136    { return 0; }
137};
138
139BZ_NAMESPACE_END
140
141#include <blitz/bench.cc> 
142
143#endif // BZ_BENCH_H
Note: See TracBrowser for help on using the repository browser.