schwz  Generated automatically from develop
solve.hpp (228ce7a)
1 
2 /*******************************<SCHWARZ LIB LICENSE>***********************
3 Copyright (c) 2019, the SCHWARZ LIB authors
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ******************************<SCHWARZ LIB LICENSE>*************************/
33 
34 
35 #ifndef solve_hpp
36 #define solve_hpp
37 
38 #include <memory>
39 #include <vector>
40 
41 #include <settings.hpp>
42 
43 #include <communicate.hpp>
44 #include <conv_tools.hpp>
45 #include <solver_tools.hpp>
46 
47 
48 namespace schwz {
49 
50 
61 template <typename ValueType = gko::default_precision,
62  typename IndexType = gko::int32,
63  typename MixedValueType = gko::default_precision>
64 class Solve : public Settings {
65 public:
66  using ResidualCriterionFactory =
67  typename gko::stop::ResidualNormReduction<ValueType>::Factory;
68  using IterationCriterionFactory = typename gko::stop::Iteration::Factory;
69 
70  Solve() = default;
71 
72  Solve(const Settings &settings);
73 
74  friend class Initialize<ValueType, IndexType>;
75 
76 protected:
77  std::shared_ptr<gko::matrix::Dense<ValueType>> local_residual_vector;
78 
79  std::shared_ptr<gko::matrix::Dense<ValueType>> residual_vector;
80 
81  std::shared_ptr<gko::Array<IndexType>> convergence_vector;
82 
83  std::shared_ptr<gko::Array<IndexType>> convergence_sent;
84 
85  std::shared_ptr<gko::Array<IndexType>> convergence_local;
86 
90  MPI_Win window_residual_vector;
91 
95  MPI_Win window_convergence;
96 
110  void setup_local_solver(
111  const Settings &settings, Metadata<ValueType, IndexType> &metadata,
112  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
113  &local_matrix,
114  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
115  &triangular_factor_l,
116  std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
117  &triangular_factor_u,
118  std::shared_ptr<gko::matrix::Permutation<IndexType>> &local_perm,
119  std::shared_ptr<gko::matrix::Permutation<IndexType>> &local_inv_perm,
120  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_rhs);
121 
122 
131  void compute_local_factors(
132  const Settings &settings,
133  const Metadata<ValueType, IndexType> &metadata,
134  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
135  &local_matrix);
136 
137 
150  void local_solve(
151  const Settings &settings, Metadata<ValueType, IndexType> &metadata,
152  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
153  &local_matrix,
154  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
155  &triangular_factor_l,
156  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
157  &triangular_factor_u,
158  std::shared_ptr<gko::matrix::Permutation<IndexType>> &local_perm,
159  std::shared_ptr<gko::matrix::Permutation<IndexType>> &local_inv_perm,
160  std::shared_ptr<gko::matrix::Dense<ValueType>> &work_vector,
161  std::shared_ptr<gko::matrix::Dense<ValueType>> &init_guess,
162  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution);
163 
181  void check_convergence(
182  const Settings &settings, Metadata<ValueType, IndexType> &metadata,
184  &comm_struct,
185  std::shared_ptr<gko::Array<IndexType>> &convergence_vector,
186  const std::shared_ptr<gko::matrix::Dense<ValueType>>
187  &global_old_solution,
188  const std::shared_ptr<gko::matrix::Dense<ValueType>> &global_solution,
189  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
190  &local_matrix,
191  std::shared_ptr<gko::matrix::Dense<ValueType>> &work_vector,
192  ValueType &local_residual_norm, ValueType &local_residual_norm0,
193  ValueType &global_residual_norm, ValueType &global_residual_norm0,
194  int &num_converged_procs);
195 
211  void check_global_convergence(
212  const Settings &settings, Metadata<ValueType, IndexType> &metadata,
214  &comm_struct,
215  std::shared_ptr<gko::Array<IndexType>> &convergence_vector,
216  ValueType &local_resnorm, ValueType &local_resnorm0,
217  ValueType &global_resnorm, ValueType &global_resnorm0,
218  int &converged_all_local, int &num_converged_procs);
219 
234  bool check_local_convergence(
235  const Settings &settings, Metadata<ValueType, IndexType> &metadata,
236  const std::shared_ptr<gko::matrix::Dense<ValueType>> &global_solution,
237  const std::shared_ptr<gko::matrix::Dense<ValueType>>
238  &global_old_solution,
239  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
240  &local_matrix,
241  std::shared_ptr<gko::matrix::Dense<ValueType>> &work_vector,
242  ValueType &local_resnorm, ValueType &local_resnorm0);
243 
253  void update_residual(
254  const Settings &settings,
255  std::shared_ptr<gko::matrix::Dense<ValueType>> &global_solution,
256  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
257  &local_matrix,
258  const std::shared_ptr<gko::matrix::Dense<ValueType>>
259  &global_old_solution);
260 
274  void compute_residual_norm(
275  const Settings &settings,
276  const Metadata<ValueType, IndexType> &metadata,
277  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
278  &global_matrix,
279  const std::shared_ptr<gko::matrix::Dense<ValueType>> &global_solution,
280  const std::shared_ptr<gko::matrix::Dense<ValueType>> &global_rhs,
281  ValueType &mat_norm, ValueType &rhs_norm, ValueType &sol_norm,
282  ValueType &residual_norm);
283 
287  void clear(Settings &settings);
288 
289 private:
293  std::shared_ptr<gko::LinOp> solver;
294 
298  std::shared_ptr<gko::stop::Combined::Factory> combined_criterion;
299 
300  // /**
301  // * The local iterative solver iteration criterion.
302  // */
303  // std::shared_ptr<IterationCriterionFactory> iteration_criterion;
304 
308  std::shared_ptr<gko::log::Record> record_logger;
309 
313  std::shared_ptr<gko::solver::LowerTrs<ValueType, IndexType>> L_solver;
314 
318  std::shared_ptr<gko::solver::UpperTrs<ValueType, IndexType>> U_solver;
319 
320 #if SCHW_HAVE_CHOLMOD
321  struct cholmod {
322  int num_nonzeros;
323  int num_rows;
324 
325  cholmod_common settings;
326  cholmod_sparse *system_matrix;
327  cholmod_dense *rhs;
328  cholmod_factor *L_factor;
329  int sorted;
330  int packed;
331  int stype;
332  int xtype;
333  };
334  cholmod cholmod;
335 #endif
336 
337 #if SCHW_HAVE_UMFPACK
338  struct umfpack {
339  int factor_l_nnz;
340  int factor_u_nnz;
341  int nz_udiag;
342  int n_row;
343  int n_col;
344  int do_reciproc;
345  void *numeric;
346  std::shared_ptr<gko::matrix::Dense<ValueType>> row_scale;
347  int status;
348  double control[UMFPACK_CONTROL];
349  double info[UMFPACK_INFO];
350  };
351  umfpack umfpack;
352 #endif
353 
354  Settings settings;
356 };
357 
358 
359 } // namespace schwz
360 
361 
362 #endif // solve.hpp
The solver metadata struct.
Definition: settings.hpp:319
The Solver class the provides the solver and the convergence checking methods.
Definition: solve.hpp:64
The communication struct used to store the communication data.
Definition: communicate.hpp:67
The struct that contains the solver settings and the parameters to be set by the user.
Definition: settings.hpp:77
The Schwarz wrappers namespace.
Definition: comm_helpers.hpp:49
The initialization class that provides methods for initialization of the solver.
Definition: initialization.hpp:72