schwz  Generated automatically from develop
solver_tools.hpp (544e47f)
1 #ifndef solver_tools_hpp
2 #define solver_tools_hpp
3 
4 
5 #include <memory>
6 #include <vector>
7 
8 
9 #include <schwarz/config.hpp>
10 #include <settings.hpp>
11 #include <utils.hpp>
12 
13 
14 #if SCHW_HAVE_CHOLMOD
15 #include <cholmod.h>
16 #endif
17 
18 #if SCHW_HAVE_UMFPACK
19 #include <umfpack.h>
20 #endif
21 
22 
23 namespace schwz {
29 namespace SolverTools {
30 
31 #if SCHW_HAVE_CHOLMOD
32 template <typename ValueType, typename IndexType>
33 void solve_direct_cholmod(
34  const Settings &settings, const Metadata<ValueType, IndexType> &metadata,
35  cholmod_common &ch_settings, cholmod_factor *L_factor, cholmod_dense *rhs,
36  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution)
37 {
38  using vec = gko::matrix::Dense<ValueType>;
39  auto local_n = metadata.local_size_x;
40  rhs->x = local_solution->get_values();
41 
42  cholmod_dense *sol = cholmod_solve(CHOLMOD_A, L_factor, rhs, &ch_settings);
43  auto temp =
44  vec::create(settings.executor->get_master(),
45  gko::dim<2>(local_solution->get_size()[0], 1),
46  gko::Array<ValueType>::view(settings.executor->get_master(),
47  local_solution->get_size()[0],
48  (ValueType *)(sol->x)),
49  1);
50 
51  local_solution->copy_from(gko::lend(temp));
52  cholmod_free_dense(&sol, &ch_settings);
53 }
54 #endif
55 
56 
57 #if SCHW_HAVE_UMFPACK
58 template <typename ValueType, typename IndexType>
59 void solve_direct_umfpack(
60  const Settings &settings, const Metadata<ValueType, IndexType> &metadata,
61  void *umfpack_numeric,
62  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_rhs,
63  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution)
64 {}
65 #endif
66 
67 
68 template <typename ValueType, typename IndexType>
69 void solve_direct_ginkgo(
70  const Settings &settings, const Metadata<ValueType, IndexType> &metadata,
71  const std::shared_ptr<gko::solver::LowerTrs<ValueType, IndexType>>
72  &L_solver,
73  const std::shared_ptr<gko::solver::UpperTrs<ValueType, IndexType>>
74  &U_solver,
75  std::shared_ptr<gko::matrix::Dense<ValueType>> &work_vector,
76  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution)
77 {
78  using vec = gko::matrix::Dense<ValueType>;
79  auto vec_size = local_solution->get_size()[0];
80  auto temp_rhs = vec::create(
81  settings.executor, gko::dim<2>(vec_size, 1),
82  gko::Array<ValueType>::view(settings.executor, vec_size,
83  work_vector->get_values() + vec_size),
84  1);
85  L_solver->apply(gko::lend(local_solution), gko::lend(temp_rhs));
86  U_solver->apply(gko::lend(temp_rhs), gko::lend(local_solution));
87 }
88 
89 
90 template <typename ValueType, typename IndexType>
91 inline void solve_iterative_ginkgo(
92  const Settings &settings, const Metadata<ValueType, IndexType> &metadata,
93  const std::shared_ptr<gko::LinOp> &solver,
94  const std::shared_ptr<gko::matrix::Dense<ValueType>> &local_rhs,
95  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution)
96 {
97  solver->apply(gko::lend(local_rhs), gko::lend(local_solution));
98 }
99 
100 
101 template <typename ValueType, typename IndexType>
102 void extract_local_vector(const Settings &settings,
103  const Metadata<ValueType, IndexType> &metadata,
104  gko::matrix::Dense<ValueType> *sub_vector,
105  const gko::matrix::Dense<ValueType> *vector,
106  const IndexType &vec_index)
107 {
108  using vec = gko::matrix::Dense<ValueType>;
109  sub_vector->get_executor()->get_mem_space()->copy_from(
110  settings.executor->get_mem_space().get(), metadata.local_size,
111  vector->get_const_values() + vec_index, sub_vector->get_values());
113  metadata.overlap_size, metadata.overlap_row.get_const_data(),
114  vector->get_const_values(),
115  &(sub_vector->get_values()[metadata.local_size]), copy));
116 }
117 
118 
119 } // namespace SolverTools
120 
121 
122 // Explicit Instantiations
123 #if SCHW_HAVE_CHOLMOD
124 #define DECLARE_FUNCTION(ValueType, IndexType) \
125  void SolverTools::solve_direct_cholmod( \
126  const Settings &, const Metadata<ValueType, IndexType> &, \
127  cholmod_common &, cholmod_factor *, cholmod_dense *, \
128  std::shared_ptr<gko::matrix::Dense<ValueType>> &)
129 INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(DECLARE_FUNCTION);
130 #undef DECLARE_FUNCTION
131 #endif
132 
133 #define DECLARE_FUNCTION(ValueType, IndexType) \
134  void SolverTools::extract_local_vector( \
135  const Settings &, const Metadata<ValueType, IndexType> &, \
136  gko::matrix::Dense<ValueType> *, \
137  const gko::matrix::Dense<ValueType> *, const IndexType &)
138 INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(DECLARE_FUNCTION);
139 #undef DECLARE_FUNCTION
140 
141 #define DECLARE_FUNCTION(ValueType, IndexType) \
142  void SolverTools::solve_iterative_ginkgo( \
143  const Settings &, const Metadata<ValueType, IndexType> &, \
144  const std::shared_ptr<gko::LinOp> &, \
145  std::shared_ptr<gko::matrix::Dense<ValueType>> &, \
146  std::shared_ptr<gko::matrix::Dense<ValueType>> &) \
147  INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(DECLARE_FUNCTION);
148 #undef DECLARE_FUNCTION
149 
150 
151 } // namespace schwz
152 
153 
154 #endif // solver_tools.hpp
The solver metadata struct.
Definition: settings.hpp:319
gko::size_type overlap_size
The size of the overlap between the subdomains.
Definition: settings.hpp:353
Definition: gather.hpp:71
The struct that contains the solver settings and the parameters to be set by the user.
Definition: settings.hpp:77
gko::Array< IndexType > overlap_row
The overlap row indices.
Definition: settings.hpp:480
The Schwarz wrappers namespace.
Definition: comm_helpers.hpp:49
std::shared_ptr< gko::Executor > executor
The ginkgo executor the code is to be executed on.
Definition: settings.hpp:86
gko::size_type local_size_x
The size of the local subdomain matrix + the overlap.
Definition: settings.hpp:343
gko::size_type local_size
The size of the local subdomain matrix.
Definition: settings.hpp:338