MyraMath
ppotrf2


Source: tests/pdense/ppotrf2.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.
19 #include <myramath/dense/gemm.h>
20 #include <myramath/dense/potrf.h>
21 #include <myramath/dense/trsm.h>
24 
25 // Parallel algorithms.
26 #include <myramath/pdense/pherk.h>
27 #include <myramath/pdense/phemm.h>
28 #include <myramath/pdense/ppotrf.h>
29 #include <myramath/pdense/ptrsm.h>
31 
32 // Reporting.
33 #include <tests/myratest.h>
34 
35 using namespace myra;
36 typedef pdense::Options Options;
37 
38 namespace {
39 
40 template<class Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
41  {
42  typedef typename ReflectPrecision<Number>::type Precision;
43  myra::out() << typestring<Number>() << std::endl;
44  // Construct random hermitian positive definite matrix A
45  auto G = Matrix<Number>::random(I,I);
46  auto A = gemm(G,G,'H');
48  auto X = Matrix<Number>::random(I,J);
49  auto B = phemm('L',L,X);
50  Number one(1);
51  // Initialize options.
52  auto options = Options::create().set_nthreads(4).set_blocksize(128);
53  // Measure factor/solve times for serial routines.
54  auto L_serial = L;
55  auto X_serial = B;
56  potrf_inplace(L_serial);
57  trsm_inplace('L','N',L_serial,X_serial);
58  trsm_inplace('L','H',L_serial,X_serial);
59  Precision e_serial = frobenius(A*X_serial-B) / frobenius(B);
60  // Measure factor/solve times for parallel routines.
61  auto L_parallel = L;
62  auto X_parallel = B;
63  ppotrf_inplace(L_parallel,options);
64  ptrsm_inplace('L','N',L_parallel,X_parallel,'N',one,options);
65  ptrsm_inplace('L','H',L_parallel,X_parallel,'N',one,options);
66  Precision e_parallel = frobenius(A*X_parallel-B) / frobenius(B);
67  // Report accuracy and time.
68  myra::out() << " |L*L'*X-B|, serial = " << e_serial << std::endl;
69  myra::out() << " |L*L'*X-B|, parallel = " << e_parallel << std::endl;
70  REQUIRE(e_serial < tolerance);
71  REQUIRE(e_parallel < tolerance);
72  }
73 
74 } // namespace
75 
76 ADD_TEST("ppotrf2","[pdense][parallel]")
77  {
78  int I = 512;
79  int J = 256;
80  test<NumberS>(I,J,1.0e-4f);
81  test<NumberD>(I,J,1.0e-8);
82  test<NumberC>(I,J,1.0e-4f);
83  test<NumberZ>(I,J,1.0e-8);
84  }
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.
Thread-parallel version of dense/phemm.h, hermitian Matrix * dense 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
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.
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.
Reflects Precision trait for a Number, scalar Number types should specialize it.
Definition: Number.h:33
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.


Results: [PASS]

float
|L*L'*X-B|, serial = 3.05581e-07
|L*L'*X-B|, parallel = 2.92997e-07
double
|L*L'*X-B|, serial = 4.72538e-16
|L*L'*X-B|, parallel = 4.25729e-16
std::complex<float>
|L*L'*X-B|, serial = 3.13721e-07
|L*L'*X-B|, parallel = 3.03349e-07
std::complex<double>
|L*L'*X-B|, serial = 4.97572e-16
|L*L'*X-B|, parallel = 4.59068e-16


Go back to Summary of /test programs.