MyraMath
phetrf2


Source: tests/pdense/phetrf2.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>
18 
19 // Serial algorithms.
20 #include <myramath/dense/gemm.h>
21 #include <myramath/dense/hetrf.h>
22 #include <myramath/dense/trsm.h>
25 #include <myramath/dense/swaps.h>
26 
27 // Parallel algorithms.
28 #include <myramath/pdense/phemm.h>
29 #include <myramath/pdense/phetrf.h>
30 #include <myramath/pdense/ptrsm.h>
32 
33 // Reporting.
34 #include <tests/myratest.h>
35 
36 using namespace myra;
37 typedef pdense::Options Options;
38 
39 namespace {
40 
41 template<class Precision> void test(int I, int J, Precision tolerance)
42  {
43  typedef std::complex<Precision> Number;
44  myra::out() << typestring<Number>() << std::endl;
45  // Construct random hermitian matrix A
46  auto A = Matrix<Number>::random(I,I);
47  A = A + hermitian(A);
48  // A.transform([](const NumberZ& a){return NumberZ(a.real(),0);});
50  auto X = Matrix<Number>::random(I,J);
51  auto B = phemm('L',L,X);
52  Number one(1);
53  // Initialize options.
54  auto options = Options::create().set_nthreads(4).set_blocksize(128);
55  // Test phetrf('L')
56  {
57  // Measure factor/solve times for serial routine.
58  auto L_serial = L;
59  auto X_serial = B;
60  auto PQRI_serial = hetrf_inplace(L_serial);
61  // This routine factors A = P'*L*Q'*I*Q*L'*P, several steps required for backsolution.
62  swap_rows(PQRI_serial.P_swaps,X_serial);
63  trsm_inplace('L', 'N', L_serial, X_serial);
64  PQRI_serial.R.solve(X_serial,'L','N');
65  swap_rows(PQRI_serial.Q_swaps,X_serial);
66  X_serial.bottom(PQRI_serial.n_minus) *= -one;
67  iswap_rows(PQRI_serial.Q_swaps,X_serial);
68  PQRI_serial.R.solve(X_serial,'L','H');
69  trsm_inplace('L', 'H', L_serial, X_serial);
70  iswap_rows(PQRI_serial.P_swaps,X_serial);
71  Precision e_serial = frobenius(A*X_serial-B) / frobenius(B);
72  // Measure factor/solve times for serial routine.
73  auto L_parallel = L;
74  auto X_parallel = B;
75  auto PQRI_parallel = phetrf_inplace(L_parallel,options);
76  // This routine factors A = P'*L*Q'*I*Q*L'*P, several steps required for backsolution.
77  swap_rows(PQRI_parallel.P_swaps,X_parallel);
78  ptrsm_inplace('L', 'N', L_parallel, X_parallel, 'N', one, options);
79  PQRI_parallel.R.solve(X_parallel,'L','N');
80  swap_rows(PQRI_parallel.Q_swaps,X_parallel);
81  X_parallel.bottom(PQRI_parallel.n_minus) *= -one;
82  iswap_rows(PQRI_parallel.Q_swaps,X_parallel);
83  PQRI_parallel.R.solve(X_parallel,'L','H');
84  ptrsm_inplace('L', 'H', L_parallel, X_parallel, 'N', one, options);
85  iswap_rows(PQRI_parallel.P_swaps,X_parallel);
86  Precision e_parallel = frobenius(A*X_parallel-B) / frobenius(B);
87  // Report accuracy and time.
88  myra::out() << " |L*L'*X-B|, serial = " << e_serial << std::endl;
89  myra::out() << " |L*L'*X-B|, parallel = " << e_parallel << std::endl;
90  REQUIRE(e_serial < tolerance);
91  REQUIRE(e_parallel < tolerance);
92  }
93  }
94 
95 } // namespace
96 
97 ADD_TEST("phetrf2","[pdense][parallel]")
98  {
99  int I = 512;
100  int J = 256;
101  test<float> (I,J,1.0e-3f);
102  test<double> (I,J,1.0e-8);
103  }
Interface class for representing subranges of dense Matrix&#39;s.
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
LDL&#39; decompositions for real hermitian Matrix A (indefinite is fine).
Thread-parallel version of dense/trsm.h, triangular Matrix \ dense Matrix backsolution.
Thread-parallel version of dense/hetrf.h, LDL&#39; decomposition of a hermitian indefinite Matrix...
Range construct for a lower triangular matrix stored in rectangular packed format.
Definition: syntax.dox:1
Routines for backsolving by a triangular Matrix or LowerMatrix.
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.
Routines related to swap sequences, often used during pivoting.
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.
Stores a lower triangular matrix in rectangular packed format.
Definition: conjugate.h:22
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.
Interface class for representing subranges of contiguous int&#39;s.


Results: [PASS]

std::complex<float>
|L*L'*X-B|, serial = 1.8843e-05
|L*L'*X-B|, parallel = 2.07508e-05
std::complex<double>
|L*L'*X-B|, serial = 3.37864e-14
|L*L'*X-B|, parallel = 3.73965e-14


Go back to Summary of /test programs.