Commit b4668dfb authored by Dmitry Bagaev's avatar Dmitry Bagaev

Minor-fixes for *biilu2 solvers

parent e953e5eb
......@@ -5,7 +5,7 @@ SyncToy*
*.iml
.idea/*.xml
.idea/
Source/Solver/solver_fcbiilu2/fcbiilu2.cpp
......
<SolverParameters>
<inner_ilu2>
<test file="inner_options.txt" />
</inner_ilu2>
<inner_ddpqiluc2>
<test file="inner_options.txt" />
</inner_ddpqiluc2>
<inner_mptiluc>
<test file="inner_options.txt" />
</inner_mptiluc>
<inner_mptilu2>
<test file="inner_options.txt" />
</inner_mptilu2>
<fcbiilu2>
<test file="ctrl_dat" />
</fcbiilu2>
<k3biilu2>
<test file="ctrl_dat" />
</k3biilu2>
<petsc>
<test file="petsc_options.txt" />
</petsc>
<trilinos_ifpack>
<test file="trilinos_ifpack_options.xml" />
</trilinos_ifpack>
</SolverParameters>
\ No newline at end of file
maximum_iterations 300
gmres_substeps 4
relative_tolerance 1.0e-5
absolute_tolerance 1.0e-10
divergence_tolerance 1e+200
reorder_nonzeros 0
rescale_iterations 8
adapt_ddpq_tolerance 0
drop_tolerance 3.0e-5
reuse_tolerance 1.0e-5
ddpq_tolerance 0.0
condition_estimation 1
schwartz_overlap 6
......@@ -10,6 +10,7 @@
#if defined(USE_SOLVER)
namespace INMOST {
class SolverInterface;
class SolverParameters {
public:
std::string solverName;
......@@ -22,6 +23,8 @@ namespace INMOST {
SolverParameters(const SolverParameters &other);
~SolverParameters();
static void SetInnerParametersFromFile(const std::string &file, SolverInterface *solver);
};
typedef std::vector<std::pair<std::string, std::string> >::iterator parameters_iterator_t;
......
#include "SolverInterface.h"
#if defined(USE_SOLVER)
namespace INMOST {
SolverParameters::SolverParameters(std::string solverName, std::string solverPrefix, std::string internalFile) : solverName(solverName),
solverPrefix(solverPrefix),
internalFile(internalFile) {}
SolverParameters::SolverParameters(std::string solverName, std::string solverPrefix, std::string internalFile)
: solverName(solverName),
solverPrefix(solverPrefix),
internalFile(internalFile) {}
SolverParameters::SolverParameters(const SolverParameters &other) : solverName(other.solverName), solverPrefix(other.solverPrefix),
internalFile(other.internalFile),
parameters(other.parameters) {
SolverParameters::SolverParameters(const SolverParameters &other) : solverName(other.solverName),
solverPrefix(other.solverPrefix),
internalFile(other.internalFile),
parameters(other.parameters) {
}
SolverParameters::~SolverParameters() {}
void SolverParameters::SetInnerParametersFromFile(const std::string &file, SolverInterface *solver) {
char line[4096];
char parameterName[4096];
char parameterValue[4096];
FILE *databaseFile = fopen(file.c_str(), "r");
if (!databaseFile) return;
while (!feof(databaseFile) && fgets(line, 4096, databaseFile)) {
if (line[0] == '#') continue;
sscanf(line, "%s %s", parameterName, parameterValue);
solver->SetParameter(parameterName, parameterValue);
}
}
}
#endif //USE_SOLVER
\ No newline at end of file
......@@ -55,9 +55,16 @@ namespace INMOST {
solver_data->eps = 1e-5; // the residual precision: ||r|| < eps * ||b||; eps=1e-6
solver_data->nit = 999; // number of iterations permitted; nit=999
solver_data->msglev = 2; // messages level; msglev=0 for silent; msglev=1 to output solution statistics
SolverInitializeFcbiilu2(solver_data, argc, argv, p.internalFile.c_str());
for (parameters_iterator_t parameter = p.parameters.begin(); parameter < p.parameters.end(); parameter++) {
this->SetParameter((*parameter).first, (*parameter).second);
solver_data->params_initialized = false;
if (!p.internalFile.empty()) {
SolverInitializeFcbiilu2(solver_data, argc, argv, p.internalFile.c_str());
if (!solver_data->params_initialized) {
SolverParameters::SetInnerParametersFromFile(p.internalFile, this);
}
} else {
for (parameters_iterator_t parameter = p.parameters.begin(); parameter < p.parameters.end(); parameter++) {
this->SetParameter((*parameter).first, (*parameter).second);
}
}
}
......@@ -129,20 +136,15 @@ namespace INMOST {
INMOST_DATA_ENUM_TYPE vbeg, vend;
RHS.GetInterval(vbeg, vend);
vector_fcbiilu2 *rhs_data = NULL;
VectorInitDataFcbiilu2(&rhs_data, RHS.GetCommunicator(), RHS.GetName().c_str());
VectorPreallocateFcbiilu2(rhs_data, local_size);
vector_fcbiilu2 rhs_data = {};
rhs_data.n = local_size;
rhs_data.v = &RHS[vbeg];
vector_fcbiilu2 *solution_data = NULL;
VectorInitDataFcbiilu2(&solution_data, SOL.GetCommunicator(), SOL.GetName().c_str());
VectorPreallocateFcbiilu2(solution_data, local_size);
VectorFillFcbiilu2(rhs_data, &RHS[vbeg]);
VectorFinalizeFcbiilu2(rhs_data);
vector_fcbiilu2 solution_data = {};
solution_data.n = local_size;
solution_data.v = &SOL[vbeg];
VectorFillFcbiilu2(solution_data, &SOL[vbeg]);
VectorFinalizeFcbiilu2(solution_data);
bool result = SolverSolveFcbiilu2(solver_data, rhs_data, solution_data);
if (result) VectorLoadFcbiilu2(solution_data, &SOL[vbeg]);
bool result = SolverSolveFcbiilu2(solver_data, &rhs_data, &solution_data);
iter_time = solver_data->dstat[9];
return result;
}
......
......@@ -249,76 +249,6 @@ void MatrixFinalizeFcbiilu2(matrix_fcbiilu2 *data) {
(void) data;
}
void VectorInitDataFcbiilu2(vector_fcbiilu2 **ppA, INMOST_MPI_Comm comm, const char *name) {
if (ppA == NULL) throw INMOST::DataCorruptedInSolver;
*ppA = (vector_fcbiilu2 *) malloc(sizeof(vector_fcbiilu2));
vector_fcbiilu2 *A = (vector_fcbiilu2 *) *ppA;
A->n = 0;
(void) comm;
(void) name;
}
void VectorCopyDataFcbiilu2(vector_fcbiilu2 **ppA, vector_fcbiilu2 *pB) {
T(std::cout << "##### ins. VectorCopyDataFcbiilu2 \n";)//db!
if (ppA == NULL || pB == NULL) throw INMOST::DataCorruptedInSolver;
*ppA = (vector_fcbiilu2 *) malloc(sizeof(vector_fcbiilu2));
vector_fcbiilu2 *A = (vector_fcbiilu2 *) *ppA;
vector_fcbiilu2 *B = (vector_fcbiilu2 *) pB;
A->n = B->n;
if (B->n != 0) {
A->v = (double *) malloc(sizeof(double) * A->n);
memcpy(A->v, B->v, sizeof(double) * A->n);
}
}
void VectorAssignDataFcbiilu2(vector_fcbiilu2 *pA, vector_fcbiilu2 *pB) {
T(std::cout << "##### ins. VectorAssignDataFcbiilu2 \n";)//db!
vector_fcbiilu2 *A = (vector_fcbiilu2 *) pA;
vector_fcbiilu2 *B = (vector_fcbiilu2 *) pB;
if (A == NULL || B == NULL) throw INMOST::DataCorruptedInSolver;
if (A != B) {
if (A->n != 0) free(A->v);
A->n = B->n;
if (B->n != 0) {
A->v = (double *) malloc(sizeof(double) * A->n);
memcpy(A->v, B->v, sizeof(double) * A->n);
}
}
}
void VectorPreallocateFcbiilu2(vector_fcbiilu2 *pA, int size) {
vector_fcbiilu2 *A = (vector_fcbiilu2 *) pA;
if (A == NULL) throw INMOST::DataCorruptedInSolver;
A->n = size;
A->v = (double *) malloc(sizeof(double) * size);
}
void VectorFillFcbiilu2(vector_fcbiilu2 *pA, double *values) {
vector_fcbiilu2 *A = (vector_fcbiilu2 *) pA;
if (A == NULL) throw INMOST::DataCorruptedInSolver;
memcpy(A->v, values, sizeof(double) * A->n);
}
void VectorLoadFcbiilu2(vector_fcbiilu2 *pA, double *values) {
vector_fcbiilu2 *A = (vector_fcbiilu2 *) pA;
if (A == NULL) throw INMOST::DataCorruptedInSolver;
memcpy(values, A->v, sizeof(double) * A->n);
}
void VectorFinalizeFcbiilu2(vector_fcbiilu2 *data) {
(void) data;
}
void VectorDestroyDataFcbiilu2(vector_fcbiilu2 **ppA) {
if (ppA == NULL) throw INMOST::DataCorruptedInSolver;
if (*ppA != NULL) {
vector_fcbiilu2 *A = (vector_fcbiilu2 *) *ppA;
free(A->v);
free(*ppA);
*ppA = NULL;
}
}
void SolverInitializeFcbiilu2(bcg_fcbiilu2 *data, int *argc, char ***argv, const char *file_options) {
T(std::cout << "##### ins. SolverInitializeFcbiilu2 (" << file_options << ") \n";)//db!
if (file_options == NULL) return;
......@@ -342,7 +272,8 @@ void SolverInitializeFcbiilu2(bcg_fcbiilu2 *data, int *argc, char ***argv, const
getline(is, s);
sscanf(s.c_str(), "%lg", &(data->tau)); //9 tau
//? msglev
} else { // file: "biilu2_options.txt"
data->params_initialized = true;
} else if (s == "biilu2_options.txt") { // file: "biilu2_options.txt"
getline(is, s);
sscanf(s.c_str(), "%d", &(data->kovl)); //1 kovl
getline(is, s);
......@@ -353,6 +284,7 @@ void SolverInitializeFcbiilu2(bcg_fcbiilu2 *data, int *argc, char ***argv, const
sscanf(s.c_str(), "%d", &(data->nit)); //4 nit
getline(is, s);
sscanf(s.c_str(), "%d", &(data->msglev)); //5 msglev
data->params_initialized = true;
}
T(std::cout << "##### ins. SolverInitializeFcbiilu2: kovl=" << set_kovl << " tau=" << set_tau << " eps=" << set_eps << " nit=" << set_nit << " msglev="
<< set_msglev << " from: " << file_options << " \n";)//db!
......
......@@ -23,6 +23,7 @@ typedef struct
double dstat[16]; // double statistics array on return
double RESID; // residual norm
int ITER; // number of BiCGStab iterations performed
bool params_initialized; // backward compatibility with old parameter files
} bcg_fcbiilu2;
typedef struct
......@@ -49,15 +50,6 @@ void MatrixFillFcbiilu2(matrix_fcbiilu2 * pA, int size, int nproc, int * ibl, in
void MatrixFillValuesFcbiilu2(matrix_fcbiilu2 * pA, double * values);
void MatrixFinalizeFcbiilu2(matrix_fcbiilu2 * data);
void VectorInitDataFcbiilu2(vector_fcbiilu2 ** ppA, INMOST_MPI_Comm comm, const char * name);
void VectorCopyDataFcbiilu2(vector_fcbiilu2 ** ppA, vector_fcbiilu2 * pB);
void VectorAssignDataFcbiilu2(vector_fcbiilu2 * pA, vector_fcbiilu2 * pB);
void VectorPreallocateFcbiilu2(vector_fcbiilu2 * pA, int size);
void VectorFillFcbiilu2(vector_fcbiilu2 * pA, double * values);
void VectorLoadFcbiilu2(vector_fcbiilu2 * pA, double * values);
void VectorFinalizeFcbiilu2(vector_fcbiilu2 * data);
void VectorDestroyDataFcbiilu2(vector_fcbiilu2 ** ppA);
void SolverInitializeFcbiilu2(bcg_fcbiilu2 *data, int * argc,char *** argv, const char * file_options);
bool SolverIsFinalizedFcbiilu2();
void SolverFinalizeFcbiilu2();
......
......@@ -24,23 +24,9 @@ namespace INMOST {
void SolverInner::Setup(int *argc, char ***argv, SolverParameters &p)
{
char line[4096];
char parameterName[4096];
char parameterValue[4096];
if (!p.internalFile.empty())
{
FILE *databaseFile = fopen(p.internalFile.c_str(), "r");
if (!databaseFile) return;
while (!feof(databaseFile) && fgets(line, 4096, databaseFile))
{
if (line[0] == '#') continue;
sscanf(line, "%s %s", parameterName, parameterValue);
this->SetParameter(parameterName, parameterValue);
}
}
else
{
if (!p.internalFile.empty()) {
SolverParameters::SetInnerParametersFromFile(p.internalFile, this);
} else {
for (parameters_iterator_t parameter = p.parameters.begin(); parameter < p.parameters.end(); parameter++)
this->SetParameter((*parameter).first, (*parameter).second);
}
......
......@@ -51,7 +51,6 @@ namespace INMOST {
virtual void Finalize();
virtual ~SolverInner();
};
}
......
#include "SolverK3BIILU2.h"
#include "solver_k3biilu2.h"
#include <Source/Misc/utils.h>
#include <Source/Solver/solver_inner/SolverInner.h>
namespace INMOST {
......@@ -50,8 +51,11 @@ namespace INMOST {
void SolverK3BIILU2::Setup(int *argc, char ***argv, SolverParameters &p) {
SolverInitDataK3biilu2(&solver_data, communicator, p.solverPrefix.c_str());
if (p.internalFile != "") {
if (!p.internalFile.empty()) {
SolverInitializeK3biilu2(solver_data, argc, argv, p.internalFile.c_str());
if (!solver_data->parameters_initialized) {
SolverParameters::SetInnerParametersFromFile(p.internalFile, this);
}
} else {
for (parameters_iterator_t parameter = p.parameters.begin(); parameter < p.parameters.end(); parameter++) {
this->SetParameter((*parameter).first, (*parameter).second);
......@@ -131,23 +135,16 @@ namespace INMOST {
bool SolverK3BIILU2::Solve(INMOST::Sparse::Vector &RHS, INMOST::Sparse::Vector &SOL) {
INMOST_DATA_ENUM_TYPE vbeg, vend;
RHS.GetInterval(vbeg, vend);
vector_k3biilu2 *rhs_data = NULL;
vector_k3biilu2 *solution_data = NULL;
VectorInitDataK3biilu2(&rhs_data, RHS.GetCommunicator(), RHS.GetName().c_str());
VectorPreallocateK3biilu2(rhs_data, local_size);
VectorInitDataK3biilu2(&solution_data, SOL.GetCommunicator(), SOL.GetName().c_str());
VectorPreallocateK3biilu2(solution_data, local_size);
VectorFillK3biilu2(rhs_data, &RHS[vbeg]);
VectorFinalizeK3biilu2(rhs_data);
vector_k3biilu2 rhs_data = {};
rhs_data.n = local_size;
rhs_data.v = &RHS[vbeg];
VectorFillK3biilu2(solution_data, &SOL[vbeg]);
VectorFinalizeK3biilu2(solution_data);
vector_k3biilu2 solution_data = {};
solution_data.n = local_size;
solution_data.v = &SOL[vbeg];
bool result = SolverSolveK3biilu2(solver_data, rhs_data, solution_data);
if (result) VectorLoadK3biilu2(solution_data, &SOL[vbeg]);
bool result = SolverSolveK3biilu2(solver_data, &rhs_data, &solution_data);
iter_time = solver_data->dstat[9];
time_prec = solver_data->dstat[7];
return result;
......
......@@ -321,76 +321,6 @@ void MatrixFinalizeK3biilu2(matrix_k3biilu2 *data) {
(void) data;
}
void VectorInitDataK3biilu2(vector_k3biilu2 **ppA, INMOST_MPI_Comm comm, const char *name) {
if (ppA == NULL) throw INMOST::DataCorruptedInSolver;
*ppA = (vector_k3biilu2 *) malloc(sizeof(vector_k3biilu2));
vector_k3biilu2 *A = *ppA;
A->n = 0;
(void) comm;
(void) name;
}
void VectorCopyDataK3biilu2(vector_k3biilu2 **ppA, vector_k3biilu2 *pB) {
T(std::cout << "##### ins. VectorCopyDataK3biilu2 \n";)//db!
if (ppA == NULL || pB == NULL) throw INMOST::DataCorruptedInSolver;
*ppA = (vector_k3biilu2 *) malloc(sizeof(vector_k3biilu2));
vector_k3biilu2 *A = *ppA;
vector_k3biilu2 *B = pB;
A->n = B->n;
if (B->n != 0) {
A->v = (double *) malloc(sizeof(double) * A->n);
memcpy(A->v, B->v, sizeof(double) * A->n);
}
}
void VectorAssignDataK3biilu2(vector_k3biilu2 *pA, vector_k3biilu2 *pB) {
T(std::cout << "##### ins. VectorAssignDataK3biilu2 \n";)//db!
vector_k3biilu2 *A = pA;
vector_k3biilu2 *B = pB;
if (A == NULL || B == NULL) throw INMOST::DataCorruptedInSolver;
if (A != B) {
if (A->n != 0) free(A->v);
A->n = B->n;
if (B->n != 0) {
A->v = (double *) malloc(sizeof(double) * A->n);
memcpy(A->v, B->v, sizeof(double) * A->n);
}
}
}
void VectorPreallocateK3biilu2(vector_k3biilu2 *pA, int size) {
vector_k3biilu2 *A = pA;
if (A == NULL) throw INMOST::DataCorruptedInSolver;
A->n = size;
A->v = (double *) malloc(sizeof(double) * size);
}
void VectorFillK3biilu2(vector_k3biilu2 *pA, double *values) {
vector_k3biilu2 *A = pA;
if (A == NULL) throw INMOST::DataCorruptedInSolver;
memcpy(A->v, values, sizeof(double) * A->n);
}
void VectorLoadK3biilu2(vector_k3biilu2 *pA, double *values) {
vector_k3biilu2 *A = pA;
if (A == NULL) throw INMOST::DataCorruptedInSolver;
memcpy(values, A->v, sizeof(double) * A->n);
}
void VectorFinalizeK3biilu2(vector_k3biilu2 *data) {
(void) data;
}
void VectorDestroyDataK3biilu2(vector_k3biilu2 **ppA) {
if (ppA == NULL) throw INMOST::DataCorruptedInSolver;
if (*ppA != NULL) {
vector_k3biilu2 *A = *ppA;
free(A->v);
free(*ppA);
*ppA = NULL;
}
}
void SolverInitializeK3biilu2(bcg_k3biilu2 *data, int *argc, char ***argv, const char *file_options) {
T(std::cout << "##### ins. SolverInitializeK3biilu2 (" << file_options << ") \n";)//db!
if (file_options == NULL) return;
......@@ -440,6 +370,7 @@ void SolverInitializeK3biilu2(bcg_k3biilu2 *data, int *argc, char ***argv, const
sscanf(s.c_str(), "%d", &parIter.ichk); //18 ichk
getline(is, s);
sscanf(s.c_str(), "%d", &parIter.msglev); //19 msglev
data->parameters_initialized = true;
} else if (s == "ctrl_dat") {
getline(is, s); //1 skip iext
getline(is, s); //2 skip mtx filename
......@@ -459,7 +390,7 @@ void SolverInitializeK3biilu2(bcg_k3biilu2 *data, int *argc, char ***argv, const
parPrec.tau2 = -1.0;
parIter.ittype = (parIter.niter_cycle > 1) ? 1 : 0;
//? msglev
} else { // file: "biilu2_options.txt"
} else if (s == "biilu2_options.txt") { // file: "biilu2_options.txt"
getline(is, s);
sscanf(s.c_str(), "%d", &parPrec.ncycle); //1 kovl
getline(is, s);
......@@ -471,6 +402,7 @@ void SolverInitializeK3biilu2(bcg_k3biilu2 *data, int *argc, char ***argv, const
getline(is, s);
sscanf(s.c_str(), "%d", &parIter.msglev); //5 msglev
parPrec.tau2 = -1.0;
data->parameters_initialized = true;
}
T(std::cout << "##### ins. SolverInitializeK3biilu2: prec_float=" << parPrec.prec_float << " ncycle=" << parPrec.ncycle << " ordtype=" << parPrec.ordtype
<< " collap=" << parPrec.collap << " sctype=" << parPrec.sctype << " nitersc=" << parPrec.nitersc << " fcttype=" << parPrec.fcttype
......@@ -507,6 +439,7 @@ void SolverInitDataK3biilu2(bcg_k3biilu2 **data, INMOST_MPI_Comm comm, const cha
(*data)->pSolver = new k3d::CK3D_Solver<int, double, double>();
(*data)->pParIter = new ParIter();
(*data)->pParams = new k3d::SParams();
(*data)->parameters_initialized = false;
ParametersDefault(*((*data)->pParIter), *((*data)->pParams));
T(cout << "HHHHH bef. Clean in SolverInitDataK3biilu2 \n";)//DB!
(*data)->pSolver->Clean();
......
......@@ -34,6 +34,7 @@ typedef struct {
double dstat[16]; // double statistics array on return
double RESID; // residual norm
int ITER; // number of BiCGStab iterations performed
bool parameters_initialized; // backward compatibility with old parameter files
} bcg_k3biilu2;
typedef struct {
......@@ -84,22 +85,6 @@ void MatrixFillValuesK3biilu2(matrix_k3biilu2 *pA, double *values);
void MatrixFinalizeK3biilu2(matrix_k3biilu2 *data);
void VectorInitDataK3biilu2(vector_k3biilu2 **ppA, INMOST_MPI_Comm comm, const char *name);
void VectorCopyDataK3biilu2(vector_k3biilu2 **ppA, vector_k3biilu2 *pB);
void VectorAssignDataK3biilu2(vector_k3biilu2 *pA, vector_k3biilu2 *pB);
void VectorPreallocateK3biilu2(vector_k3biilu2 *pA, int size);
void VectorFillK3biilu2(vector_k3biilu2 *pA, double *values);
void VectorLoadK3biilu2(vector_k3biilu2 *pA, double *values);
void VectorFinalizeK3biilu2(vector_k3biilu2 *data);
void VectorDestroyDataK3biilu2(vector_k3biilu2 **ppA);
void SolverInitializeK3biilu2(bcg_k3biilu2 *data, int *argc, char ***argv, const char *file_options);
bool SolverIsFinalizedK3biilu2();
......
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