MyraMath
rldlt2_saddle1


Source: tests/multifrontal/rldlt/rldlt2_saddle1.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/Vector.h>
21 
22 // Algorithms.
28 #include <myramath/sparse/gemv.h>
29 #include <myramath/multifrontal/detail/restriction.h>
32 
33 // Solver under test.
35 
36 // Reporting.
37 #include <tests/myratest.h>
38 
39 using namespace myra;
40 
41 namespace detail {
42 
43 template<class Precision>
44 void test_saddle1(const SparseMatrix<Precision>& A, const Permutation& P, multifrontal::Options options, Precision tolerance)
45  {
46  SparseRLDLTSolver<Precision> solver(A,P,options);
47  // Check A*x = b solution.
48  int N = solver.size();
49  auto b = Vector<Precision>::random(N);
50  auto x = b;
51  solver.solve(x.column());
52  Precision error = euclidean( gemv(A,x) - b );
53  myra::out() << "|A*x-b| = " << error << std::endl;
54  myra::out() << "A-flops = " << solver.tree().n_work_llt() << std::endl;
55  REQUIRE( error < tolerance );
56  }
57 
58 template<class Precision>
59 void test_saddle1(int I, int J, int K, Precision tolerance)
60  {
61  // Generate system with saddle point structure, A = [L R; R' 0], where L is
62  // a graph laplacian and R is some restriction of dirichlet constraints.
63  // .. laplacian part L, sized IxJ
64  int N = I*J;
65  SparseMatrix<Precision> L = laplacian2<Precision>(I,J);
66  // .. restriction part R, enforces K random constraints
67  std::vector<int> Ri;
68  for (int k = 0; k < K; ++k)
69  Ri.push_back( random_int(N) );
70  sortunique(Ri);
71  K = ssize(Ri);
72  using namespace multifrontal::detail;
73  SparseMatrix<Precision> R = restriction<Precision>(N,Ri);
74  // .. transpose part R'
75  SparseMatrix<Precision> Rt = transpose(R);
76  // .. zero part 0
78  // Concatenate system.
79  SparseMatrix<Precision> A = bothcat(L,R,Rt,Z);
80 
81  // Check the flop count to solve just L.
82  typedef multifrontal::Options Options;
83  Options options = Options::create().set_blocksize(1).set_globsize(1).set_nthreads(1);
84  Permutation P = reorder(L.pattern());
85  myra::out() << "L-flops = " << AssemblyTree(L.pattern(),P,options).n_work_llt() << std::endl;
86 
87  // Run the test with various permutations ..
88 
89  // .. P0, natural order
90  std::vector<int> natural(N+K,-1);
91  for (int n = 0; n < N+K; ++n)
92  natural[n] = n;
94  test_saddle1(A,P0,options,tolerance);
95 
96  // .. P1, reversed order
97  std::vector<int> reversed(N+K,-1);
98  for (int n = 0; n < N+K; ++n)
99  reversed[n] = N+K-1-n;
100  Permutation P1 = Permutation::from_iperm(reversed);
101  test_saddle1(A,P1,options,tolerance);
102 
103  // .. P2, from reorder()
104  Permutation P2 = reorder(A.pattern());
105  test_saddle1(A,P2,options,tolerance);
106 
107  // .. P3, from mmd()
108  Permutation P3 = mmd(A.pattern());
109  test_saddle1(A,P3,options,tolerance);
110 
111  }
112 
113 } // namespace detail
114 
115 ADD_TEST("rldlt2_saddle1","[multifrontal]")
116  {
117  int IJK = 20;
118  ::detail::test_saddle1<float >(IJK,IJK,IJK, 1.0e-4f);
119  ::detail::test_saddle1<double>(IJK,IJK,IJK, 1.0e-10);
120  }
Routines for computing euclidean norm of a Vector/VectorRange, or normalizing a Vector/VectorRange to...
Returns a transposed copy of a SparseMatrix.
Routines to concatenate SparseMatrix&#39;s in two-by-two fashion.
static Permutation from_iperm(const intCRange &iperm)
Delegates to one of the tagged constructors above.
Definition: Permutation.cpp:198
Options pack for routines in /multifrontal.
Definition: Options.h:24
static SparseMatrix< Number > zeros(int I, int J)
Generates a zero-valued SparseMatrix of specified size. Empty, no storage required.
Definition: SparseMatrix.cpp:501
Represents a Permutation matrix, used to reorder rows/columns/etc of various numeric containers...
Definition: Permutation.h:34
Symbolic analysis data structure for all multifrontal solvers.
Definition: AssemblyTree.h:38
Interface class for representing subranges of dense Vector&#39;s.
Sparse direct solver suitable for real symmetric indefinite systems.
Definition: SparseRLDLTSolver.h:61
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
static Vector< Number > random(int N)
Generates a random Vector of specified size.
Definition: Vector.cpp:276
Definition: syntax.dox:1
Permutation mmd(const PatternRange &A)
Reorders A for reduced fill-in using multiple minimum degree.
Definition: random.cpp:45
Various utility functions/classes related to scalar Number types.
Signatures for sparse matrix * dense vector multiplies. All delegate to gemm() under the hood...
PatternRange pattern() const
Returns the nonzero Pattern over all of A(:,:)
Definition: SparseMatrix.cpp:221
Range/Iterator types associated with Pattern.
Container for either a column vector or row vector (depends upon the usage context) ...
Container class for a sparse nonzero pattern, used in reordering/symbolic analysis.
Aggregates a (perm, iperm, swaps) triple into a vocabulary type.
Minimum degree algorithms, for computing fill-minimizing permutations.
Computes a fill-reducing Permutation for a structurally symmetric sparse A.
Sparse direct solver suitable for real symmetric indefinite systems.
Stores an IxJ matrix A in compressed sparse column format.
Definition: bothcat.h:23
Helper routines for reordering/filling 2D structured grids. Used by many unit tests.
Range/Iterator types associated with SparseMatrix.
Interface class for representing subranges of contiguous int&#39;s.


Results: [PASS]

L-flops = 33577
|A*x-b| = 2.60667e-06
A-flops = 98773
|A*x-b| = 2.62035e-06
A-flops = 82951
|A*x-b| = 2.15171e-06
A-flops = 36449
|A*x-b| = 2.086e-06
A-flops = 47682
L-flops = 34879
|A*x-b| = 5.19611e-15
A-flops = 100000
|A*x-b| = 5.75119e-15
A-flops = 83614
|A*x-b| = 4.60797e-15
A-flops = 42835
|A*x-b| = 4.1312e-15
A-flops = 54197


Go back to Summary of /test programs.