MyraMath
pher2k2


Source: tests/pdense/pher2k2.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>
17 
18 // Serial algorithms.
20 #include <myramath/dense/her2k.h>
22 
23 // Parallel algorithms.
24 #include <myramath/pdense/pher2k.h>
26 
27 // Reporting.
28 #include <tests/myratest.h>
29 
30 using namespace myra;
31 typedef pdense::Options Options;
32 
33 namespace {
34 
35 template<class Precision> void test(int I, int J, Precision tolerance)
36  {
37  typedef std::complex<Precision> Number;
38  myra::out() << typestring<Number>() << std::endl;
39  // Generate random matrix A and B.
40  auto A = Matrix<Number>::random(I,J);
41  auto B = Matrix<Number>::random(I,J);
42  Number alpha = random<Number>();
43  Precision beta = random<Precision>();
44  // Initialize options.
45  auto options = Options::create().set_nthreads(4).set_blocksize(128);
46  // Check her2k('N')
47  {
48  auto C_serial = LowerMatrix<Number>::random(I);
49  for (int i = 0; i < I; ++i)
50  C_serial(i,i) = std::real(C_serial(i,i));
51  auto C_parallel = C_serial;
52  her2k_inplace(C_serial,A,B,'N',alpha,beta);
53  pher2k_inplace(C_parallel,A,B,'N',alpha,beta,options);
54  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
55  myra::out() << " |her2k('N')-pher2k('N')| = " << error << std::endl;
56  REQUIRE(error < tolerance);
57  }
58  // Check her2k('T')
59  {
60  auto C_serial = LowerMatrix<Number>::random(J);
61  for (int j = 0; j < J; ++j)
62  C_serial(j,j) = std::real(C_serial(j,j));
63  auto C_parallel = C_serial;
64  her2k_inplace(C_serial,A,B,'T',alpha,beta);
65  pher2k_inplace(C_parallel,A,B,'T',alpha,beta,options);
66  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
67  myra::out() << " |her2k('T')-pher2k('T')| = " << error << std::endl;
68  REQUIRE(error < tolerance);
69  }
70  // Check her2k('H')
71  {
72  auto C_serial = LowerMatrix<Number>::random(J);
73  for (int j = 0; j < J; ++j)
74  C_serial(j,j) = std::real(C_serial(j,j));
75  auto C_parallel = C_serial;
76  her2k_inplace(C_serial,A,B,'H',alpha,beta);
77  pher2k_inplace(C_parallel,A,B,'H',alpha,beta,options);
78  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
79  myra::out() << " |her2k('H')-pher2k('H')| = " << error << std::endl;
80  REQUIRE(error < tolerance);
81  }
82  // Check her2k('C')
83  {
84  auto C_serial = LowerMatrix<Number>::random(I);
85  for (int i = 0; i < I; ++i)
86  C_serial(i,i) = std::real(C_serial(i,i));
87  auto C_parallel = C_serial;
88  her2k_inplace(C_serial,A,B,'C',alpha,beta);
89  pher2k_inplace(C_parallel,A,B,'C',alpha,beta,options);
90  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
91  myra::out() << " |her2k('C')-pher2k('C')| = " << error << std::endl;
92  REQUIRE(error < tolerance);
93  }
94  }
95 
96 } // namespace
97 
98 ADD_TEST("pher2k2","[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  }
Thread parallel version of dense/her2k.h, hermitian rank-2k updates.
Interface class for representing subranges of dense Matrix&#39;s.
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 rank-2k updates, a specialized form of Matrix*Matrix multiplication.
Range construct for a lower triangular matrix stored in rectangular packed format.
Definition: syntax.dox:1
Specialized container for a lower triangular matrix, O(N^2/2) storage. Used by symmetry exploiting ma...
Various utility functions/classes related to scalar Number types.
General purpose dense matrix container, O(i*j) storage.
Options pack for routines in /pdense.
Simplistic random number functions.
static LowerMatrix< Number > random(int N)
Generates a random LowerMatrix of specified size.
Definition: LowerMatrix.cpp:249


Results: [PASS]

std::complex<float>
|her2k('N')-pher2k('N')| = 3.75736e-08
|her2k('T')-pher2k('T')| = 5.82294e-08
|her2k('H')-pher2k('H')| = 5.82239e-08
|her2k('C')-pher2k('C')| = 3.81043e-08
std::complex<double>
|her2k('N')-pher2k('N')| = 1.15687e-16
|her2k('T')-pher2k('T')| = 1.42385e-16
|her2k('H')-pher2k('H')| = 1.4353e-16
|her2k('C')-pher2k('C')| = 1.15855e-16


Go back to Summary of /test programs.