1 #include <shark/LinAlg/BLAS/blas.h> 7 template<
class Triangular,
class AMat,
class BMat,
class CMat>
9 blas::matrix_expression<AMat, blas::cpu_tag>
const& A,
10 blas::matrix_expression<BMat, blas::cpu_tag>
const& B,
11 blas::matrix_expression<CMat, blas::cpu_tag> & C
13 double minTime = std::numeric_limits<double>::max();
14 for(std::size_t i = 0; i != 10; ++i){
16 noalias(C) += blas::triangular_prod<Triangular>(A,B);
17 minTime = min(minTime,time.
stop());
19 return (0.5*A().size1()*A().size2()*B().size2())/minTime/1024/1024;
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 != 10; ++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;
33 blas::matrix<double,blas::row_major> Brow(size,size);
34 for(std::size_t k = 0; k != size; ++k){
35 for(std::size_t j = 0; j != size; ++j){
36 Brow(k,j) = 0.1/size*j+0.1/size*k;
39 blas::matrix<double,blas::column_major> Acol = Arow;
40 blas::matrix<double,blas::column_major> Bcol = Brow;
42 blas::matrix<double,blas::row_major> Crow(size,size,0.0);
43 blas::matrix<double,blas::column_major> Ccol(size,size,0.0);
44 std::cout<<size<<
"\t row major result - lower\t"<<benchmark<blas::lower>(Arow,Brow,Crow)<<
"\t"<< benchmark<blas::lower>(Acol,Brow,Crow)
45 <<
"\t"<< benchmark<blas::lower>(Arow,Bcol,Crow) <<
"\t" <<benchmark<blas::lower>(Acol,Bcol,Crow) <<std::endl;
46 std::cout<<size<<
"\t row major result - upper\t"<<benchmark<blas::upper>(Arow,Brow,Crow)<<
"\t"<< benchmark<blas::upper>(Acol,Brow,Crow)
47 <<
"\t"<< benchmark<blas::upper>(Arow,Bcol,Crow) <<
"\t" <<benchmark<blas::upper>(Acol,Bcol,Crow) <<std::endl;
48 std::cout<<size<<
"\t column major result - lower\t"<<benchmark<blas::lower>(Arow,Brow,Ccol)<<
"\t"<< benchmark<blas::lower>(Acol,Brow,Ccol)
49 <<
"\t"<< benchmark<blas::lower>(Arow,Bcol,Ccol) <<
"\t" <<benchmark<blas::lower>(Acol,Bcol,Ccol) <<std::endl;
50 std::cout<<size<<
"\t column major result - upper\t"<<benchmark<blas::upper>(Arow,Brow,Ccol)<<
"\t"<< benchmark<blas::upper>(Acol,Brow,Ccol)
51 <<
"\t"<< benchmark<blas::upper>(Arow,Bcol,Ccol) <<
"\t" <<benchmark<blas::upper>(Acol,Bcol,Ccol) <<std::endl;