/[escript]/trunk/cusplibrary/cusp/precond/ainv.h
ViewVC logotype

Contents of /trunk/cusplibrary/cusp/precond/ainv.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (5 years, 10 months ago) by caltinay
File MIME type: text/plain
File size: 7560 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

1 /*
2 * Copyright 2008-2010 NVIDIA Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*! \file ainv.h
18 * \brief Approximate Inverse (AINV) preconditioner.
19 */
20
21 #pragma once
22
23 #include <cusp/detail/config.h>
24
25 #include <cusp/linear_operator.h>
26 #include <cusp/hyb_matrix.h>
27
28 namespace cusp
29 {
30 namespace precond
31 {
32
33
34 /*! \addtogroup preconditioners Preconditioners
35 * \ingroup preconditioners
36 * \{
37 */
38
39 /*! \p scaled_bridson_ainv : Approximate Inverse preconditoner (from Bridson's "outer product" formulation)
40 * The diagonal matrix is folded into the factorization to reduce operation count during
41 * preconditioner application. Not sure if this is a good idea or not, yet.
42 * This preconditioner allows for a novel dropping strategy, where rather than a fixed
43 * drop tolerance, you can specify now many non-zeroes are allowed per row. The non-zeroes
44 * will be chosen based on largest magnitude. This idea has been applied to IC factorization,
45 * but not AINV as far as I'm aware. See:
46 * Lin, C. and More, J. J. 1999. Incomplete Cholesky Factorizations with Limited Memory.
47 * SIAM J. Sci. Comput. 21, 1 (Aug. 1999), 24-45.
48 * This preconditioner will only work for SPD matrices.
49 *
50 */
51 template <typename ValueType, typename MemorySpace>
52 class scaled_bridson_ainv : public linear_operator<ValueType, MemorySpace>
53 {
54 typedef linear_operator<ValueType, MemorySpace> Parent;
55
56 public:
57 cusp::hyb_matrix<int, ValueType, MemorySpace> w;
58 cusp::hyb_matrix<int, ValueType, MemorySpace> w_t;
59
60 /*! construct a \p ainv preconditioner
61 *
62 * \param A matrix to precondition
63 * \tparam MatrixType matrix
64 * \param ValueType drop_tolerance Tolerance for dropping during factorization
65 * \param nonzero_per_row Count of non-zeroes allowed per row of the factored matrix. If negative or lin_dropping==true, this will be ignored.
66 * \param lin_dropping When true, this will use the dropping strategy from Lin & More, where the per-row count will be based on A's structure.
67 * \param lin_param when lin_dropping set to true, this indicates how many additional non-zeros per row to include
68 */
69 template<typename MatrixTypeA>
70 scaled_bridson_ainv(const MatrixTypeA & A, ValueType drop_tolerance=0.1, int nonzero_per_row=-1, bool lin_dropping=false, int lin_param=1);
71
72 /*! apply the preconditioner to vector \p x and store the result in \p y
73 *
74 * \param x input vector
75 * \param y ouput vector
76 * \tparam VectorType1 vector
77 * \tparam VectorType2 vector
78 */
79 template <typename VectorType1, typename VectorType2>
80 void operator()(const VectorType1& x, VectorType2& y) const;
81 };
82 /*! \}
83 */
84
85
86 /*! \addtogroup preconditioners Preconditioners
87 * \ingroup preconditioners
88 * \{
89 */
90
91 /*! \p bridson_ainv : Approximate Inverse preconditoner (from Bridson's "outer product" formulation)
92 * This preconditioner allows for a novel dropping strategy, where rather than a fixed
93 * drop tolerance, you can specify now many non-zeroes are allowed per row. The non-zeroes
94 * will be chosen based on largest magnitude. This idea has been applied to IC factorization,
95 * but not AINV as far as I'm aware. See:
96 * Lin, C. and More, J. J. 1999. Incomplete Cholesky Factorizations with Limited Memory.
97 * SIAM J. Sci. Comput. 21, 1 (Aug. 1999), 24-45.
98 * This preconditioner will only work for SPD matrices.
99 */
100
101 template <typename ValueType, typename MemorySpace>
102 class bridson_ainv : public linear_operator<ValueType, MemorySpace>
103 {
104 typedef linear_operator<ValueType, MemorySpace> Parent;
105
106 public:
107 cusp::hyb_matrix<int, ValueType, MemorySpace> w;
108 cusp::hyb_matrix<int, ValueType, MemorySpace> w_t;
109 cusp::array1d<ValueType, MemorySpace> diagonals;
110
111 /*! construct a \p ainv preconditioner
112 *
113 * \param A matrix to precondition
114 * \tparam MatrixTypeA matrix
115 * \param ValueType drop_tolerance Tolerance for dropping during factorization
116 * \param nonzero_per_row Count of non-zeroes allowed per row of the factored matrix. If negative or lin_dropping==true, this will be ignored.
117 * \param lin_dropping When true, this will use the dropping strategy from Lin & More, where the per-row count will be based on A's structure.
118 * \param lin_param when lin_dropping set to true, this indicates how many additional non-zeros per row to include
119 */
120 template<typename MatrixTypeA>
121 bridson_ainv(const MatrixTypeA & A, ValueType drop_tolerance=0.1, int nonzero_per_row =-1, bool lin_dropping=false, int lin_param=1);
122
123 /*! apply the preconditioner to vector \p x and store the result in \p y
124 *
125 * \param x input vector
126 * \param y ouput vector
127 * \tparam VectorType1 vector
128 * \tparam VectorType2 vector
129 */
130 template <typename VectorType1, typename VectorType2>
131 void operator()(const VectorType1& x, VectorType2& y) const;
132 };
133 /*! \}
134 */
135
136
137 /*! \addtogroup preconditioners Preconditioners
138 * \ingroup preconditioners
139 * \{
140 */
141
142 /*! \p nonsym_bridson_ainv : Approximate Inverse preconditoner (from Bridson's "outer product" formulation)
143 * The non-symmetric form, which is identical to the standard form in the case of symmetric matrices, but
144 * handles non-symmtric matrices as well. The storage and cost of applying the preconditioner
145 * are about the same, but build time is 2x higher.
146 */
147
148 template <typename ValueType, typename MemorySpace>
149 class nonsym_bridson_ainv : public linear_operator<ValueType, MemorySpace>
150 {
151 typedef linear_operator<ValueType, MemorySpace> Parent;
152
153 public:
154 cusp::hyb_matrix<int, ValueType, MemorySpace> w_t;
155 cusp::hyb_matrix<int, ValueType, MemorySpace> z;
156 cusp::array1d<ValueType, MemorySpace> diagonals;
157
158 /*! construct a \p ainv preconditioner
159 *
160 * \param A matrix to precondition
161 * \tparam MatrixTypeA matrix
162 * \param ValueType drop_tolerance Tolerance for dropping during factorization
163 * \param nonzero_per_row Count of non-zeroes allowed per row of the factored matrix. If negative or lin_dropping==true, this will be ignored.
164 * \param lin_dropping When true, this will use the dropping strategy from Lin & More, where the per-row count will be based on A's structure.
165 * \param lin_param when lin_dropping set to true, this indicates how many additional non-zeros per row to include
166 */
167 template<typename MatrixTypeA>
168 nonsym_bridson_ainv(const MatrixTypeA & A, ValueType drop_tolerance=0.1, int nonzero_per_row=-1, bool lin_dropping=false, int lin_param=1);
169
170 /*! apply the preconditioner to vector \p x and store the result in \p y
171 *
172 * \param x input vector
173 * \param y ouput vector
174 * \tparam VectorType1 vector
175 * \tparam VectorType2 vector
176 */
177 template <typename VectorType1, typename VectorType2>
178 void operator()(const VectorType1& x, VectorType2& y) const;
179 };
180 /*! \}
181 */
182
183 } // end namespace precond
184 } // end namespace cusp
185
186 #include <cusp/precond/detail/ainv.inl>
187

  ViewVC Help
Powered by ViewVC 1.1.26