~ubuntu-branches/ubuntu/utopic/blitz++/utopic

« back to all changes in this revision

Viewing changes to benchmarks/floop14.cpp

  • Committer: Package Import Robot
  • Author(s): Christophe Trophime
  • Date: 2012-07-06 09:15:30 UTC
  • mfrom: (11.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120706091530-vzrb8zf0vpbf8tp9
Tags: 1:0.10-1
* New upstream release
  Closes: #679407
* debian/rules:
  - update for new release
  - add override_dh_auto_test target
  - regenerate configure and Makefile.am
* debian/control:
  - add libtool, automake to BuildDepends
* debian/libblitz-doc.install
  - modify path for html files
* remove uneeded patches
* add examples.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// floop14 generated by makeloops.py Thu Jun 30 16:44:56 2011
 
3
 
 
4
#include <blitz/vector2.h>
 
5
#include <blitz/array.h>
 
6
#include <random/uniform.h>
 
7
#include <blitz/benchext.h>
 
8
 
 
9
#ifdef BZ_HAVE_VALARRAY
 
10
 #define BENCHMARK_VALARRAY
 
11
#endif
 
12
 
 
13
#ifdef BENCHMARK_VALARRAY
 
14
#include <valarray>
 
15
#endif
 
16
 
 
17
BZ_NAMESPACE(blitz)
 
18
extern void sink();
 
19
BZ_NAMESPACE_END
 
20
 
 
21
BZ_USING_NAMESPACE(blitz)
 
22
BZ_USING_NAMESPACE(std)
 
23
 
 
24
#if defined(BZ_FORTRAN_SYMBOLS_WITH_TRAILING_UNDERSCORES)
 
25
 #define floop14_f77 floop14_f77_
 
26
 #define floop14_f77overhead floop14_f77overhead_
 
27
 #define floop14_f90 floop14_f90_
 
28
 #define floop14_f90overhead floop14_f90overhead_
 
29
#elif defined(BZ_FORTRAN_SYMBOLS_WITH_DOUBLE_TRAILING_UNDERSCORES)
 
30
 #define floop14_f77 floop14_f77__
 
31
 #define floop14_f77overhead floop14_f77overhead__
 
32
 #define floop14_f90 floop14_f90__
 
33
 #define floop14_f90overhead floop14_f90overhead__
 
34
#elif defined(BZ_FORTRAN_SYMBOLS_CAPS)
 
35
 #define floop14_f77 FLOOP14_F77
 
36
 #define floop14_f77overhead FLOOP14_F77OVERHEAD
 
37
 #define floop14_f90 FLOOP14_F90
 
38
 #define floop14_f90overhead FLOOP14_F90OVERHEAD
 
39
#endif
 
40
 
 
41
extern "C" {
 
42
  void floop14_f77(const int& N, float* y, float* x, float* a, float* b);
 
43
  void floop14_f77overhead(const int& N, float* y, float* x, float* a, float* b);
 
44
  void floop14_f90(const int& N, float* y, float* x, float* a, float* b);
 
45
  void floop14_f90overhead(const int& N, float* y, float* x, float* a, float* b);
 
46
 
 
47
}
 
48
 
 
49
void VectorVersion(BenchmarkExt<int>& bench);
 
50
void ArrayVersion(BenchmarkExt<int>& bench);
 
51
void ArrayVersion_unaligned(BenchmarkExt<int>& bench);
 
52
void ArrayVersion_misaligned(BenchmarkExt<int>& bench);
 
53
void ArrayVersion_index(BenchmarkExt<int>& bench);
 
54
void doTinyVectorVersion(BenchmarkExt<int>& bench);
 
55
void F77Version(BenchmarkExt<int>& bench);
 
56
#ifdef FORTRAN_90
 
57
void F90Version(BenchmarkExt<int>& bench);
 
58
#endif
 
59
#ifdef BENCHMARK_VALARRAY
 
60
void ValarrayVersion(BenchmarkExt<int>& bench);
 
61
#endif
 
62
 
 
63
const int numSizes = 80;
 
64
const bool runvector=false; // no point as long as Vector is Array<1>
 
65
 
 
66
int main()
 
67
{
 
68
    int numBenchmarks = 5;
 
69
    if (runvector) numBenchmarks++;
 
70
#ifdef BENCHMARK_VALARRAY
 
71
    numBenchmarks++;
 
72
#endif
 
73
#ifdef FORTRAN_90
 
74
    numBenchmarks++;
 
75
#endif
 
76
 
 
77
    BenchmarkExt<int> bench("floop14: $x = $a+$b; $y = $a-$b", numBenchmarks);
 
78
 
 
79
    bench.setNumParameters(numSizes);
 
80
 
 
81
    Array<int,1> parameters(numSizes);
 
82
    Array<long,1> iters(numSizes);
 
83
    Array<double,1> flops(numSizes);
 
84
 
 
85
    parameters=pow(pow(2.,0.25),tensor::i)+tensor::i;
 
86
    flops = 2 * parameters;
 
87
    iters = 100000000L / flops;
 
88
    iters = where(iters<2, 2, iters);
 
89
    cout << iters << endl;
 
90
    
 
91
    bench.setParameterVector(parameters);
 
92
    bench.setIterations(iters);
 
93
    bench.setOpsPerIteration(flops);
 
94
    bench.setDependentVariable("flops");
 
95
    bench.beginBenchmarking();
 
96
 
 
97
 
 
98
 
 
99
    ArrayVersion(bench);
 
100
    ArrayVersion_unaligned(bench);
 
101
    ArrayVersion_misaligned(bench);
 
102
    ArrayVersion_index(bench);
 
103
    //doTinyVectorVersion(bench);
 
104
    F77Version(bench);
 
105
#ifdef FORTRAN_90
 
106
    F90Version(bench);
 
107
#endif
 
108
#ifdef BENCHMARK_VALARRAY
 
109
    ValarrayVersion(bench);
 
110
#endif
 
111
 
 
112
    if(runvector)
 
113
      VectorVersion(bench);
 
114
 
 
115
    bench.endBenchmarking();
 
116
 
 
117
    bench.saveMatlabGraph("floop14.m");
 
118
    return 0;
 
119
}
 
120
 
 
121
template<class T>
 
122
void initializeRandomDouble(T* data, int numElements, int stride = 1)
 
123
{
 
124
    ranlib::Uniform<T> rnd;
 
125
 
 
126
    for (int i=0; i < numElements; ++i)
 
127
        data[size_t(i*stride)] = rnd.random();
 
128
}
 
129
 
 
130
template<class T>
 
131
void initializeRandomDouble(valarray<T>& data, int numElements, int stride = 1)
 
132
{
 
133
    ranlib::Uniform<T> rnd;
 
134
 
 
135
    for (int i=0; i < numElements; ++i)
 
136
        data[size_t(i*stride)] = rnd.random();
 
137
}
 
138
 
 
139
void VectorVersion(BenchmarkExt<int>& bench)
 
140
{
 
141
    bench.beginImplementation("Vector<T>");
 
142
 
 
143
    while (!bench.doneImplementationBenchmark())
 
144
    {
 
145
        int N = bench.getParameter();
 
146
        long iters = bench.getIterations();
 
147
 
 
148
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
149
 
 
150
        Vector<float> y(N);
 
151
        initializeRandomDouble(y.data(), N);
 
152
        Vector<float> x(N);
 
153
        initializeRandomDouble(x.data(), N);
 
154
        Vector<float> a(N);
 
155
        initializeRandomDouble(a.data(), N);
 
156
        Vector<float> b(N);
 
157
        initializeRandomDouble(b.data(), N);
 
158
 
 
159
 
 
160
        bench.start();
 
161
        for (long i=0; i < iters; ++i)
 
162
        {
 
163
            x = a+b; y = a-b;
 
164
            sink();
 
165
        }
 
166
        bench.stop();
 
167
 
 
168
        bench.startOverhead();
 
169
        for (long i=0; i < iters; ++i) {
 
170
            sink();
 
171
        }
 
172
 
 
173
        bench.stopOverhead();
 
174
    }
 
175
 
 
176
    bench.endImplementation();
 
177
}
 
178
 
 
179
 
 
180
  void ArrayVersion(BenchmarkExt<int>& bench)
 
181
{
 
182
    bench.beginImplementation("Array<T,1>");
 
183
 
 
184
    while (!bench.doneImplementationBenchmark())
 
185
    {
 
186
        int N = bench.getParameter();
 
187
        long iters = bench.getIterations();
 
188
 
 
189
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
190
 
 
191
        Array<float,1> y(N);
 
192
        initializeRandomDouble(y.dataFirst(), N);
 
193
        Array<float,1> x(N);
 
194
        initializeRandomDouble(x.dataFirst(), N);
 
195
        Array<float,1> a(N);
 
196
        initializeRandomDouble(a.dataFirst(), N);
 
197
        Array<float,1> b(N);
 
198
        initializeRandomDouble(b.dataFirst(), N);
 
199
 
 
200
 
 
201
        bench.start();
 
202
        for (long i=0; i < iters; ++i)
 
203
        {
 
204
            x = a+b; y = a-b;
 
205
            sink();
 
206
        }
 
207
        bench.stop();
 
208
 
 
209
        bench.startOverhead();
 
210
        for (long i=0; i < iters; ++i) {
 
211
            sink();
 
212
        }
 
213
 
 
214
        bench.stopOverhead();
 
215
    }
 
216
 
 
217
    bench.endImplementation();
 
218
}
 
219
 
 
220
 
 
221
  void ArrayVersion_index(BenchmarkExt<int>& bench)
 
222
{
 
223
    bench.beginImplementation("Array<T,1> (indexexpr.)");
 
224
 
 
225
    while (!bench.doneImplementationBenchmark())
 
226
    {
 
227
        int N = bench.getParameter();
 
228
        long iters = bench.getIterations();
 
229
 
 
230
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
231
 
 
232
        Array<float,1> y(N);
 
233
        initializeRandomDouble(y.dataFirst(), N);
 
234
        Array<float,1> x(N);
 
235
        initializeRandomDouble(x.dataFirst(), N);
 
236
        Array<float,1> a(N);
 
237
        initializeRandomDouble(a.dataFirst(), N);
 
238
        Array<float,1> b(N);
 
239
        initializeRandomDouble(b.dataFirst(), N);
 
240
 
 
241
 
 
242
        bench.start();
 
243
        for (long i=0; i < iters; ++i)
 
244
        {
 
245
            x = a(tensor::i)+b(tensor::i); y = a(tensor::i)-b(tensor::i);;
 
246
            sink();
 
247
        }
 
248
        bench.stop();
 
249
 
 
250
        bench.startOverhead();
 
251
        for (long i=0; i < iters; ++i) {
 
252
            sink();
 
253
        }
 
254
 
 
255
        bench.stopOverhead();
 
256
    }
 
257
 
 
258
    bench.endImplementation();
 
259
}
 
260
 
 
261
  void ArrayVersion_unaligned(BenchmarkExt<int>& bench)
 
262
{
 
263
    bench.beginImplementation("Array<T,1> (unal.)");
 
264
 
 
265
    while (!bench.doneImplementationBenchmark())
 
266
    {
 
267
        int N = bench.getParameter();
 
268
        long iters = bench.getIterations();
 
269
 
 
270
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
271
 
 
272
 
 
273
    Array<float,1> yfill(N+1);
 
274
    Array<float,1> y(yfill(Range(1,N)));
 
275
    initializeRandomDouble(y.dataFirst(), N);
 
276
 
 
277
    Array<float,1> xfill(N+1);
 
278
    Array<float,1> x(xfill(Range(1,N)));
 
279
    initializeRandomDouble(x.dataFirst(), N);
 
280
 
 
281
    Array<float,1> afill(N+1);
 
282
    Array<float,1> a(afill(Range(1,N)));
 
283
    initializeRandomDouble(a.dataFirst(), N);
 
284
 
 
285
    Array<float,1> bfill(N+1);
 
286
    Array<float,1> b(bfill(Range(1,N)));
 
287
    initializeRandomDouble(b.dataFirst(), N);
 
288
 
 
289
 
 
290
        bench.start();
 
291
        for (long i=0; i < iters; ++i)
 
292
        {
 
293
            x = a+b; y = a-b;
 
294
            sink();
 
295
        }
 
296
        bench.stop();
 
297
 
 
298
        bench.startOverhead();
 
299
        for (long i=0; i < iters; ++i) {
 
300
            sink();
 
301
        }
 
302
 
 
303
        bench.stopOverhead();
 
304
    }
 
305
 
 
306
    bench.endImplementation();
 
307
}
 
308
 
 
309
  void ArrayVersion_misaligned(BenchmarkExt<int>& bench)
 
310
{
 
311
    bench.beginImplementation("Array<T,1> (misal.)");
 
312
 
 
313
    while (!bench.doneImplementationBenchmark())
 
314
    {
 
315
        int N = bench.getParameter();
 
316
        long iters = bench.getIterations();
 
317
 
 
318
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
319
 
 
320
 
 
321
    Array<float,1> yfill(N+4);
 
322
    Array<float,1> y(yfill(Range(0,N+0-1)));
 
323
    initializeRandomDouble(y.dataFirst(), N);
 
324
 
 
325
    Array<float,1> xfill(N+4);
 
326
    Array<float,1> x(xfill(Range(1,N+1-1)));
 
327
    initializeRandomDouble(x.dataFirst(), N);
 
328
 
 
329
    Array<float,1> afill(N+4);
 
330
    Array<float,1> a(afill(Range(2,N+2-1)));
 
331
    initializeRandomDouble(a.dataFirst(), N);
 
332
 
 
333
    Array<float,1> bfill(N+4);
 
334
    Array<float,1> b(bfill(Range(3,N+3-1)));
 
335
    initializeRandomDouble(b.dataFirst(), N);
 
336
 
 
337
 
 
338
        bench.start();
 
339
        for (long i=0; i < iters; ++i)
 
340
        {
 
341
            x = a+b; y = a-b;
 
342
            sink();
 
343
        }
 
344
        bench.stop();
 
345
 
 
346
        bench.startOverhead();
 
347
        for (long i=0; i < iters; ++i) {
 
348
            sink();
 
349
        }
 
350
 
 
351
        bench.stopOverhead();
 
352
    }
 
353
 
 
354
    bench.endImplementation();
 
355
}
 
356
 
 
357
#ifdef BENCHMARK_VALARRAY
 
358
void ValarrayVersion(BenchmarkExt<int>& bench)
 
359
{
 
360
    bench.beginImplementation("valarray<T>");
 
361
 
 
362
    while (!bench.doneImplementationBenchmark())
 
363
    {
 
364
        int N = bench.getParameter();
 
365
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
366
 
 
367
        long iters = bench.getIterations();
 
368
 
 
369
        valarray<float> y(N);
 
370
        initializeRandomDouble(y, N);
 
371
        valarray<float> x(N);
 
372
        initializeRandomDouble(x, N);
 
373
        valarray<float> a(N);
 
374
        initializeRandomDouble(a, N);
 
375
        valarray<float> b(N);
 
376
        initializeRandomDouble(b, N);
 
377
 
 
378
 
 
379
        bench.start();
 
380
        for (long i=0; i < iters; ++i)
 
381
        {
 
382
            x = a+b; y = a-b;
 
383
            sink();
 
384
        }
 
385
        bench.stop();
 
386
 
 
387
        bench.startOverhead();
 
388
        for (long i=0; i < iters; ++i) {
 
389
          sink();
 
390
        }
 
391
        bench.stopOverhead();
 
392
    }
 
393
 
 
394
    bench.endImplementation();
 
395
}
 
396
#endif
 
397
 
 
398
void F77Version(BenchmarkExt<int>& bench)
 
399
{
 
400
    bench.beginImplementation("Fortran 77");
 
401
 
 
402
    while (!bench.doneImplementationBenchmark())
 
403
    {
 
404
        int N = bench.getParameter();
 
405
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
406
 
 
407
        int iters = bench.getIterations();
 
408
 
 
409
        float* y = new float[N];
 
410
        initializeRandomDouble(y, N);
 
411
        float* x = new float[N];
 
412
        initializeRandomDouble(x, N);
 
413
        float* a = new float[N];
 
414
        initializeRandomDouble(a, N);
 
415
        float* b = new float[N];
 
416
        initializeRandomDouble(b, N);
 
417
        
 
418
 
 
419
        bench.start();
 
420
        for (int iter=0; iter < iters; ++iter)
 
421
            floop14_f77(N, y, x, a, b);
 
422
        bench.stop();
 
423
 
 
424
        bench.startOverhead();
 
425
        for (int iter=0; iter < iters; ++iter)
 
426
            floop14_f77overhead(N, y, x, a, b);
 
427
 
 
428
        bench.stopOverhead();
 
429
 
 
430
        delete [] y;
 
431
        delete [] x;
 
432
        delete [] a;
 
433
        delete [] b;
 
434
 
 
435
    }
 
436
 
 
437
    bench.endImplementation();
 
438
}
 
439
 
 
440
#ifdef FORTRAN_90
 
441
void F90Version(BenchmarkExt<int>& bench)
 
442
{
 
443
    bench.beginImplementation("Fortran 90");
 
444
 
 
445
    while (!bench.doneImplementationBenchmark())
 
446
    {
 
447
        int N = bench.getParameter();
 
448
        cout << bench.currentImplementation() << ": N = " << N << endl;
 
449
 
 
450
        int iters = bench.getIterations();
 
451
 
 
452
        float* y = new float[N];
 
453
        initializeRandomDouble(y, N);
 
454
        float* x = new float[N];
 
455
        initializeRandomDouble(x, N);
 
456
        float* a = new float[N];
 
457
        initializeRandomDouble(a, N);
 
458
        float* b = new float[N];
 
459
        initializeRandomDouble(b, N);
 
460
 
 
461
 
 
462
        bench.start();
 
463
        for (int iter=0; iter < iters; ++iter)
 
464
            floop14_f90(N, y, x, a, b);
 
465
        bench.stop();
 
466
 
 
467
        bench.startOverhead();
 
468
        for (int iter=0; iter < iters; ++iter)
 
469
            floop14_f90overhead(N, y, x, a, b);
 
470
 
 
471
        bench.stopOverhead();
 
472
        delete [] y;
 
473
        delete [] x;
 
474
        delete [] a;
 
475
        delete [] b;
 
476
 
 
477
    }
 
478
 
 
479
    bench.endImplementation();
 
480
}
 
481
#endif
 
482