MyraMath
phemm1


Source: tests/pdense/phemm1.cpp

1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
11 // Containers.
13 #include <myramath/dense/Matrix.h>
15 
16 // Serial algorithms.
19 #include <myramath/dense/tril.h>
20 #include <myramath/dense/triu.h>
21 #include <myramath/dense/hemm.h>
23 
24 // Parallel algorithms.
25 #include <myramath/pdense/phemm.h>
27 
28 // Reporting.
29 #include <tests/myratest.h>
30 
31 using namespace myra;
32 typedef pdense::Options Options;
33 
34 namespace {
35 
36 template<class Precision> void test(int I, int J, Precision tolerance)
37  {
38  typedef std::complex<Precision> Number;
39  myra::out() << typestring<Number>() << std::endl;
40  // Make random hermitian matrix A.
41  auto A = Matrix<Number>::random(I,I);
42  A = A + hermitian(A);
43  Number alpha = random<Number>();
44  Number beta = random<Number>();
45  // Make upper/lower triangles of it.
46  Matrix<Number> L = tril(A);
47  Matrix<Number> U = triu(A);
48  // Initialize options.
49  auto options = Options::create().set_nthreads(4).set_blocksize(128);
50  // Check phemm('L','L')
51  {
52  auto B = Matrix<Number>::random(I,J);
53  auto C1 = Matrix<Number>::random(I,J);
54  auto C2 = C1;
55  hemm_inplace('L', 'L', C1, L, B, alpha, beta);
56  phemm_inplace('L', 'L', C2, L, B, alpha, beta, options);
57  Precision error = frobenius(C1-C2)/frobenius(C1);
58  myra::out() << " |hemm('L','L')-phemm('L','L')| = " << error << std::endl;
59  REQUIRE(error < tolerance);
60  }
61  // Check phemm('L','U')
62  {
63  auto B = Matrix<Number>::random(I,J);
64  auto C1 = Matrix<Number>::random(I,J);
65  auto C2 = C1;
66  hemm_inplace('L', 'U', C1, U, B, alpha, beta);
67  phemm_inplace('L', 'U', C2, U, B, alpha, beta, options);
68  Precision error = frobenius(C1-C2)/frobenius(C1);
69  myra::out() << " |hemm('L','U')-phemm('L','U')| = " << error << std::endl;
70  REQUIRE(error < tolerance);
71  }
72  // Check phemm('R','L')
73  {
74  auto B = Matrix<Number>::random(J,I);
75  auto C1 = Matrix<Number>::random(J,I);
76  auto C2 = C1;
77  hemm_inplace('R', 'L', C1, L, B, alpha, beta);
78  phemm_inplace('R', 'L', C2, L, B, alpha, beta, options);
79  Precision error = frobenius(C1-C2)/frobenius(C1);
80  myra::out() << " |hemm('R','L')-phemm('R','L')| = " << error << std::endl;
81  REQUIRE(error < tolerance);
82  }
83  // Check phemm('R','U')
84  {
85  auto B = Matrix<Number>::random(J,I);
86  auto C1 = Matrix<Number>::random(J,I);
87  auto C2 = C1;
88  hemm_inplace('R', 'U', C1, U, B, alpha, beta);
89  phemm_inplace('R', 'U', C2, U, B, alpha, beta, options);
90  Precision error = frobenius(C1-C2)/frobenius(C1);
91  myra::out() << " |hemm('R','U')-phemm('R','U')| = " << error << std::endl;
92  REQUIRE(error < tolerance);
93  }
94  }
95 
96 } // namespace
97 
98 ADD_TEST("phemm1","[pdense][parallel]")
99  {
100  int I = 512;
101  int J = 256;
102  test<float > (I,J,1.0e-4f);
103  test<double> (I,J,1.0e-8);
104  }
Interface class for representing subranges of dense Matrix&#39;s.
Tabulates an IxJ matrix. Allows random access, has column major layout to be compatible with BLAS/LAP...
Definition: bdsqr.h:20
Thread-parallel version of dense/phemm.h, hermitian Matrix * dense Matrix multiplication.
Routines for computing Frobenius norms of various algebraic containers.
static Matrix< Number > random(int I, int J)
Generates a random Matrix of specified size.
Definition: Matrix.cpp:353
Options pack for routines in /pdense.
Definition: Options.h:24
Routines for hermitian Matrix * dense Matrix multiplication.
Definition: syntax.dox:1
Returns the lower triangle of a dense Matrix.
Returns the upper triangle of a dense Matrix.
Various utility functions/classes related to scalar Number types.
General purpose dense matrix container, O(i*j) storage.
Options pack for routines in /pdense.
Returns a hermitian copy of a Matrix. The inplace version only works on a square operand.
Simplistic random number functions.


Results: [PASS]

std::complex<float>
|hemm('L','L')-phemm('L','L')| = 2.90252e-07
|hemm('L','U')-phemm('L','U')| = 3.46372e-07
|hemm('R','L')-phemm('R','L')| = 4.68456e-07
|hemm('R','U')-phemm('R','U')| = 4.69157e-07
std::complex<double>
|hemm('L','L')-phemm('L','L')| = 5.53697e-16
|hemm('L','U')-phemm('L','U')| = 6.61817e-16
|hemm('R','L')-phemm('R','L')| = 7.2084e-16
|hemm('R','U')-phemm('R','U')| = 7.23341e-16


Go back to Summary of /test programs.