20{
21
22 cout << "\n";
23 cout << "=== Matrix: Native/BLAS multiplication =============\n";
24 cout << "\n";
25
29 a( 0, 0 ) = 1.0;
30 a( 0, 1 ) = 2.0;
31 a( 0, 2 ) = 3.0;
32 a( 1, 0 ) = 4.0;
33 a( 1, 1 ) = 5.0;
34 a( 1, 2 ) = 6.0;
35 b( 0, 0 ) = 1.0;
36 b( 0, 1 ) = 2.0;
37 b( 1, 0 ) = 3.0;
38 b( 1, 1 ) = 4.0;
39 b( 2, 0 ) = 5.0;
40 b( 2, 1 ) = 6.0;
42 answer( 0, 0 ) = 22.0;
43 answer( 0, 1 ) = 28.0;
44 answer( 1, 0 ) = 49.0;
45 answer( 1, 1 ) = 64.0;
46
47 c = a.multiply( b );
48
49 const double tol = 1.e-10;
51 c.sub( answer );
52 if ( c.inf_norm() > tol )
53 {
54 std::cout << " Infinity norm of error = " << c.inf_norm() << "\n";
55 std::cout << " Native method : Simple (2x3) * (3x2) matrix mult failed\n";
57 }
58 else
59 {
60 std::cout << " Native method : Simple (2x3) * (3x2) matrix mult passed \n";
61 }
62
63
64#ifdef LAPACK
67 cblas.sub( answer );
68 if ( cblas.inf_norm() > tol )
69 {
70 std::cout << " Infinity norm of error = " << cblas.inf_norm() << "\n";
71 std::cout << " BLAS : Simple (2x3) * (3x2) matrix mult failed \n";
73 }
74 else
75 {
76 std::cout << " BLAS : Simple (2x3) * (3x2) matrix mult test passed \n";
77 }
78#endif
79
80#ifdef TIME
82 for ( int N = 128; N <= 2048 ; N *= 2 )
83 {
84 std::cout << "\n --- Filling arrays of size " << N << "x" << N << "\n";
85
86
88 Utility::fill_random( A );
90 Utility::fill_random( B );
92
96 std::cout << "\n Native N^3 multiplication method :\n";
99
100#ifdef LAPACK
101
106 std::cout << "\n BLAS multiplication method :\n";
109
110 Cblas.sub( C );
111 if ( Cblas.inf_norm() > tol )
112 {
113 std::cout << " Infinity norm of error = " << Cblas.inf_norm() << "\n";
114 std::cout << " BLAS & native matrix multiplication disagree! \n";
116 }
117#endif
118
119 }
120#endif
121
122 if ( failed )
123 {
124 cout << "\033[1;31;48m * FAILED \033[0m\n";
125 }
126 else
127 {
128 cout << "\033[1;32;48m * PASSED \033[0m\n";
129 }
130}
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
A simple CPU-clock-tick timer for timing metods.
void start()
Start the timer & reset stored time to zero.
void print() const
Write a string to cout stating the time taken.
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
void reset()
Pause the clock & add the time interval to the stored cumulative time.
double A(1.0)
initial hump amplitude
DenseMatrix< double > multiply(DenseMatrix< double > &A, DenseMatrix< double > &B)
BLAS wrapper to do DOUBLE DENSE A_{MxK} * B_{KxN} = C_{MxN} Since this is a Fortran library,...