MyraMath
rcholesky2_partialsolve


Source: tests/multifrontal/rcholesky/rcholesky2_partialsolve.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.
14 #include <myramath/dense/Matrix.h>
19 
20 // Algorithms.
23 #include <myramath/dense/gemm.h>
26 
27 // Solver under test.
29 
30 // Reporting.
31 #include <tests/myratest.h>
32 
33 using namespace myra;
34 
35 namespace {
36 
37 template<class Precision> void test(int I, int J, Precision tolerance)
38  {
39  myra::out() << typestring<Precision>() << std::endl;
40  // Generate A.
41  int N = I*J;
42  auto A = laplacian2<Precision>(I,J);
43  // Options related to reordering. Test input is small, so need to use small
44  // blocks/no globbing to make sure the symbolic factorization is nontrivial
45  typedef multifrontal::Options Options;
46  Options options = Options::create().set_blocksize(8).set_globsize(4).set_nthreads(1);
47  // Reorder A using bisection and factor it.
48  Permutation perm = bisect2(I,J);
49  SparseRCholeskySolver<Precision> solver(A,perm,options);
50  // Make random restriction Ri.
51  std::vector<int> Ri(20,0);
52  for (int i = 0; i < Ri.size(); ++i)
53  Ri[i] = random_int(N);
54  sortunique(Ri);
55  // Make random restriction Rj.
56  std::vector<int> Rj(30,0);
57  for (int j = 0; j < Rj.size(); ++j)
58  Rj[j] = random_int(N);
59  sortunique(Rj);
60  // Form restricted inverse Z = Ri'inv(A)*Rj
61  Matrix<Precision> Z = solver.inverse(Ri,Rj);
62  int K = 15;
63  // Test from the left.
64  {
65  auto B1 = Matrix<Precision>::random(ssize(Rj),K);
66  auto B2 = Matrix<Precision>::random(ssize(Ri),K);
67  Precision error_N = frobenius( gemm(Z,'N',B1) - solver.partialsolve(Ri,Rj,B1,'L','N') );
68  Precision error_T = frobenius( gemm(Z,'T',B2) - solver.partialsolve(Ri,Rj,B2,'L','T') );
69  Precision error_H = frobenius( gemm(Z,'H',B2) - solver.partialsolve(Ri,Rj,B2,'L','H') );
70  Precision error_C = frobenius( gemm(Z,'C',B1) - solver.partialsolve(Ri,Rj,B1,'L','C') );
71  myra::out() << " error in Z^N * B = " << error_N << std::endl;
72  myra::out() << " error in Z^T * B = " << error_T << std::endl;
73  myra::out() << " error in Z^H * B = " << error_H << std::endl;
74  myra::out() << " error in Z^C * B = " << error_C << std::endl;
75  REQUIRE(error_N < tolerance);
76  REQUIRE(error_T < tolerance);
77  REQUIRE(error_H < tolerance);
78  REQUIRE(error_C < tolerance);
79  }
80  // Test from the right.
81  {
82  auto B1 = Matrix<Precision>::random(K,ssize(Ri));
83  auto B2 = Matrix<Precision>::random(K,ssize(Rj));
84  Precision error_N = frobenius( gemm(B1,Z,'N') - solver.partialsolve(Ri,Rj,B1,'R','N') );
85  Precision error_T = frobenius( gemm(B2,Z,'T') - solver.partialsolve(Ri,Rj,B2,'R','T') );
86  Precision error_H = frobenius( gemm(B2,Z,'H') - solver.partialsolve(Ri,Rj,B2,'R','H') );
87  Precision error_C = frobenius( gemm(B1,Z,'C') - solver.partialsolve(Ri,Rj,B1,'R','C') );
88  myra::out() << " error in B * Z^N = " << error_N << std::endl;
89  myra::out() << " error in B * Z^T = " << error_T << std::endl;
90  myra::out() << " error in B * Z^H = " << error_H << std::endl;
91  myra::out() << " error in B * Z^C = " << error_C << std::endl;
92  REQUIRE(error_N < tolerance);
93  REQUIRE(error_T < tolerance);
94  REQUIRE(error_H < tolerance);
95  REQUIRE(error_C < tolerance);
96  }
97  }
98 
99 } // namespace
100 
101 ADD_TEST("rcholesky2_partialsolve","[multifrontal][parallel]")
102  {
103  test<float >(20,20,1.0e-4f);
104  test<double>(20,20,1.0e-10);
105  }
Interface class for representing subranges of dense Matrix&#39;s.
Options pack for routines in /multifrontal.
Definition: Options.h:24
Represents a Permutation matrix, used to reorder rows/columns/etc of various numeric containers...
Definition: Permutation.h:34
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
Reduces a std::vector to its unique entries, and sorts it.
General purpose compressed-sparse-column (CSC) container.
void sortunique(std::vector< T > &v)
Reduces a std::vector to its unique entries, and sorts it.
Definition: sortunique.h:20
Definition: syntax.dox:1
Various utility functions/classes related to scalar Number types.
General purpose dense matrix container, O(i*j) storage.
Sparse direct solver suitable for real symmetric positive definite systems.
Aggregates a (perm, iperm, swaps) triple into a vocabulary type.
Sparse direct solver suitable for real symmetric positive definite systems.
Definition: SparseRCholeskySolver.h:61
Simplistic random number functions.
Helper routines for reordering/filling 2D structured grids. Used by many unit tests.
Variety of routines all for dense Matrix*Matrix multiplies. Delegates to the BLAS.
Range/Iterator types associated with SparseMatrix.
Interface class for representing subranges of contiguous int&#39;s.


Results: [PASS]

float
error in Z^N * B = 8.32962e-08
error in Z^T * B = 1.05689e-07
error in Z^H * B = 1.05689e-07
error in Z^C * B = 8.32962e-08
error in B * Z^N = 1.29292e-07
error in B * Z^T = 1.13806e-07
error in B * Z^H = 1.13806e-07
error in B * Z^C = 1.29292e-07
double
error in Z^N * B = 3.81757e-16
error in Z^T * B = 2.95419e-16
error in Z^H * B = 2.95419e-16
error in Z^C * B = 3.81757e-16
error in B * Z^N = 2.86477e-16
error in B * Z^T = 2.90939e-16
error in B * Z^H = 2.90939e-16
error in B * Z^C = 2.86477e-16


Go back to Summary of /test programs.