potrf.cpp
Go to the documentation of this file.
1 #include <shark/LinAlg/BLAS/blas.h>
3 #include <shark/Core/Timer.h>
4 #include <iostream>
5 using namespace shark;
6 using namespace std;
7 
8 template<class MatA, class Triang>
9 double benchmark(
10  blas::matrix_expression<MatA, blas::cpu_tag> const& A,
11  Triang
12 ){
13  double minTime = std::numeric_limits<double>::max();
14  volatile double res = 0;
15  for(std::size_t i = 0; i != 20; ++i){
16  typename blas::matrix_temporary<MatA>::type Acopy =A;
17  Timer time;
18  blas::kernels::potrf<Triang>(Acopy);
19  minTime = min(minTime,time.stop());
20  res += max(Acopy);
21  }
22  return (1.0/3.0*A().size1()*A().size1()*A().size1())/minTime/1024/1024;
23 }
24 
25 int main(int argc, char **argv) {
26  std::size_t size = 128;
27  std::cout<<"Mega Flops"<<std::endl;
28  for(std::size_t iter = 0; iter != 10; ++iter){
29  blas::matrix<double,blas::row_major> Arow(size,size);
30  for(std::size_t i = 0; i != size; ++i){
31  for(std::size_t j = 0; j != size; ++j){
32  Arow(i,j) = 0.1/size*i+0.1/size*j;
33  }
34  Arow(i,i) += 1000.0;
35  }
36  blas::matrix<double,blas::column_major> Acol = Arow;
37  std::cout<<size<<"\t upper\t"<<benchmark(Arow,blas::upper())<<"\t"<< benchmark(Acol,blas::upper())<<std::endl;
38  std::cout<<size<<"\t lower\t"<<benchmark(Arow,blas::lower())<<"\t"<< benchmark(Acol,blas::lower())<<std::endl;
39  size *=2;
40  }
41 }