MyraMath
pherk2


Source: tests/pdense/pherk2.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/herk.h>
23 
24 // Parallel algorithms.
25 #include <myramath/pdense/pherk.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  // Generate random matrix A.
41  auto A = Matrix<Number>::random(I,J);
42  Precision alpha = random<Precision>();
43  Precision beta = random<Precision>();
44  // Initialize options.
45  auto options = Options::create().set_nthreads(4).set_blocksize(128);
46  // Check herk('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  herk_inplace(C_serial,A,'N',alpha,beta);
53  pherk_inplace(C_parallel,A,'N',alpha,beta,options);
54  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
55  myra::out() << " |herk('N')-pherk('N')| = " << error << std::endl;
56  REQUIRE(error < tolerance);
57  }
58  // Check herk('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  herk_inplace(C_serial,A,'T',alpha,beta);
65  pherk_inplace(C_parallel,A,'T',alpha,beta,options);
66  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
67  myra::out() << " |herk('T')-pherk('T')| = " << error << std::endl;
68  REQUIRE(error < tolerance);
69  }
70  // Check herk('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  herk_inplace(C_serial,A,'H',alpha,beta);
77  pherk_inplace(C_parallel,A,'H',alpha,beta,options);
78  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
79  myra::out() << " |herk('H')-pherk('H')| = " << error << std::endl;
80  REQUIRE(error < tolerance);
81  }
82  // Check herk('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  herk_inplace(C_serial,A,'C',alpha,beta);
89  pherk_inplace(C_parallel,A,'C',alpha,beta,options);
90  Precision error = frobenius(C_serial-C_parallel) / frobenius(C_serial);
91  myra::out() << " |herk('C')-pherk('C')| = " << error << std::endl;
92  REQUIRE(error < tolerance);
93  }
94  }
95 
96 } // namespace
97 
98 ADD_TEST("pherk2","[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.
Routines for hermitian rank-k updates, a specialized form of Matrix*Matrix multiplication.
Routines for computing Frobenius norms of various algebraic containers.
Thread parallel version of dense/herk.h, hermitian rank-k updates.
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
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.
Returns a hermitian copy of a Matrix. The inplace version only works on a square operand.
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>
|herk('N')-pherk('N')| = 0
|herk('T')-pherk('T')| = 0
|herk('H')-pherk('H')| = 0
|herk('C')-pherk('C')| = 0
std::complex<double>
|herk('N')-pherk('N')| = 0
|herk('T')-pherk('T')| = 0
|herk('H')-pherk('H')| = 0
|herk('C')-pherk('C')| = 0


Go back to Summary of /test programs.