1 #ifndef solver_tools_hpp 2 #define solver_tools_hpp 9 #include <schwarz/config.hpp> 10 #include <settings.hpp> 29 namespace SolverTools {
32 template <
typename ValueType,
typename IndexType>
33 void solve_direct_cholmod(
35 cholmod_common &ch_settings, cholmod_factor *L_factor, cholmod_dense *rhs,
36 std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution)
38 using vec = gko::matrix::Dense<ValueType>;
40 rhs->x = local_solution->get_values();
42 cholmod_dense *sol = cholmod_solve(CHOLMOD_A, L_factor, rhs, &ch_settings);
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)),
51 local_solution->copy_from(gko::lend(temp));
52 cholmod_free_dense(&sol, &ch_settings);
58 template <
typename ValueType,
typename IndexType>
59 void solve_direct_umfpack(
61 void *umfpack_numeric,
62 std::shared_ptr<gko::matrix::Dense<ValueType>> &local_rhs,
63 std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution)
68 template <
typename ValueType,
typename IndexType>
69 void solve_direct_ginkgo(
71 const std::shared_ptr<gko::solver::LowerTrs<ValueType, IndexType>>
73 const std::shared_ptr<gko::solver::UpperTrs<ValueType, IndexType>>
75 std::shared_ptr<gko::matrix::Dense<ValueType>> &work_vector,
76 std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution)
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),
85 L_solver->apply(gko::lend(local_solution), gko::lend(temp_rhs));
86 U_solver->apply(gko::lend(temp_rhs), gko::lend(local_solution));
90 template <
typename ValueType,
typename IndexType>
91 inline void solve_iterative_ginkgo(
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)
97 solver->apply(gko::lend(local_rhs), gko::lend(local_solution));
101 template <
typename ValueType,
typename IndexType>
102 void extract_local_vector(
const Settings &settings,
104 gko::matrix::Dense<ValueType> *sub_vector,
105 const gko::matrix::Dense<ValueType> *vector,
106 const IndexType &vec_index)
108 using vec = gko::matrix::Dense<ValueType>;
109 sub_vector->get_executor()->get_mem_space()->copy_from(
111 vector->get_const_values() + vec_index, sub_vector->get_values());
114 vector->get_const_values(),
115 &(sub_vector->get_values()[metadata.
local_size]), copy));
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 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 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 154 #endif // solver_tools.hpp
Definition: gather.hpp:71
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
std::shared_ptr< gko::Executor > executor
The ginkgo executor the code is to be executed on.
Definition: settings.hpp:86