syrk.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 Triangular, class AMat, class CMat>
9 double benchmark(
10  blas::matrix_expression<AMat, blas::cpu_tag> const& A,
11  blas::matrix_expression<CMat, blas::cpu_tag> & C
12 ){
13  double minTime = std::numeric_limits<double>::max();
14  for(std::size_t i = 0; i != 10; ++i){
15  Timer time;
16  shark::blas::kernels::syrk<Triangular::is_upper>(A,C,2.0);
17  minTime = min(minTime,time.stop());
18  }
19  return (0.5*A().size1()*A().size2()*A().size1())/minTime/1024/1024;
20 }
21 
22 int main(int argc, char **argv) {
23  std::size_t size = 100;
24  std::cout<<"Mega Flops"<<std::endl;
25  for(std::size_t iter = 0; iter != 5; ++iter){
26  blas::matrix<double,blas::row_major> Arow(size,size);
27  for(std::size_t i = 0; i != size; ++i){
28  for(std::size_t k = 0; k != size; ++k){
29  Arow(i,k) = 0.1/size*i+0.1/size*k;
30  }
31  }
32  blas::matrix<double,blas::column_major> Acol = Arow;
33 
34  blas::matrix<double,blas::row_major> Crow(size,size,0.0);
35  blas::matrix<double,blas::column_major> Ccol(size,size,0.0);
36  std::cout<<size<<"\trow major result - lower\t"<<benchmark<blas::lower>(Arow,Crow)<<"\t"<< benchmark<blas::lower>(Acol,Crow)<<std::endl;
37  std::cout<<size<<"\trow major result - upper\t"<<benchmark<blas::upper>(Arow,Crow)<<"\t"<< benchmark<blas::upper>(Acol,Crow)<<std::endl;
38  std::cout<<size<<"\tcolumn major result - lower\t"<<benchmark<blas::lower>(Arow,Ccol)<<"\t"<< benchmark<blas::lower>(Acol,Ccol)<<std::endl;
39  std::cout<<size<<"\tcolumn major result - upper\t"<<benchmark<blas::upper>(Arow,Ccol)<<"\t"<< benchmark<blas::upper>(Acol,Ccol)<<std::endl;
40 
41 
42  std::cout<<std::endl;
43  size *=2;
44  }
45 }