Commit 447145dd authored by Dmitry Bagaev's avatar Dmitry Bagaev
Browse files

More improvements in k3biilu2 interface

parent d5d188e7
#include "SolverK3BIILU2.h"
#include "solver_k3biilu2.h"
#include <Source/Misc/utils.h>
namespace INMOST {
......@@ -49,10 +50,17 @@ namespace INMOST {
void SolverK3BIILU2::Setup(int *argc, char ***argv, SolverParameters &p) {
SolverInitDataK3biilu2(&solver_data, communicator, p.solverPrefix.c_str());
SolverInitializeK3biilu2(solver_data, argc, argv, p.internalFile.c_str());
if (p.internalFile != "") {
SolverInitializeK3biilu2(solver_data, argc, argv, p.internalFile.c_str());
} else {
for (parameters_iterator_t parameter = p.parameters.begin(); parameter < p.parameters.end(); parameter++) {
this->SetParameter((*parameter).first, (*parameter).second);
}
}
}
void SolverK3BIILU2::SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner) {
double time_start = Timer();
bool modified_pattern = ModifiedPattern;
//~ if( A.comm != comm ) throw DifferentCommunicatorInSolver;
if (matrix_data == NULL) {
......@@ -77,7 +85,7 @@ namespace INMOST {
ibl[0] = 0;
int n = A.Size();
#if defined(USE_MPI)
INMOST_DATA_ENUM_TYPE mbeg,mend;
INMOST_DATA_ENUM_TYPE mbeg, mend;
A.GetInterval(mbeg, mend);
n = mend - mbeg;
int block_end = mend;
......@@ -119,6 +127,7 @@ namespace INMOST {
}
MatrixFinalizeK3biilu2(matrix_data);
SolverSetMatrixK3biilu2(solver_data, matrix_data, modified_pattern, OldPreconditioner);
time_prec = Timer() - time_start;
}
bool SolverK3BIILU2::Solve(INMOST::Sparse::Vector &RHS, INMOST::Sparse::Vector &SOL) {
......@@ -141,6 +150,7 @@ namespace INMOST {
bool result = SolverSolveK3biilu2(solver_data, rhs_data, solution_data);
if (result) VectorLoadK3biilu2(solution_data, &SOL[vbeg]);
iter_time = solver_data->dstat[9];
return result;
}
......@@ -157,23 +167,33 @@ namespace INMOST {
}
std::string SolverK3BIILU2::GetParameter(std::string name) const {
std::cout << "SolverK3BIILU2::GetParameter unsupported operation" << std::endl;
//throw INMOST::SolverUnsupportedOperation;
if (name == "time_prec") return INMOST::to_string(time_prec);
if (name == "time_iter") return INMOST::to_string(iter_time);
if (name == "time_total") return INMOST::to_string(time_prec + iter_time);
if (name == "prec_density") return INMOST::to_string(solver_data->dstat[0]);
if (name == "pivot_mod") return INMOST::to_string(solver_data->istat[0]);
std::cout << "Parameter " << name << " is unknown" << std::endl;
return "";
}
void SolverK3BIILU2::SetParameter(std::string name, std::string value) {
const char *val = value.c_str();
if (name == "msglev") solver_data->pParIter->msglev = atoi(val);
else if (name == "kovl") solver_data->pParams->ncycle = atoi(val);
else if (name == "tau") {
solver_data->pParams->tau1 = atof(val);
solver_data->pParams->tau2 = -1.0;
} else if (name == "nit") solver_data->pParIter->maxit = atoi(val);
else if (name == "eps") solver_data->pParIter->eps = atof(val);
else std::cout << "Parameter " << name << " is unknown" << std::endl;
}
const INMOST_DATA_ENUM_TYPE SolverK3BIILU2::Iterations() const {
return static_cast<INMOST_DATA_ENUM_TYPE>(SolverIterationNumberK3biilu2(solver_data));
return static_cast<INMOST_DATA_ENUM_TYPE>(solver_data->istat[2]);
}
const INMOST_DATA_REAL_TYPE SolverK3BIILU2::Residual() const {
return SolverResidualNormK3biilu2(solver_data);
return solver_data->dstat[2];
}
const std::string SolverK3BIILU2::ReturnReason() const {
......
......@@ -11,6 +11,9 @@ namespace INMOST {
bcg_k3biilu2 *solver_data;
matrix_k3biilu2 *matrix_data;
INMOST_DATA_ENUM_TYPE local_size, global_size;
double time_prec;
double iter_time;
public:
SolverK3BIILU2();
......
......@@ -23,25 +23,6 @@
#endif
//getline(is, s); //1 skip iext
//getline(is, s); //2 skip mtx filename
//getline(is, s); //3 skip rhs filename
//getline(is, s);
//sscanf(s.c_str(), "%lg", &parIter.eps); //4 eps
//getline(is, s);
//sscanf(s.c_str(), "%d", &parIter.maxit); //5 maxit
//getline(is, s);
//sscanf(s.c_str(), "%d", &parIter.niter_cycle); //6 kgmr
//getline(is, s);
//sscanf(s.c_str(), "%d", &parIter.ncoef); //7 kdeg
//getline(is, s);
//sscanf(s.c_str(), "%d", &parPrec.ncycle); //8 kovl
//getline(is, s);
//sscanf(s.c_str(), "%lg", &parPrec.tau1); //9 tau
//parPrec.tau2 = -1.0;
//parIter.ittype = (parIter.niter_cycle > 1) ? 1 : 0;
////? msglev
void ParametersDefault(ParIter &parIter, k3d::SParams &parPrec) {
parIter.ittype = 0; // 0 - BiCGStab; 1,2,3 - GMRES(niter_cycle); 2 - +Poly(ncoef)_BiCGStab; 3 - +Poly(ncoef)_GMRESb(niter_cycle2)
parIter.niter_cycle = 1; // outer GMRES cycle (=kgmr by IEK); 1 - BiCGStab
......@@ -50,7 +31,7 @@ void ParametersDefault(ParIter &parIter, k3d::SParams &parPrec) {
parIter.eps = 1e-6; // the residual precision: ||r|| < eps * ||b||; eps=1e-6
parIter.maxit = 999; // number of iterations permitted; maxit=999
parIter.ichk = 5; // number of skipped iterations to check the convergence
parIter.msglev = 2; // messages level; msglev=0 for silent; msglev>0 to output solution statistics
parIter.msglev = 0; // messages level; msglev=0 for silent; msglev>0 to output solution statistics
parPrec.ncycle = 3;
parPrec.tau1 = 3e-3;
......@@ -125,7 +106,10 @@ int k3biilu2_bcg(
if (pParIter->msglev > 0)
std::cout << " K3: prec_extend=" << prec_extend << " density=" << density << " scpiv_min=" << scpiv_min << " scpiv_max=" << scpiv_max
<< " nmodif=" << nmodif << " piv_min=" << piv_min << " piv_max=" << piv_max << " dtime_fct=" << dtime_fct << endl;
istat[0] = nmodif;
dstat[0] = density;
dstat[7] = dtime_fct;
// } else {
// T(cout<<"HHHHH k3biilu2_bcg: else (job == 0)\n";)//DB!
//pSolver->PrepareMatrix((void *)&comm, np, pblks, pblk2cpu,
......@@ -146,8 +130,11 @@ int k3biilu2_bcg(
if (pParIter->msglev > 0)
std::cout << " K3: rhs_norm=" << rhs_norm << " res_ini=" << res_ini << " niter=" << niter << " nmvm=" << nmvm << " res_fin=" << res_fin
<< " dtime_iter=" << dtime_iter << endl;
istat[2] = niter;
dstat[2] = (rhs_norm == 0e0) ? res_fin : res_fin / rhs_norm;
dstat[9] = dtime_iter;
istat[2] = niter;
pSolver->CleanMvmA(); //? prec iter iter
}
......@@ -558,11 +545,3 @@ bool SolverSolveK3biilu2(bcg_k3biilu2 *data, vector_k3biilu2 *rhs_data, vector_k
T(std::cout << "##### ins. SolverSolveK3biilu2 \n";)//db!
return solvebcg_k3(data, rhs_data, sol_data) == 0;
}
int SolverIterationNumberK3biilu2(bcg_k3biilu2 *data) {
return data->ITER;
}
double SolverResidualNormK3biilu2(bcg_k3biilu2 *data) {
return data->RESID;
}
......@@ -118,9 +118,5 @@ void SolverSetMatrixK3biilu2(bcg_k3biilu2 *data, matrix_k3biilu2 *matrix_data, b
bool SolverSolveK3biilu2(bcg_k3biilu2 *data, vector_k3biilu2 *rhs_data, vector_k3biilu2 *sol_data);
int SolverIterationNumberK3biilu2(bcg_k3biilu2 *data);
double SolverResidualNormK3biilu2(bcg_k3biilu2 *data);
#endif //SOLVER_K3BIILU2_H_INCLUDED
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment