1 #ifndef INMOST_SOLVER_INCLUDED
2 #define INMOST_SOLVER_INCLUDED
4 #include "inmost_common.h"
5 #include "inmost_sparse.h"
7 #if defined(USE_SOLVER)
10 class SolverInterface;
12 class SolverParameters;
14 enum SolverVerbosityLevel {
15 SolverVerbosityLevel0 = 0,
16 SolverVerbosityLevel1 = 1,
17 SolverVerbosityLevel2 = 2
32 typedef std::string Type;
43 static const Type
ANI;
65 static std::vector<SolverParameters> parameters;
68 static bool is_initialized;
69 static bool is_finalized;
70 SolverInterface *solver;
72 SolverVerbosityLevel versbosity;
73 double preconditioner_time;
74 double iterations_time;
79 static void parseXMLDatabase(
const char *xml_database);
89 typedef std::vector<INMOST_DATA_ENUM_TYPE> storage_type;
90 storage_type global_to_proc;
91 storage_type global_overlap;
92 std::vector<INMOST_DATA_ENUM_TYPE> vector_exchange_recv;
93 std::vector<INMOST_DATA_ENUM_TYPE> vector_exchange_send;
94 std::vector<INMOST_DATA_REAL_TYPE> send_storage;
95 std::vector<INMOST_DATA_REAL_TYPE> recv_storage;
96 std::vector<INMOST_MPI_Request> send_requests;
97 std::vector<INMOST_MPI_Request> recv_requests;
98 std::vector<INMOST_DATA_ENUM_TYPE> extended_indexes;
99 INMOST_DATA_ENUM_TYPE local_vector_begin;
100 INMOST_DATA_ENUM_TYPE local_vector_end;
101 INMOST_DATA_ENUM_TYPE initial_matrix_begin;
102 INMOST_DATA_ENUM_TYPE initial_matrix_end;
103 INMOST_DATA_ENUM_TYPE local_matrix_begin;
104 INMOST_DATA_ENUM_TYPE local_matrix_end;
106 INMOST_MPI_Comm comm;
157 void GetOverlapRegion(INMOST_DATA_ENUM_TYPE proc, INMOST_DATA_ENUM_TYPE &mbeg, INMOST_DATA_ENUM_TYPE &mend)
const;
163 void GetLocalRegion(INMOST_DATA_ENUM_TYPE proc, INMOST_DATA_ENUM_TYPE &mbeg, INMOST_DATA_ENUM_TYPE &mend)
const;
168 void GetVectorRegion(INMOST_DATA_ENUM_TYPE &mbeg, INMOST_DATA_ENUM_TYPE &mend)
const {
169 mbeg = local_vector_begin;
170 mend = local_vector_end;
173 INMOST_DATA_ENUM_TYPE
GetRank()
const {
return rank; }
175 INMOST_DATA_ENUM_TYPE
GetSize()
const {
return size; }
188 void Integrate(INMOST_DATA_REAL_TYPE *inout, INMOST_DATA_ENUM_TYPE num)
const;
190 INMOST_MPI_Comm
GetComm()
const {
return comm; }
194 assert(!send_requests.empty());
195 return &send_requests[0];
200 assert(!recv_requests.empty());
201 return &recv_requests[0];
204 INMOST_DATA_ENUM_TYPE
GetSendRequestsSize() {
return static_cast<INMOST_DATA_ENUM_TYPE
>(send_requests.size()); }
206 INMOST_DATA_ENUM_TYPE
GetRecvRequestsSize() {
return static_cast<INMOST_DATA_ENUM_TYPE
>(recv_requests.size()); }
209 assert(!vector_exchange_send.empty());
210 return &vector_exchange_send[0];
213 INMOST_DATA_ENUM_TYPE
GetSendExchangeSize() {
return static_cast<INMOST_DATA_ENUM_TYPE
>(send_storage.size()); }
216 assert(!vector_exchange_recv.empty());
217 return &vector_exchange_recv[0];
220 INMOST_DATA_ENUM_TYPE
GetRecvExchangeSize() {
return static_cast<INMOST_DATA_ENUM_TYPE
>(recv_storage.size()); }
237 Solver(std::string solverName, std::string prefix =
"", INMOST_MPI_Comm _comm = INMOST_MPI_COMM_WORLD);
260 void SetVerbosityLevel(SolverVerbosityLevel level);
283 static void Initialize(
int *argc,
char ***argv,
const char *database = NULL);
443 INMOST_DATA_REAL_TYPE
Condest(INMOST_DATA_REAL_TYPE tol, INMOST_DATA_ENUM_TYPE maxits = 100);
458 typedef std::vector<std::string>::iterator solvers_names_iterator_t;
459 typedef std::vector<SolverParameters>::iterator solver_parameters_iterator_t;
464 void Initialize(
const std::string &path);
468 void Enable(
const std::string &solver_name,
const std::string &solver_prefix);
470 void Disable(
const std::string &solver_name,
const std::string &solver_prefix);
472 bool isEnabled(
const std::string &solver_name,
const std::string &solver_prefix);
474 bool isDisabled(
const std::string &solver_name,
const std::string &solver_prefix);
476 void SolverOptimize(
Solver &solver,
bool use_last_suggestion =
false);
478 void SolverOptimizeSaveResult(
Solver &solver,
double metrics,
bool is_good);
480 void DestroySavedOptimizer(
Solver &solver);
Base class for low level parallel operations with objects of Solver class.
INMOST_MPI_Comm GetComm() const
Get the communicator which the solver is associated with.
INMOST_DATA_ENUM_TYPE GetProcessor(INMOST_DATA_ENUM_TYPE gind) const
Retrieve the processor number by binary search for the specified global index.
INMOST_MPI_Request * GetSendRequests()
MPI structures that hold information on sent data.
void Clear()
Clear all structures and data.
INMOST_DATA_ENUM_TYPE GetRank() const
Get the rank of the current communicator, i.e. the current process index.
OrderInfo & operator=(OrderInfo const &other)
Assign all structures.
INMOST_DATA_ENUM_TYPE GetSendRequestsSize()
Total number of send requests.
void Update(Sparse::Vector &x)
Update the shared data in parallel vector.
~OrderInfo()
Clears all data.
void RestoreVector(Sparse::Vector &v) const
Restore initial nonparallel state of the Vector.
void GetLocalRegion(INMOST_DATA_ENUM_TYPE proc, INMOST_DATA_ENUM_TYPE &mbeg, INMOST_DATA_ENUM_TYPE &mend) const
Get the local index region for the specified processor.
void RestoreMatrix(Sparse::Matrix &m)
Restore initial nonparallel state of the Matrix with no overlap.
INMOST_DATA_ENUM_TYPE GetRecvExchangeSize()
Size of the array used to receive data.
bool & HaveMatrix()
Return true if Matrix data have already been specified.
void PrepareVector(Sparse::Vector &v) const
Prepare parallel state of the Vector.
OrderInfo(const OrderInfo &other)
Copy all structures.
INMOST_DATA_ENUM_TYPE * GetRecvExchangeArray()
Request raw acces to array used to receive data.
INMOST_MPI_Request * GetRecvRequests()
MPI structures that hold information on posted receive requests.
void Integrate(INMOST_DATA_REAL_TYPE *inout, INMOST_DATA_ENUM_TYPE num) const
Get the sum of num elements of real array on all processes.
void PrepareMatrix(Sparse::Matrix &m, INMOST_DATA_ENUM_TYPE overlap)
Prepare parallel state of the Matrix with specified overlap size.
INMOST_DATA_ENUM_TYPE GetSendExchangeSize()
Size of the array used to send data.
void Accumulate(Sparse::Vector &x)
Sum shared values in parallel vector.
INMOST_DATA_ENUM_TYPE * GetSendExchangeArray()
Request raw access to array used to send data.
void GetOverlapRegion(INMOST_DATA_ENUM_TYPE proc, INMOST_DATA_ENUM_TYPE &mbeg, INMOST_DATA_ENUM_TYPE &mend) const
Get the overlap index region for the specified processor.
INMOST_DATA_ENUM_TYPE GetRecvRequestsSize()
Total number of posted receive requests.
OrderInfo()
Default initialize all structures.
void GetVectorRegion(INMOST_DATA_ENUM_TYPE &mbeg, INMOST_DATA_ENUM_TYPE &mend) const
Get the local index region for the current processor.
INMOST_DATA_ENUM_TYPE GetSize() const
Get the size of the current communicator, i.e. the total number of processes used.
Main class to set and solve linear system.
void SetParameterEnum(std::string name, INMOST_DATA_ENUM_TYPE value)
Backward-compatibility access to integer-typed parameters.
static const Type INNER_DDPQILUC
inner Solver based on BiCGStab(L) solver with second order Crout-ILU with inversed-based condition es...
INMOST_DATA_ENUM_TYPE Iterations() const
Return the number of iterations performed by the last solution.
SolverVerbosityLevel VerbosityLevel() const
Return the solver verbosity specified level of the current solver.
static bool isFinalized()
Checks the stage of parallel solution is finalized.
const std::string SolutionMetadataLine(const std::string &delimiter) const
Get the useful info of the last solution.
static void Finalize()
Finalize the stage of parallel solution.
static const Type PETSc
external Solver PETSc,
bool Solve(Sparse::Vector &RHS, Sparse::Vector &SOL)
Solver the linear system: A*x = b.
const std::string ReturnReason() const
Get the reason of convergence or divergence of the last solution.
static const Type ANI
external Solver from ANI3D based on ILU2 (sequential Fortran version),
void SetParameter(std::string name, std::string value)
static const Type Trilinos_Ifpack
external Solver AztecOO with Ifpack preconditioner.
static const Type Trilinos_Belos
external Solver Belos from Trilinos package, currently without preconditioner.
INMOST_DATA_REAL_TYPE Residual() const
Return the final precondioned residual achieved by the last solution.
static bool isSolverAvailable(std::string name)
Checks if solver available.
static bool isInitialized()
Checks the stage of parallel solution is initialized.
bool IsSolved() const
Return the last solution successfullness.
~Solver()
Delete solver and associated data.
void SetParameterReal(std::string name, INMOST_DATA_REAL_TYPE value)
Backward-compatibility access to real-typed parameters.
static const Type Trilinos_ML
external Solver AztecOO with ML preconditioner.
double PreconditionerTime() const
Return the time of preconditioner evaluation by the last solution.
static const Type K3BIILU2
inner K3BIILU2 Solver (BIILU2 parallel version).
Solver(std::string solverName, std::string prefix="", INMOST_MPI_Comm _comm=INMOST_MPI_COMM_WORLD)
Main constructor of the solver.
std::string SolverPrefix() const
Return the solver user specified name of the current solver.
static const Type INNER_MPTILU2
inner Solver based on BiCGStab(L) solver with second order ILU and maximum product transversal reorde...
Solver & operator=(const Solver &other)
Assign a solver.
static const Type SUPERLU
external Solver SuperLU
static const Type Trilinos_Aztec
external Solver AztecOO from Trilinos package.
std::string SolverName() const
Return the solver name.
static const Type INNER_ILU2
inner Solver based on BiCGStab(L) solver with second order ILU factorization as preconditioner.
Solver(const Solver &other)
Copy a solver.
static const Type INNER_MLMPTILUC
inner Solver based on BiCGStab(L) solver with second order Crout-ILU with inversed-based condition es...
INMOST_DATA_REAL_TYPE Condest(INMOST_DATA_REAL_TYPE tol, INMOST_DATA_ENUM_TYPE maxits=100)
Computes the smallest and the largest eigenvalue with the power method.
static const Type FCBIILU2
external FCBIILU2 Solver (BIILU2 parallel F2C version).
static void Initialize(int *argc, char ***argv, const char *database=NULL)
Initialize the stage of parallel solution.
static std::vector< std::string > getAvailableSolvers()
Return the list of all available solvers.
static const Type INNER_MPTILUC
inner Solver based on BiCGStab(L) solver with second order Crout-ILU with inversed-based condition es...
std::string GetParameter(std::string name) const
Get the solver output parameter.
void SetMatrix(Sparse::Matrix &A, bool ModifiedPattern=true, bool OldPreconditioner=false)
Set the matrix and construct the preconditioner.
std::string GetReason()
Backward-compatibility acces to return reason.
double IterationsTime() const
Return the time of iteration stage by the last solution.
bool Clear()
Clear all internal data of the current solver including matrix, preconditioner etc.
Class to store the distributed sparse matrix by compressed rows.
Distributed vector class.