MyraMath
ptrsm2


Source: tests/pdense/ptrsm2.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.
21 #include <myramath/dense/gemm.h>
22 #include <myramath/dense/tril.h>
23 #include <myramath/dense/triu.h>
24 #include <myramath/dense/trsm.h>
25 #include <myramath/dense/herk.h>
26 #include <myramath/dense/potrf.h>
27 
28 // Parallel algorithms.
29 #include <myramath/pdense/ptrsm.h>
30 #include <myramath/pdense/pgemm.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 Number> void test(int I, int J, typename ReflectPrecision<Number>::type tolerance)
42  {
43  typedef typename ReflectPrecision<Number>::type Precision;
44  myra::out() << typestring<Number>() << std::endl;
45  // Make well-conditioned L (a cholesky triangle).
46  auto G = Matrix<Number>::random(I,I);
47  auto L = herk(G,'N');
48  potrf_inplace(L);
49  Number one(1);
50  auto alpha = random<Number>();
51  // Initialize options.
52  auto options = Options::create().set_nthreads(4).set_blocksize(64);
53  // Try all variations of side/op.
54  std::vector<char> sides;
55  sides.push_back('L');
56  sides.push_back('R');
57  std::vector<char> ops;
58  ops.push_back('N');
59  ops.push_back('T');
60  ops.push_back('H');
61  ops.push_back('C');
62  for (int s = 0; s < sides.size(); ++s)
63  for (int o = 0; o < ops.size(); ++o)
64  {
65  char side = sides[s];
66  char op = ops[o];
67  // Generate random X/B
68  auto X = (side == 'L') ? Matrix<Number>::random(I,J) : Matrix<Number>::random(J,I);
69  auto B = (side == 'L') ? (one/alpha)*pgemm(L.make_Matrix(),op,X) : (one/alpha)*pgemm(X,L.make_Matrix(),op);
70  // Backsolve using both trsm() and ptrsm()
71  auto B_serial = B;
72  auto B_parallel = B;
73  trsm_inplace(side,op,L,B_serial,'N',alpha);
74  ptrsm_inplace(side,op,L,B_parallel,'N',alpha,options);
75  // Compare errors.
76  Precision e_serial = frobenius(B_serial-X) / frobenius(X);
77  Precision e_parallel = frobenius(B_parallel-X) / frobenius(X);
78  if (side == 'L')
79  {
80  myra::out() << " |L^" << op << "\\B-X| serial = " << e_serial << std::endl;
81  myra::out() << " |L^" << op << "\\B-X| parallel = " << e_parallel << std::endl;
82  }
83  else if (side == 'R')
84  {
85  myra::out() << " |B/L^" << op << "-X| serial = " << e_serial << std::endl;
86  myra::out() << " |B/L^" << op << "-X| parallel = " << e_parallel << std::endl;
87  }
88  REQUIRE(e_serial < tolerance);
89  REQUIRE(e_parallel < tolerance);
90  }
91  }
92 
93 } // namespace
94 
95 ADD_TEST("ptrsm2","[pdense][parallel]")
96  {
97  int I = 256;
98  int J = 128;
99  test<NumberS>(I,J,1.0e-3f);
100  test<NumberD>(I,J,1.0e-8);
101  test<NumberC>(I,J,1.0e-3f);
102  test<NumberZ>(I,J,1.0e-8);
103  }
Cholesky factorization routines for positive definite matrices.
Interface class for representing subranges of dense Matrix&#39;s.
Tabulates an IxJ matrix. Allows random access, has column major layout to be compatible with BLAS/LAP...
Definition: bdsqr.h:20
Routines for hermitian rank-k updates, a specialized form of Matrix*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
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...
Returns the lower triangle of a dense Matrix.
Returns the upper triangle of a dense Matrix.
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
Simplistic random number functions.
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^N\B-X| serial = 3.94981e-06
|L^N\B-X| parallel = 4.80008e-06
|L^T\B-X| serial = 4.89754e-07
|L^T\B-X| parallel = 4.88912e-07
|L^H\B-X| serial = 4.963e-07
|L^H\B-X| parallel = 4.93816e-07
|L^C\B-X| serial = 4.0229e-06
|L^C\B-X| parallel = 4.892e-06
|B/L^N-X| serial = 5.06035e-07
|B/L^N-X| parallel = 5.02461e-07
|B/L^T-X| serial = 4.07096e-06
|B/L^T-X| parallel = 4.73378e-06
|B/L^H-X| serial = 3.88497e-06
|B/L^H-X| parallel = 4.9363e-06
|B/L^C-X| serial = 4.99073e-07
|B/L^C-X| parallel = 4.95771e-07
double
|L^N\B-X| serial = 2.72498e-15
|L^N\B-X| parallel = 2.44478e-15
|L^T\B-X| serial = 7.87358e-16
|L^T\B-X| parallel = 7.74825e-16
|L^H\B-X| serial = 7.93018e-16
|L^H\B-X| parallel = 7.69663e-16
|L^C\B-X| serial = 2.78493e-15
|L^C\B-X| parallel = 2.52181e-15
|B/L^N-X| serial = 7.8958e-16
|B/L^N-X| parallel = 7.74487e-16
|B/L^T-X| serial = 2.65089e-15
|B/L^T-X| parallel = 2.62559e-15
|B/L^H-X| serial = 2.76936e-15
|B/L^H-X| parallel = 2.48116e-15
|B/L^C-X| serial = 7.87055e-16
|B/L^C-X| parallel = 7.61199e-16
std::complex<float>
|L^N\B-X| serial = 8.12812e-06
|L^N\B-X| parallel = 8.66505e-06
|L^T\B-X| serial = 5.7899e-07
|L^T\B-X| parallel = 5.76473e-07
|L^H\B-X| serial = 5.64767e-07
|L^H\B-X| parallel = 5.65431e-07
|L^C\B-X| serial = 7.98159e-06
|L^C\B-X| parallel = 8.82009e-06
|B/L^N-X| serial = 5.68528e-07
|B/L^N-X| parallel = 5.67803e-07
|B/L^T-X| serial = 8.22145e-06
|B/L^T-X| parallel = 8.25925e-06
|B/L^H-X| serial = 7.41446e-06
|B/L^H-X| parallel = 8.52447e-06
|B/L^C-X| serial = 5.75249e-07
|B/L^C-X| parallel = 5.74935e-07
std::complex<double>
|L^N\B-X| serial = 2.02922e-14
|L^N\B-X| parallel = 1.86986e-14
|L^T\B-X| serial = 9.27742e-16
|L^T\B-X| parallel = 9.30613e-16
|L^H\B-X| serial = 9.68563e-16
|L^H\B-X| parallel = 9.25248e-16
|L^C\B-X| serial = 2.06691e-14
|L^C\B-X| parallel = 1.98845e-14
|B/L^N-X| serial = 9.41747e-16
|B/L^N-X| parallel = 9.25751e-16
|B/L^T-X| serial = 1.85259e-14
|B/L^T-X| parallel = 1.79425e-14
|B/L^H-X| serial = 1.93315e-14
|B/L^H-X| parallel = 1.8566e-14
|B/L^C-X| serial = 9.44295e-16
|B/L^C-X| parallel = 9.02848e-16


Go back to Summary of /test programs.