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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (5 years, 9 months ago) by caltinay
File MIME type: text/plain
File size: 3259 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-2009 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 diagonal.h
18 * \brief Diagonal preconditioner.
19 *
20 * Contributed by Andrew Trachenko and Nikita Styopin
21 * at SALD Laboratory ( http://www.saldlab.com )
22 */
23
24 #pragma once
25
26 #include <cusp/detail/config.h>
27
28 #include <cusp/linear_operator.h>
29
30 namespace cusp
31 {
32 namespace precond
33 {
34
35 /*! \addtogroup preconditioners Preconditioners
36 * \ingroup preconditioners
37 * \{
38 */
39
40 /*! \p diagonal : diagonal preconditoner (aka Jacobi preconditioner)
41 *
42 * Given a matrix \c A to precondition, the diagonal preconditioner
43 * simply extracts the main diagonal \c D of a \c A and implements
44 * <tt>y = D^-1 x</tt> when applied to a vector \p x.
45 *
46 * Diagonal preconditioning is very inexpensive to use, but has
47 * limited effectiveness. However, if the matrix \p A has poorly
48 * scaled rows then diagonal preconditioning can substantially
49 * reduce the number of solver iterations required to reach
50 * convergence.
51 *
52 * \tparam ValueType Type used for matrix values (e.g. \c float or \c double).
53 * \tparam MemorySpace A memory space (e.g. \c cusp::host_memory or cusp::device_memory)
54 *
55 * The following code snippet demonstrates how to use a
56 * \p diagonal preconditioner to solve a linear system.
57 *
58 * \code
59 * #include <cusp/precond/diagonal.h>
60 * ...
61 *
62 * // allocate storage for solution (x) and right hand side (b)
63 * cusp::array1d<float, cusp::device_memory> x(A.num_rows, 0);
64 * cusp::array1d<float, cusp::device_memory> b(A.num_rows, 1);
65 *
66 * cusp::default_monitor<float> monitor(b, 100, 1e-6);
67 *
68 * // setup preconditioner
69 * cusp::precond::diagonal<float, cusp::device_memory> M(A);
70 *
71 * // solve
72 * cusp::krylov::bicgstab(A, x, b, monitor, M);
73 *
74 * \endcode
75 *
76 */
77 template <typename ValueType, typename MemorySpace>
78 class diagonal : public linear_operator<ValueType, MemorySpace>
79 {
80 typedef linear_operator<ValueType, MemorySpace> Parent;
81 cusp::array1d<ValueType, MemorySpace> diagonal_reciprocals;
82
83 public:
84 /*! construct a \p diagonal preconditioner
85 *
86 * \param A matrix to precondition
87 * \tparam MatrixType matrix
88 */
89 template<typename MatrixType>
90 diagonal(const MatrixType& A);
91
92 /*! apply the preconditioner to vector \p x and store the result in \p y
93 *
94 * \param x input vector
95 * \param y ouput vector
96 * \tparam VectorType1 vector
97 * \tparam VectorType2 vector
98 */
99 template <typename VectorType1, typename VectorType2>
100 void operator()(const VectorType1& x, VectorType2& y) const;
101 };
102 /*! \}
103 */
104
105 } // end namespace precond
106 } // end namespace cusp
107
108 #include <cusp/precond/detail/diagonal.inl>
109

  ViewVC Help
Powered by ViewVC 1.1.26