This file is indexed.

/usr/include/blitz/benchext.cc is in libblitz0-dev 1:0.10-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
/***************************************************************************
 * blitz/benchext.cc  Methods for Benchmarking class with external control.
 *
 * $Id$
 *
 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
 *
 * This file is a part of Blitz.
 *
 * Blitz is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Blitz is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with Blitz.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Suggestions:          blitz-devel@lists.sourceforge.net
 * Bugs:                 blitz-support@lists.sourceforge.net    
 *
 * For more information, please see the Blitz++ Home Page:
 *    https://sourceforge.net/projects/blitz/
 *
 ****************************************************************************/
#ifndef BZ_BENCHEXT_CC
#define BZ_BENCHEXT_CC

#ifndef BZ_BENCHEXT_H
 #error <blitz/benchext.cc> must be included via <blitz/benchext.h>
#endif

//#include <blitz/vector-et.h>

#ifdef BZ_HAVE_STD
 #include <fstream>
 #include <string>
#else
 #include <fstream.h>
 #include <string.h>
#endif

BZ_NAMESPACE(blitz)

template<typename P_parameter>
BenchmarkExt<P_parameter>::BenchmarkExt(const char* name, 
    int numImplementations)
{
    BZPRECONDITION(numImplementations > 0);

    description_ = name;
    numImplementations_ = numImplementations;

    implementationDescriptions_.resize(numImplementations);
    parameterDescription_ = "Vector length";
    
    // we don't really know this is the default, do we...
    setDependentVariable("flops");

    /*
    // Set up default parameters and iterations
    setNumParameters(19);

    // NEEDS_WORK: once pow(X,Y) is supported, can just say
    // parameters_ = pow(10.0, Range(1,20)/4.0);
    
    for (unsigned i=0; i < numParameters_; ++i)
      parameters_(i) = static_cast<P_parameter>(BZ_MATHFN_SCOPE(pow)(10.0, (i+1)/4.0));

    iterations_ = 5.0e+5 / parameters_;
    flopsPerIteration_ = parameters_;
    */
    // Set up initial state
    state_ = initializing;
    implementationNumber_ = 0;
}

