Functions
TensorIndicesStress_test.cc File Reference

Stress test for TensorIndices class. More...

#include "lardata/Utilities/TensorIndices.h"
#include <array>
#include <chrono>
#include <sstream>
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Stress test for TensorIndices class.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
June 28, 2016
See also
TensorIndices.h

This test performs repeated queries to a TensorIndices object of rank 5. Usage:

TensorIndicesStress_test [DimSize]

where DimSize is the dimension of each size (default: 16 and 32 for debug and non-debug compilation respectively). This test is not extremely representative of a real use case in that the loop content is small and can likely kept in the processor cache, which is not often the case in real scenarios.

Definition in file TensorIndicesStress_test.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 35 of file TensorIndicesStress_test.cc.

35  {
36 
37  // debug being much slower, by default we ask for less cycles
38 #ifdef NDEBUG
39  unsigned int dimSize = 80; // default value
40 #else // !NDEBUG
41  unsigned int dimSize = 32; // default value
42 #endif // ?NDEBUG
43 
44  //
45  // command line argument parsing
46  //
47  if (argc > 1) {
48  std::istringstream sstr(argv[1]);
49  sstr >> dimSize;
50  if (!sstr || (dimSize <= 0)) {
51  std::cerr << "Invalid dimension size: '" << argv[1] << "'." << std::endl;
52  return 1;
53  }
54  }
55 
56 
57  //
58  // set up
59  //
60  auto indices
61  = util::makeTensorIndices(dimSize, dimSize, dimSize, dimSize, dimSize);
62 
63  std::cout << "Running through " << indices.dim<0>()
64  << "x" << indices.dim<1>()
65  << "x" << indices.dim<2>()
66  << "x" << indices.dim<3>()
67  << "x" << indices.dim<4>()
68  << " = " << indices.size() << " tensor elements"
69  << std::endl;
70 
71  //
72  // run
73  //
74  auto startTime = std::chrono::high_resolution_clock::now();
75  using index_t = decltype(indices)::Index_t;
76  std::array<index_t, indices.rank()> i;
77  decltype(indices)::DimSize_t count = 0;
78  for (i[0] = 0; i[0] < (index_t) indices.dim<0>(); ++(i[0])) {
79  for (i[1] = 0; i[1] < (index_t) indices.dim<1>(); ++(i[1])) {
80  for (i[2] = 0; i[2] < (index_t) indices.dim<2>(); ++(i[2])) {
81  for (i[3] = 0; i[3] < (index_t) indices.dim<3>(); ++(i[3])) {
82  for (i[4] = 0; i[4] < (index_t) indices.dim<4>(); ++(i[4])) {
83 
84  auto linIndex = indices(i[0], i[1], i[2], i[3], i[4]);
85  if (count != linIndex) {
86  std::cerr << "Error: ["
87  << i[0] << "][" << i[1] << "][" << i[2] << "]["
88  << i[3] << "][" << i[4]
89  << "] => " << linIndex << " (expected: " << count << ")"
90  << std::endl;
91  return 1;
92  }
93  ++count;
94  } // loop 4
95  } // loop 3
96  } // loop 2
97  } // loop 1
98  } // loop 0
100 
101  std::chrono::duration<double> elapsed = stopTime - startTime;
102  std::cout << "Iterating through all " << count << " indices took "
103  << (elapsed.count() * 1000.) << " milliseconds." << std::endl;
104 
105  return 0;
106 } // main()
unsigned int Index_t
Type to denote the index of the flag.
Definition: BitMask.h:60
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
auto makeTensorIndices(DIMS...dims)
Instantiates a TensorIndices class with the specified dimensions.
QTextStream & endl(QTextStream &s)