MyraMath
ppotrf1


Source: tests/pdense/ppotrf1.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.
17 #include <myramath/dense/gemm.h>
18 #include <myramath/dense/potrf.h>
19 #include <myramath/dense/trsm.h>
21 
22 // Parallel algorithms.
23 #include <myramath/pdense/pgemm.h>
24 #include <myramath/pdense/ppotrf.h>
25 #include <myramath/pdense/ptrsm.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 Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
37  {
38  typedef typename ReflectPrecision<Number>::type Precision;
39  myra::out() << typestring<Number>() << std::endl;
40  // Construct random symmetric positive definite matrix A, random X, and image B=A*X
41  auto G = Matrix<Number>::random(I,I);
42  auto A = pgemm(G,G,'H');
43  for (int i = 0; i < I; ++i)
44  A(i,i) += 1;
45  auto X = Matrix<Number>::random(I,J);
46  auto B = pgemm(A,X);
47  Number one(1);
48  // Initialize options.
49  auto options = Options::create().set_nthreads(4).set_blocksize(128);
50  // Testing/profiling ppotrf('L')
51  {
52  // Measure factor/solve times for serial routines.
53  auto L_serial = A;
54  auto X_serial = B;
55  potrf_inplace('L','R',L_serial);
56  trsm_inplace('L','L','N',L_serial,X_serial);
57  trsm_inplace('L','L','H',L_serial,X_serial);
58  Precision e_serial = frobenius(A*X_serial-B) / frobenius(B);
59  // Measure factor/solve times for parallel routines.
60  auto L_parallel = A;
61  auto X_parallel = B;
62  ppotrf_inplace('L',L_parallel,options);
63  ptrsm_inplace('L','L','N',L_parallel,X_parallel,'N',one,options);
64  ptrsm_inplace('L','L','H',L_parallel,X_parallel,'N',one,options);
65  Precision e_parallel = frobenius(A*X_parallel-B) / frobenius(B);
66  // Report accuracy and time.
67  myra::out() << " |L*L'*X-B|, serial = " << e_serial << std::endl;
68  myra::out() << " |L*L'*X-B|, parallel = " << e_parallel << std::endl;
69  REQUIRE(e_serial < tolerance);
70  REQUIRE(e_parallel < tolerance);
71  }
72  // Testing/profiling ppotrf('U')
73  {
74  // Measure factor/solve times for serial routines.
75  auto U_serial = A;
76  auto X_serial = B;
77  potrf_inplace('U','R',U_serial);
78  trsm_inplace('L','U','N',U_serial,X_serial);
79  trsm_inplace('L','U','H',U_serial,X_serial);
80  Precision e_serial = frobenius(A*X_serial-B) / frobenius(B);
81  // Measure factor/solve times for parallel routines.
82  auto U_parallel = A;
83  auto X_parallel = B;
84  ppotrf_inplace('U',U_parallel,options);
85  ptrsm_inplace('L','U','N',U_parallel,X_parallel,'N',one,options);
86  ptrsm_inplace('L','U','H',U_parallel,X_parallel,'N',one,options);
87  Precision e_parallel = frobenius(A*X_parallel-B) / frobenius(B);
88  // Report accuracy and time.
89  myra::out() << " |U*U'*X-B|, serial = " << e_serial << std::endl;
90  myra::out() << " |U*U'*X-B|, parallel = " << e_parallel << std::endl;
91  REQUIRE(e_serial < tolerance);
92  REQUIRE(e_parallel < tolerance);
93  }
94  }
95 
96 } // namespace
97 
98 ADD_TEST("ppotrf1","[pdense][parallel]")
99  {
100  int I = 512;
101  int J = 256;
102  test<NumberS> (I,J,1.0e-4f);
103  test<NumberD> (I,J,1.0e-8);
104  test<NumberC> (I,J,1.0e-4f);
105  test<NumberZ> (I,J,1.0e-8);
106  }
Cholesky factorization routines for positive definite matrices.
Thread-parallel version of dense/potrf.h, Cholesky decomposition of a symmetric positive Matrix...
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.
Definition: syntax.dox:1
Routines for backsolving by a triangular Matrix or LowerMatrix.
Various utility functions/classes related to scalar Number types.
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.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.


Results: [PASS]

float
|L*L'*X-B|, serial = 3.8177e-07
|L*L'*X-B|, parallel = 2.90744e-07
|U*U'*X-B|, serial = 3.62301e-07
|U*U'*X-B|, parallel = 2.86831e-07
double
|L*L'*X-B|, serial = 6.62325e-16
|L*L'*X-B|, parallel = 4.28738e-16
|U*U'*X-B|, serial = 6.24621e-16
|U*U'*X-B|, parallel = 4.26244e-16
std::complex<float>
|L*L'*X-B|, serial = 3.82463e-07
|L*L'*X-B|, parallel = 3.02693e-07
|U*U'*X-B|, serial = 3.61825e-07
|U*U'*X-B|, parallel = 2.9542e-07
std::complex<double>
|L*L'*X-B|, serial = 6.65187e-16
|L*L'*X-B|, parallel = 4.56632e-16
|U*U'*X-B|, serial = 6.26351e-16
|U*U'*X-B|, parallel = 4.52292e-16


Go back to Summary of /test programs.