template<typename P_parameter>
BenchmarkExt<P_parameter>::~BenchmarkExt()
{
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::setNumParameters(int numParameters)
{
    //BZPRECONDITION(state_ == initializing);

    numParameters_ = numParameters;

    parameters_.resize(numParameters_);
    iterations_.resize(numParameters_);
    flopsPerIteration_.resize(numParameters_);

    // Set up timer and Mflops array
    times_.resize(numImplementations_, numParameters_);
    instr_.resize(numImplementations_, numParameters_);
    flops_.resize(numImplementations_, numParameters_);
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::setParameterVector(Array<P_parameter,1> parms)
{
    BZPRECONDITION(state_ == initializing);
    BZPRECONDITION(parms.size() == parameters_.size());

    parameters_ = parms;
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::setParameterDescription(const char* string)
{
    parameterDescription_ = string;
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::setIterations(Array<long,1> iters)
{
    BZPRECONDITION(state_ == initializing);

    iterations_ = iters;
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::setOpsPerIteration(Array<double,1> 
    flopsPerIteration)
{
    BZPRECONDITION(flopsPerIteration_.size() == flopsPerIteration.size());

    flopsPerIteration_ = flopsPerIteration;
}

/** Set the dependent variable of the measurements. If the independent
    variable is seconds, we output "G<dvar>/s", if it is cycles, we
    output "<dvar/c". */
template<typename P_parameter>
void BenchmarkExt<P_parameter>::setDependentVariable(const char* dvar)
{
  BZPRECONDITION(Timer::indep_var()!="");

  if(timer_.indep_var()=="s") {
    depvar_ = string("G")+dvar+"/s";
    timerconversion_ = 1./1e9;
  }
  else if(timer_.indep_var()=="c") {
    depvar_ = string(dvar)+"/c";
    timerconversion_ = 1.;
  }
  else {
    depvar_ = std::string(dvar)+"/"+timer_.indep_var();
    timerconversion_ = 1;
    }
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::beginBenchmarking()
{
    BZPRECONDITION(state_ == initializing);
    state_ = benchmarking;
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::beginImplementation(const char* description)
{
    // it would really be better if it worked for as many as we give it
    BZPRECONDITION(implementationNumber_ < numImplementations_);
    BZPRECONDITION(state_ == benchmarking);

    implementationDescriptions_[implementationNumber_] = description;

    state_ = benchmarkingImplementation;
    parameterNumber_ = 0;
}

template<typename P_parameter>
bool BenchmarkExt<P_parameter>::doneImplementationBenchmark() const
{
    BZPRECONDITION(state_ == benchmarkingImplementation);
    return parameterNumber_ == numParameters_;
}

template<typename P_parameter>
const string& BenchmarkExt<P_parameter>::currentImplementation() const
{
    BZPRECONDITION(implementationNumber_ < numImplementations_);
    return implementationDescriptions_[implementationNumber_];
}


template<typename P_parameter>
P_parameter BenchmarkExt<P_parameter>::getParameter() const
{
    BZPRECONDITION(state_ == benchmarkingImplementation);
    BZPRECONDITION(parameterNumber_ < numParameters_);

    return parameters_(parameterNumber_);
}

template<typename P_parameter>
long BenchmarkExt<P_parameter>::getIterations() const
{
    BZPRECONDITION(state_ == benchmarkingImplementation);
    BZPRECONDITION(parameterNumber_ < numParameters_);

    return iterations_(parameterNumber_);
}

template<typename P_parameter>
inline void BenchmarkExt<P_parameter>::start()
{
    BZPRECONDITION(state_ == benchmarkingImplementation);
    BZPRECONDITION(parameterNumber_ < numParameters_);
    state_ = running;
    timer_.start();
}

template<typename P_parameter>
inline void BenchmarkExt<P_parameter>::stop()
{
    timer_.stop();
    BZPRECONDITION(state_ == running);
    state_ = benchmarkingImplementation;

    times_(int(implementationNumber_), int(parameterNumber_)) = timer_.elapsed();
    instr_(int(implementationNumber_), int(parameterNumber_)) = timer_.instr();
    flops_(int(implementationNumber_), int(parameterNumber_)) = timer_.flops();
    ++parameterNumber_;
}

template<typename P_parameter>
inline void BenchmarkExt<P_parameter>::startOverhead()
{
    BZPRECONDITION(state_ == benchmarkingImplementation);
    BZPRECONDITION(parameterNumber_ > 0);
    BZPRECONDITION(parameterNumber_ <= numParameters_);
    state_ = runningOverhead;
    timer_.start();
}

template<typename P_parameter>
inline void BenchmarkExt<P_parameter>::stopOverhead()
{
    BZPRECONDITION(state_ == runningOverhead);
    timer_.stop();

    cout << "\ttimer overhead: " <<
      1.0*timer_.elapsed()/times_(int(implementationNumber_), int(parameterNumber_-1)) << endl;

    times_(int(implementationNumber_), int(parameterNumber_-1)) -= 
      timer_.elapsed();
    instr_(int(implementationNumber_), int(parameterNumber_-1)) -= 
      timer_.instr();
    flops_(int(implementationNumber_), int(parameterNumber_-1)) -= 
      timer_.flops();

    if(times_(int(implementationNumber_), int(parameterNumber_-1))<0) {
      cerr << "\tError: Timer underflow in benchmark " << implementationDescriptions_[implementationNumber_] << " " << parameters_(parameterNumber_-1) << endl;
      times_(int(implementationNumber_), int(parameterNumber_-1)) = blitz::huge(times_(0,0));
    }
    state_ = benchmarkingImplementation;
}

template<typename P_parameter>
inline void BenchmarkExt<P_parameter>::skip()
{
    BZPRECONDITION(state_ == benchmarkingImplementation);
    BZPRECONDITION(parameterNumber_ < numParameters_);
    times_(int(implementationNumber_), int(parameterNumber_)) = blitz::quiet_NaN(double());
    ++parameterNumber_;
    state_ = benchmarkingImplementation;
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::endImplementation()
{
    BZPRECONDITION(state_ == benchmarkingImplementation);
    BZPRECONDITION(parameterNumber_ == numParameters_);

    ++implementationNumber_;

    state_ = benchmarking;
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::endBenchmarking()
{
    BZPRECONDITION(state_ == benchmarking);
    BZPRECONDITION(implementationNumber_ == numImplementations_);
    
    state_ = done;
}

template<typename P_parameter>
double BenchmarkExt<P_parameter>::getMflops(unsigned implementation,
    unsigned parameterNum) const
{
    BZPRECONDITION(state_ == done);
    BZPRECONDITION(implementation < numImplementations_);
    BZPRECONDITION(parameterNum < numParameters_);
    return 1.0*iterations_(parameterNum) * flopsPerIteration_(parameterNum)
      / times_(int(implementation), int(parameterNum)) * timerconversion_;
}

template<typename P_parameter>
double BenchmarkExt<P_parameter>::getinstrperc(int implementation,
					       int parameterNum) const
{
    BZPRECONDITION(state_ == done);
    BZPRECONDITION(implementation < numImplementations_);
    BZPRECONDITION(parameterNum < numParameters_);
    return 1.0*instr_(implementation,parameterNum)/
      times_(int(implementation), int(parameterNum));
}
template<typename P_parameter>
double BenchmarkExt<P_parameter>::getflopsperc(int implementation,
					       int parameterNum) const
{
    BZPRECONDITION(state_ == done);
    BZPRECONDITION(implementation < numImplementations_);
    BZPRECONDITION(parameterNum < numParameters_);
    return 1.0*flops_(implementation,parameterNum)/
      times_(int(implementation), int(parameterNum));
}

template<typename P_parameter>
void BenchmarkExt<P_parameter>::saveMatlabGraph(const char* filename, const char* graphType) const
{
    BZPRECONDITION(state_ == done);

    {
      //ugly but saveMatlabGraph is coded into all benchmarks
      std::string pyfn(filename);
      pyfn=pyfn.replace(pyfn.find(".m"),2,std::string(".py"),0,3);
      savePylabGraph(pyfn.c_str());
    }

    ofstream ofs(filename);
     
    assert(ofs.good());

    ofs << "% This matlab file generated automatically by class Benchmark"
        << endl << "% of the Blitz++ class library." << endl << endl;

    ofs.setf(ios::scientific);

    // This will be a lot simpler once Matlab-style output formatting
    // of vectors & matrices is finished.

    // ofs << "parm = " << parameters_ << ";" << endl << endl;

    ofs << "parm = [ ";
    unsigned i;
    for (i=0; i < numParameters_; ++i)
      ofs << setprecision(12) << double(parameters_(i)) << " ";
    ofs << "]; " << endl << endl;

    ofs << "Mf = [ ";
    for (i=0; i < numParameters_; ++i)
    {
        for (unsigned j=0; j < numImplementations_; ++j)
        {
            ofs << setprecision(12) << getMflops(j,i) << " ";
        }
        if (i != numParameters_ - 1)
            ofs << ";" << endl;
    }
    ofs << "] ;" << endl << endl;

    ofs << graphType << "(parm,Mf), title('" << description_ << "'), " << endl
        << "    xlabel('" << parameterDescription_ << "'), "
        << "ylabel('" << depvar_ << "')\n"
        << "legend(";
    
    for (unsigned j=0; j < numImplementations_; ++j)
    {
        ofs << "'" << implementationDescriptions_[j] << "'";
        if (j != numImplementations_ - 1)
            ofs << ", ";
    } 

    ofs << ")" << endl;
}


template<typename P_parameter>
void BenchmarkExt<P_parameter>::savePylabGraph(const char* filename, const char* graphType) const
{
    BZPRECONDITION(state_ == done);

    ofstream ofs(filename);
     
    assert(ofs.good());

    ofs << "# This python file generated automatically by class Benchmark\n"
        << "# of the Blitz++ class library.\n"
	<< "from pylab import *\nfrom numpy import *\n"
	<< "clf()\n";

    ofs.setf(ios::scientific);

    ofs << "legnames=[";
    for (unsigned j=0; j < numImplementations_; ++j)
    {
        ofs << "'" << implementationDescriptions_[j] << "'";
        if (j != numImplementations_ - 1)
            ofs << ", ";
    } 

    ofs << "]\n\nparm = array([ ";
    unsigned i;
    for (i=0; i < numParameters_; ++i)
      ofs << setprecision(12) << double(parameters_(i)) << ", ";
    ofs << "])\n\n";

    ofs << "Mf = array([[ ";
    for (i=0; i < numParameters_; ++i)
    {
        if(i>0) ofs << ", [ ";
        for (unsigned j=0; j < numImplementations_; ++j)
        {
	  ofs << setprecision(12) << getMflops(j,i);
	  if(j<numImplementations_-1) ofs << ", ";
        }
	ofs << "]";
    }
    ofs << "])" << endl << endl;
#ifdef BZ_HAVE_LIBPAPI
    // add i/c and flops counters
    ofs << "ic = array([[ ";
    for (i=0; i < numParameters_; ++i)
    {
        if(i>0) ofs << ", [ ";
        for (unsigned j=0; j < numImplementations_; ++j)
        {
	  ofs << setprecision(12) << getinstrperc(j,i);
	  if(j<numImplementations_-1) ofs << ", ";
        }
	ofs << "]";
    }
    ofs << "])" << endl << endl;
    ofs << "fc = array([[ ";
    for (i=0; i < numParameters_; ++i)
    {
        if(i>0) ofs << ", [ ";
        for (unsigned j=0; j < numImplementations_; ++j)
        {
	  ofs << setprecision(12) << getflopsperc(j,i);
	  if(j<numImplementations_-1) ofs << ", ";
        }
	ofs << "]";
    }
    ofs << "])" << endl << endl;
#endif

    ofs << graphType << "(parm,Mf)\ntitle('" << description_ << "')\n"
        << "xlabel('" << parameterDescription_ << "')\n"
        << "ylabel('" << depvar_ << "')\n";

    ofs << "legend(legnames)\n";
}

BZ_NAMESPACE_END

#endif // BZ_BENCHEXT_CC