sparse_randomsetter.cpp File Reference
#include <map>
#include <ext/hash_map>
#include <google/dense_hash_map>
#include <google/sparse_hash_map>
#include "BenchSparseUtil.h"

Macros

#define NOGMM
 
#define NOMTL
 
#define EIGEN_GOOGLEHASH_SUPPORT   1
 
#define SIZE   10000
 
#define DENSITY   0.01
 
#define REPEAT   1
 
#define MINDENSITY   0.0004
 
#define NBTRIES   10
 
#define BENCH(X)
 

Functions

template<typename SetterType >
void dostuff (const char *name, EigenSparseMatrix &sm1)
 
int main (int argc, char *argv[])
 

Variables

static double rtime
 
static double nentries
 

Macro Definition Documentation

◆ BENCH

#define BENCH (   X)
Value:
timer.reset(); \
for (int _j = 0; _j < NBTRIES; ++_j) { \
timer.start(); \
for (int _k = 0; _k < REPEAT; ++_k) { \
X \
} \
timer.stop(); \
}
#define REPEAT
Definition: sparse_randomsetter.cpp:20
#define NBTRIES
Definition: sparse_randomsetter.cpp:30

◆ DENSITY

#define DENSITY   0.01

◆ EIGEN_GOOGLEHASH_SUPPORT

#define EIGEN_GOOGLEHASH_SUPPORT   1

◆ MINDENSITY

#define MINDENSITY   0.0004

◆ NBTRIES

#define NBTRIES   10

◆ NOGMM

#define NOGMM

◆ NOMTL

#define NOMTL

◆ REPEAT

#define REPEAT   1

◆ SIZE

#define SIZE   10000

Function Documentation

◆ dostuff()

template<typename SetterType >
void dostuff ( const char name,
EigenSparseMatrix sm1 
)
47  {
48  int rows = sm1.rows();
49  int cols = sm1.cols();
50  sm1.setZero();
51  BenchTimer t;
52  SetterType* set1 = new SetterType(sm1);
53  t.reset();
54  t.start();
55  for (int k = 0; k < nentries; ++k)
56  (*set1)(internal::random<int>(0, rows - 1), internal::random<int>(0, cols - 1)) += 1;
57  t.stop();
58  std::cout << "std::map => \t" << t.value() - rtime << " nnz=" << set1->nonZeros() << std::flush;
59 
60  // getchar();
61 
62  t.reset();
63  t.start();
64  delete set1;
65  t.stop();
66  std::cout << " back: \t" << t.value() << "\n";
67 }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Definition: BenchTimer.h:55
void setZero()
Definition: SparseMatrix.h:303
Index cols() const
Definition: SparseMatrix.h:161
Index rows() const
Definition: SparseMatrix.h:159
char char char int int * k
Definition: level2_impl.h:374
t
Definition: plotPSD.py:36
static double rtime
Definition: sparse_randomsetter.cpp:43
static double nentries
Definition: sparse_randomsetter.cpp:44

References cols, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::cols(), k, nentries, rows, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::rows(), rtime, Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::setZero(), and plotPSD::t.

◆ main()

int main ( int argc  ,
char argv[] 
)
69  {
70  int rows = SIZE;
71  int cols = SIZE;
72  float density = DENSITY;
73 
74  EigenSparseMatrix sm1(rows, cols), sm2(rows, cols);
75 
76  nentries = rows * cols * density;
77  std::cout << "n = " << nentries << "\n";
78  int dummy;
79  BenchTimer t;
80 
81  t.reset();
82  t.start();
83  for (int k = 0; k < nentries; ++k) dummy = internal::random<int>(0, rows - 1) + internal::random<int>(0, cols - 1);
84  t.stop();
85  rtime = t.value();
86  std::cout << "rtime = " << rtime << " (" << dummy << ")\n\n";
87  const int Bits = 6;
88  for (;;) {
89  dostuff<RandomSetter<EigenSparseMatrix, StdMapTraits, Bits> >("std::map ", sm1);
90  dostuff<RandomSetter<EigenSparseMatrix, GnuHashMapTraits, Bits> >("gnu::hash_map", sm1);
91  dostuff<RandomSetter<EigenSparseMatrix, GoogleDenseHashMapTraits, Bits> >("google::dense", sm1);
92  dostuff<RandomSetter<EigenSparseMatrix, GoogleSparseHashMapTraits, Bits> >("google::sparse", sm1);
93 
94  // {
95  // RandomSetter<EigenSparseMatrix,GnuHashMapTraits,Bits> set1(sm1);
96  // t.reset(); t.start();
97  // for (int k=0; k<n; ++k)
98  // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
99  // t.stop();
100  // std::cout << "gnu::hash_map => \t" << t.value()-rtime
101  // << " nnz=" << set1.nonZeros() << "\n";getchar();
102  // }
103  // {
104  // RandomSetter<EigenSparseMatrix,GoogleDenseHashMapTraits,Bits> set1(sm1);
105  // t.reset(); t.start();
106  // for (int k=0; k<n; ++k)
107  // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
108  // t.stop();
109  // std::cout << "google::dense => \t" << t.value()-rtime
110  // << " nnz=" << set1.nonZeros() << "\n";getchar();
111  // }
112  // {
113  // RandomSetter<EigenSparseMatrix,GoogleSparseHashMapTraits,Bits> set1(sm1);
114  // t.reset(); t.start();
115  // for (int k=0; k<n; ++k)
116  // set1(internal::random<int>(0,rows-1),internal::random<int>(0,cols-1)) += 1;
117  // t.stop();
118  // std::cout << "google::sparse => \t" << t.value()-rtime
119  // << " nnz=" << set1.nonZeros() << "\n";getchar();
120  // }
121  std::cout << "\n\n";
122  }
123 
124  return 0;
125 }
density
Definition: UniformPSDSelfTest.py:19
#define SIZE
Definition: sparse_randomsetter.cpp:12
#define DENSITY
Definition: sparse_randomsetter.cpp:16

References cols, UniformPSDSelfTest::density, DENSITY, k, nentries, rows, rtime, SIZE, and plotPSD::t.

Variable Documentation

◆ nentries

double nentries
static

Referenced by dostuff(), and main().

◆ rtime

double rtime
static

Referenced by dostuff(), and main().