MyraMath
psytrf2


Source: tests/pdense/psytrf2.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/sytrf.h>
22 #include <myramath/dense/trsm.h>
25 #include <myramath/dense/swaps.h>
26 
27 // Parallel routines under test.
28 #include <myramath/pdense/pgemm.h>
29 #include <myramath/pdense/psytrf.h>
30 #include <myramath/pdense/ptrsm.h>
31 #include <myramath/pdense/psymm.h>
33 
34 // Reporting.
35 #include <tests/myratest.h>
36 
37 using namespace myra;
38 typedef pdense::Options Options;
39 
40 namespace {
41 
42 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
43  {
44  typedef typename ReflectPrecision<Number>::type Precision;
45  myra::out() << typestring<Number>() << std::endl;
46  // Construct random symmetric matrix A
47  auto A = Matrix<Number>::random(I,I);
48  A = A+transpose(A);
50  auto X = Matrix<Number>::random(I,J);
51  auto B = psymm('L',L,X);
52  Number one(1);
53  // Initialize options.
54  auto options = Options::create().set_nthreads(4).set_blocksize(128);
55  // Test psytrf('L')
56  {
57  // Measure factor/solve times for serial routine.
58  auto L_serial = L;
59  auto X_serial = B;
60  auto PQRI_serial = sytrf_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','T');
69  trsm_inplace('L', 'T', 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 = psytrf_inplace(L_parallel);
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','T');
84  ptrsm_inplace('L', 'T', 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("psytrf2","[pdense][parallel]")
98  {
99  int I = 512;
100  int J = 256;
101  test<NumberS> (I,J,1.0e-4f);
102  test<NumberD> (I,J,1.0e-10);
103  test<NumberC> (I,J,1.0e-4f);
104  test<NumberZ> (I,J,1.0e-10);
105  }
106 
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
Thread-parallel version of dense/trsm.h, triangular Matrix \ dense Matrix backsolution.
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.
LDL&#39; decompositions for real symmetric Matrix A (indefinite is fine).
Specialized container for a lower triangular matrix, O(N^2/2) storage. Used by symmetry exploiting ma...
Returns a transposed copy of a Matrix. The inplace version only works on a square operand...
Thread-parallel version of dense/sytrf.h, LDL&#39; decomposition of a symmetric indefinite Matrix...
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.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
Thread-parallel version of dense/gemm.h, Matrix*Matrix multiplication.
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.
Thread-parallel symmetric Matrix * dense Matrix multiplication.
Interface class for representing subranges of contiguous int&#39;s.


Results: [PASS]

float
|L*L'*X-B|, serial = 1.45642e-05
|L*L'*X-B|, parallel = 1.40478e-05
double
|L*L'*X-B|, serial = 3.43104e-14
|L*L'*X-B|, parallel = 2.70661e-14
std::complex<float>
|L*L'*X-B|, serial = 2.022e-05
|L*L'*X-B|, parallel = 1.87708e-05
std::complex<double>
|L*L'*X-B|, serial = 3.37046e-14
|L*L'*X-B|, parallel = 2.93221e-14


Go back to Summary of /test programs.