Commit d5d188e7 authored by Dmitry Bagaev's avatar Dmitry Bagaev

K3 interface improvements

parent d64fd943
......@@ -6,3 +6,9 @@ build*/
*.iml
*.xml
Source/Solver/solver_fcbiilu2/fcbiilu2.cpp
Source/Solver/solver_k3biilu2/k3d.cpp
Source/Solver/solver_k3biilu2/k3d.h
#include "SolverK3BIILU2.h"
#include "solver_k3biilu2.h"
namespace INMOST {
SolverK3BIILU2::SolverK3BIILU2() {
solver_data = NULL;
matrix_data = NULL;
}
SolverInterface *SolverK3BIILU2::Copy(const SolverInterface *other) {
......@@ -47,7 +49,7 @@ namespace INMOST {
void SolverK3BIILU2::Setup(int *argc, char ***argv, SolverParameters &p) {
SolverInitDataK3biilu2(&solver_data, communicator, p.solverPrefix.c_str());
SolverInitializeK3biilu2(argc, argv, p.internalFile);
SolverInitializeK3biilu2(solver_data, argc, argv, p.internalFile.c_str());
}
void SolverK3BIILU2::SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner) {
......@@ -122,8 +124,8 @@ namespace INMOST {
bool SolverK3BIILU2::Solve(INMOST::Sparse::Vector &RHS, INMOST::Sparse::Vector &SOL) {
INMOST_DATA_ENUM_TYPE vbeg, vend;
RHS.GetInterval(vbeg, vend);
void *rhs_data = NULL;
void *solution_data = NULL;
vector_k3biilu2 *rhs_data = NULL;
vector_k3biilu2 *solution_data = NULL;
VectorInitDataK3biilu2(&rhs_data, RHS.GetCommunicator(), RHS.GetName().c_str());
VectorPreallocateK3biilu2(rhs_data, local_size);
......@@ -161,8 +163,9 @@ namespace INMOST {
}
void SolverK3BIILU2::SetParameter(std::string name, std::string value) {
std::cout << "SolverK3BIILU2::SetParameter unsupported operation" << std::endl;
//throw INMOST::SolverUnsupportedOperation;
const char *val = value.c_str();
if (name == "msglev") solver_data->pParIter->msglev = atoi(val);
else std::cout << "Parameter " << name << " is unknown" << std::endl;
}
const INMOST_DATA_ENUM_TYPE SolverK3BIILU2::Iterations() const {
......
......@@ -8,8 +8,8 @@ namespace INMOST {
class SolverK3BIILU2 : public SolverInterface {
private:
void *solver_data;
void *matrix_data;
bcg_k3biilu2 *solver_data;
matrix_k3biilu2 *matrix_data;
INMOST_DATA_ENUM_TYPE local_size, global_size;
public:
SolverK3BIILU2();
......
#ifndef SOLVER_K3BIILU2_H_INCLUDED
#define SOLVER_K3BIILU2_H_INCLUDED
#include "k3d.h"
#include "inmost.h"
#include "inmost_solver.h"
typedef struct {
int ittype; // 0 - BiCGStab; 1,2,3 - GMRES(niter_cycle); 2 - +Poly(ncoef)_BiCGStab; 3 - +Poly(ncoef)_GMRESb(niter_cycle2)
int niter_cycle; // outer GMRES cycle (=kgmr by IEK); 1 - BiCGStab
int ncoef; // polynomial degree (=kdeg by IEK); ittype=2,3
int niter_cycle2; // internal GMRES cycle size for ittype=3
double eps; // the residual precision: ||r|| < eps * ||b||; eps=1e-6
int maxit; // number of iterations permitted; maxit=999
int ichk; // number of skipped iterations to check the convergence
int msglev; // messages level; msglev=0 for silent; msglev>0 to output solution statistics
} ParIter;
void ParametersDefault(ParIter &parIter, k3d::SParams &parPrec);
/* BiCGStab solver structure */
typedef struct {
int n; // local number of unknowns at the local processor
int nproc; // total number of processors
int *ibl; // block splitting: ibl[0]=0; ibl[nproc]=nglob
int *ia; // row pointers: ia[0]=0; ia[nloc]=nzloc
int *ja; // global column numbers (NOTE: starting from 0 or 1); ja[nzloc]
double *a; // nonzero coefficients of local matrix A; a[nzloc]
k3d::SParams *pParams; // preconditioner construction parameters
ParIter *pParIter; // preconditioner construction parameters
k3d::CK3D_Solver<int, double, double> *pSolver; // pointer to the solver structure
int ierr; // error flag on return; ierr=0 for success
int istat[16]; // integer statistics array on return
double dstat[16]; // double statistics array on return
double RESID; // residual norm
int ITER; // number of BiCGStab iterations performed
} bcg_k3biilu2;
typedef struct {
int n; // local number of unknowns at the local processor
int nproc; // total number of processors
int *ibl; // block splitting: ibl[0]=0; ibl[nproc]=nglob
int *ia; // row pointers: ia[0]=0; ia[nloc]=nzloc
int *ja; // global column numbers (NOTE: starting from 0 or 1); ja[nzloc]
double *A; // nonzero coefficients of local matrix A; a[nzloc]
} matrix_k3biilu2;
typedef struct {
int n; // local number of unknowns at the local processor
double *v; // local data vector
} vector_k3biilu2;
/*****************************************************************************/
/* Initialize bcg solver */
int initbcg_k3(bcg_k3biilu2 *s, matrix_k3biilu2 *A, double eps);
int newmatrixbcg_k3(bcg_k3biilu2 *s, matrix_k3biilu2 *A, bool same_precond);
/* Reinitialize solver preconditioner with new matrix A */
int renewbcg_k3(bcg_k3biilu2 *s, double *A);
/* Solve linear system */
int solvebcg_k3(bcg_k3biilu2 *s, vector_k3biilu2 *b, vector_k3biilu2 *x);
/* Free memory used by solver */
void freebcg_k3(bcg_k3biilu2 *s);
/*****************************************************************************/
//#define USE_SOLVER_K3BIILU2 //just for test; see flag HAVE_SOLVER_K3BIILU2
//#if defined(USE_SOLVER_K3BIILU2)
void MatrixCopyDataK3biilu2(void ** ppA, void * pB);
void MatrixAssignDataK3biilu2(void * pA, void * pB);
void MatrixInitDataK3biilu2(void ** ppA, INMOST_MPI_Comm comm, const char * name);
void MatrixDestroyDataK3biilu2(void ** pA);
void MatrixFillK3biilu2(void * pA, int size, int nproc, int * ibl, int * ia, int * ja, double * values);
void MatrixFillValuesK3biilu2(void * pA, double * values);
void MatrixFinalizeK3biilu2(void * data);
void VectorInitDataK3biilu2(void ** ppA, INMOST_MPI_Comm comm, const char * name);
void VectorCopyDataK3biilu2(void ** ppA, void * pB);
void VectorAssignDataK3biilu2(void * pA, void * pB);
void VectorPreallocateK3biilu2(void * pA, int size);
void VectorFillK3biilu2(void * pA, double * values);
void VectorLoadK3biilu2(void * pA, double * values);
void VectorFinalizeK3biilu2(void * data);
void VectorDestroyDataK3biilu2(void ** ppA);
void SolverInitializeK3biilu2(int * argc,char *** argv, const char * file_options);
void MatrixCopyDataK3biilu2(matrix_k3biilu2 **ppA, matrix_k3biilu2 *pB);
void MatrixAssignDataK3biilu2(matrix_k3biilu2 *pA, matrix_k3biilu2 *pB);
void MatrixInitDataK3biilu2(matrix_k3biilu2 **ppA, INMOST_MPI_Comm comm, const char *name);
void MatrixDestroyDataK3biilu2(matrix_k3biilu2 **pA);
void MatrixFillK3biilu2(matrix_k3biilu2 *pA, int size, int nproc, int *ibl, int *ia, int *ja, double *values);
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();
void SolverFinalizeK3biilu2();
void SolverDestroyDataK3biilu2(void ** data);
void SolverInitDataK3biilu2(void ** data, INMOST_MPI_Comm comm, const char * name);
void SolverCopyDataK3biilu2(void ** data, void * other_data, INMOST_MPI_Comm comm);
void SolverAssignDataK3biilu2(void * data, void * other_data);
void SolverSetMatrixK3biilu2(void * data, void * matrix_data, bool same_pattern, bool reuse_preconditioner);
bool SolverSolveK3biilu2(void * data, void * rhs_data, void * sol_data);
int SolverIterationNumberK3biilu2(void * data);
double SolverResidualNormK3biilu2(void * data);
void SolverAddOtherStatK3biilu2(void * data, unsigned int * pivmod, double * prdens, double * t_prec, double * t_iter);
//#endif //USE_K3SOLVER_BIILU2
void SolverDestroyDataK3biilu2(bcg_k3biilu2 **data);
void SolverInitDataK3biilu2(bcg_k3biilu2 **data, INMOST_MPI_Comm comm, const char *name);
void SolverCopyDataK3biilu2(bcg_k3biilu2 **data, bcg_k3biilu2 *other_data, INMOST_MPI_Comm comm);
void SolverAssignDataK3biilu2(bcg_k3biilu2 *data, bcg_k3biilu2 *other_data);
void SolverSetMatrixK3biilu2(bcg_k3biilu2 *data, matrix_k3biilu2 *matrix_data, bool same_pattern, bool reuse_preconditioner);
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
......@@ -123,5 +123,9 @@ if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_FCBIILU2.*$")
add_test(NAME solver_test000_parallel_normal_fcbiilu2 COMMAND ${MPIEXEC} -np 4 $<TARGET_FILE:solver_test000> 0 fcbiilu2)
endif()
if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_K3BIILU2.*$")
add_test(NAME solver_test000_parallel_normal_k3biilu2 COMMAND ${MPIEXEC} -np 4 $<TARGET_FILE:solver_test000> 0 k3biilu2)
endif()
endif()
endif()
......@@ -55,6 +55,10 @@ if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_FCBIILU2.*$")
add_test(NAME solver_test002_serial_fcbiilu2 COMMAND $<TARGET_FILE:solver_test002> fcbiilu2 20)
endif()
if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_K3BIILU2.*$")
add_test(NAME solver_test002_serial_k3biilu2 COMMAND $<TARGET_FILE:solver_test002> k3biilu2 20)
endif()
if(USE_SOLVER_TRILINOS AND USE_MPI)
add_test(NAME solver_test002_serial_trilinos_aztec COMMAND $<TARGET_FILE:solver_test002> trilinos_aztec 20)
add_test(NAME solver_test002_serial_trilinos_belos COMMAND $<TARGET_FILE:solver_test002> trilinos_belos 20)
......@@ -94,5 +98,9 @@ if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_FCBIILU2.*$")
add_test(NAME solver_test002_parallel_fcbiilu2 COMMAND $<TARGET_FILE:solver_test002> fcbiilu2 20)
endif()
if(SOLVER_DEFINITIONS MATCHES "^.*HAVE_SOLVER_K3BIILU2.*$")
add_test(NAME solver_test002_parallel_k3biilu2 COMMAND $<TARGET_FILE:solver_test002> k3biilu2 20)
endif()
endif()
endif()
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