Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
LinearSolverT.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 IFPEN-CEA
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 * SPDX-License-Identifier: Apache-2.0
17 */
18
23
25
26#include <alien/expression/solver/SolverStat.h>
27
30#include <alien/data/IMatrix.h>
31#include <alien/data/IVector.h>
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36namespace Alien
37{
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42template <class Tag>
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
48template <class Tag>
49String
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
61template <class Tag>
62bool LinearSolver<Tag>::solve(const IMatrix& A, const IVector& b, IVector& x)
63{
64 auto dist = A.impl()->distribution();
65 // solve is a global call
66 // when redistribution, matrix or dist could be null on some subsets of procs
67 // so we return true to don't block
68 // FIXME: sync result ??
69 if (A.impl() == nullptr || dist.parallelMng() == nullptr)
70 return true;
71 // solver is not parallel but dist is
72 if (not m_solver->hasParallelSupport() && dist.isParallel()) {
73 throw FatalErrorException("solver is not parallel");
74 }
75 else {
76 m_solver->updateParallelMng(A.impl()->distribution().parallelMng());
77 }
78
79 SolverStatSentry<KernelSolver> sentry(m_stater, BaseSolverStater::ePrepare);
80 const auto& matrix = A.impl()->get<Tag>();
81 const auto& rhs = b.impl()->get<Tag>();
82 auto& sol = x.impl()->get<Tag>(true);
83 sentry.release();
84
85 SolverStatSentry<KernelSolver> sentry2(m_stater, BaseSolverStater::eSolve);
86 return m_solver->solve(matrix, rhs, sol);
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92template <class Tag>
94{
95 SolverStatSentry<KernelSolver> sentry(m_stater, BaseSolverStater::eInit);
96 m_solver->init();
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102template <class Tag>
104{
105 m_solver->end();
106}
107
108template <class Tag>
109void LinearSolver<Tag>::updateParallelMng(Arccore::MessagePassing::IMessagePassingMng* pm)
110{
111 m_solver->updateParallelMng(pm);
112}
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
116template <class Tag>
117const SolverStat&
119{
120 return m_solver->getSolverStat();
121}
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
125
126template <class Tag>
128{
129 return m_solver->hasParallelSupport();
130}
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
135template <class Tag>
136const SolverStatus&
138{
139 return m_solver->getStatus();
140}
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
145template <class Tag>
148{
149 return m_solver.get();
150}
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155template <class Tag>
156std::shared_ptr<ILinearAlgebra>
158{
159 return m_solver->algebra();
160}
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
164
165} // namespace Alien
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
IMatrix.h.
IVector.h.
LinearSolver.h.
MultiMatrixImpl.h.
MultiVectorImpl.h.
Interface for all matrices.
Definition IMatrix.h:51
virtual MultiMatrixImpl * impl()=0
Get the multimatrix implementation.
Interface for all vectors.
Definition IVector.h:51
virtual MultiVectorImpl * impl()=0
Get the multivector implementation.
void init()
Initialize the linear solver.
const SolverStatus & getStatus() const
Get solver resolution status.
std::unique_ptr< KernelSolver > m_solver
The linear solver kernel.
virtual ~LinearSolver()
Free resources.
void updateParallelMng(Arccore::MessagePassing::IMessagePassingMng *pm)
update parallel_mng, required for redistribution For some solver libraries, Solver is kind of a globa...
Arccore::String getBackEndName() const
Get package back end name.
KernelSolver * implem()
Get kernel solver implementation.
bool hasParallelSupport() const
Indicates if the kernel is parallel.
void end()
Finalize the linear solver.
std::shared_ptr< ILinearAlgebra > algebra() const
Get compatible linear algebra.
const SolverStat & getSolverStat() const
Get statistics on the solve phase.
AlgebraTraits< Tag >::solver_type KernelSolver
The type of the solver.
bool solve(const IMatrix &A, const IVector &b, IVector &x)
Solve the linear system A * x = b.
Arccore::MessagePassing::IMessagePassingMng * parallelMng() const
Get the parallel manager.
const MatrixDistribution & distribution() const
Get the matrix distribution.
const AlgebraTraits< tag >::matrix_type & get() const
Get a specific matrix implementation.
const AlgebraTraits< tag >::vector_type & get() const
Get a specific vector implementation.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17
Structure to store a solver status.