Commit efb0bb4a authored by Dmitry Bagaev's avatar Dmitry Bagaev

CLion code style reformat

parent 9705cf97
set(SOURCE set(SOURCE
${SOURCE} ${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/Solver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Solver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sparse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sparse.cpp
) )
set(HEADER set(HEADER
${HEADER} ${HEADER}
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.h ${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.h
) )
add_subdirectory(solver_inner) add_subdirectory(solver_inner)
if(USE_SOLVER_PETSC) if (USE_SOLVER_PETSC)
add_subdirectory(solver_petsc) add_subdirectory(solver_petsc)
endif() endif ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILUC2)
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp" ) set(HAVE_SOLVER_MPTILUC2 TRUE PARENT_SCOPE)
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILUC2) list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp)
set(HAVE_SOLVER_MPTILUC2 TRUE PARENT_SCOPE) list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp) else ()
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp) set(HAVE_SOLVER_MPTILUC2 FALSE PARENT_SCOPE)
else() endif ()
set(HAVE_SOLVER_MPTILUC2 FALSE PARENT_SCOPE)
endif() if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILU2)
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp" ) set(HAVE_SOLVER_MPTILU2 TRUE PARENT_SCOPE)
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILU2) list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp)
set(HAVE_SOLVER_MPTILU2 TRUE PARENT_SCOPE) list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.cpp)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp) else ()
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.cpp) set(HAVE_SOLVER_MPTILU2 FALSE PARENT_SCOPE)
else() endif ()
set(HAVE_SOLVER_MPTILU2 FALSE PARENT_SCOPE)
endif() if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_FCBIILU2)
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp" ) set(HAVE_SOLVER_FCBIILU2 TRUE PARENT_SCOPE)
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_FCBIILU2) list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h)
set(HAVE_SOLVER_FCBIILU2 TRUE PARENT_SCOPE) list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h) else ()
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp) set(HAVE_SOLVER_FCBIILU2 FALSE)
else() endif ()
set(HAVE_SOLVER_FCBIILU2 FALSE)
endif()
if (USE_MPI) if (USE_MPI)
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h" AND EXISTS if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.h" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/k3d.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp" ) "${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_K3BIILU2) set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_K3BIILU2)
set(HAVE_SOLVER_K3BIILU2 TRUE PARENT_SCOPE) set(HAVE_SOLVER_K3BIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h ${CMAKE_CURRENT_SOURCE_DIR}/k3d.h) list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h ${CMAKE_CURRENT_SOURCE_DIR}/k3d.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp) list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp)
else() else ()
set(HAVE_SOLVER_K3BIILU2 FALSE PARENT_SCOPE) set(HAVE_SOLVER_K3BIILU2 FALSE PARENT_SCOPE)
endif() endif ()
endif() endif ()
set(HEADER ${HEADER} PARENT_SCOPE) set(HEADER ${HEADER} PARENT_SCOPE)
......
...@@ -41,6 +41,5 @@ namespace INMOST { ...@@ -41,6 +41,5 @@ namespace INMOST {
} }
} }
...@@ -6,17 +6,20 @@ ...@@ -6,17 +6,20 @@
namespace INMOST { namespace INMOST {
struct SolverBaseFactory { struct SolverBaseFactory {
virtual SolverInterface* create() = 0; virtual SolverInterface *create() = 0;
virtual SolverInterface* copy(const SolverInterface* other) = 0;
virtual SolverInterface *copy(const SolverInterface *other) = 0;
virtual ~SolverBaseFactory() {}; virtual ~SolverBaseFactory() {};
}; };
template <class C> struct SolverCreateFactory : SolverBaseFactory { template<class C>
struct SolverCreateFactory : SolverBaseFactory {
SolverInterface *create() { SolverInterface *create() {
return new C; return new C;
}; };
SolverInterface *copy(const SolverInterface* other) { SolverInterface *copy(const SolverInterface *other) {
return new C(other); return new C(other);
}; };
}; };
...@@ -25,12 +28,17 @@ namespace INMOST { ...@@ -25,12 +28,17 @@ namespace INMOST {
private: private:
static std::map<std::string, SolverBaseFactory *> solvers; static std::map<std::string, SolverBaseFactory *> solvers;
public: public:
template<class T> static void registerSolver(std::string name) { template<class T>
static void registerSolver(std::string name) {
solvers.insert(std::make_pair(name, new SolverCreateFactory<T>)); solvers.insert(std::make_pair(name, new SolverCreateFactory<T>));
}; };
static SolverInterface *getSolver(std::string name); static SolverInterface *getSolver(std::string name);
static SolverInterface *copySolver(const SolverInterface *other); static SolverInterface *copySolver(const SolverInterface *other);
static std::vector<std::string> getAvailableSolvers(); static std::vector<std::string> getAvailableSolvers();
static bool isSolverAvailable(std::string name); static bool isSolverAvailable(std::string name);
}; };
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,144 +2,144 @@ ...@@ -2,144 +2,144 @@
namespace INMOST { namespace INMOST {
SolverILU2::SolverILU2() { SolverILU2::SolverILU2() {
additive_schwartz_overlap = DEFAULT_ADDITIVE_SCHWARTZ_OVERLAP; additive_schwartz_overlap = DEFAULT_ADDITIVE_SCHWARTZ_OVERLAP;
maximum_iterations = DEFAULT_MAXIMUM_ITERATIONS; maximum_iterations = DEFAULT_MAXIMUM_ITERATIONS;
absolute_tolerance = DEFAULT_ABSOLUTE_TOLERANCE; absolute_tolerance = DEFAULT_ABSOLUTE_TOLERANCE;
relative_tolerance = DEFAULT_RELATIVE_TOLERANCE; relative_tolerance = DEFAULT_RELATIVE_TOLERANCE;
divergence_tolerance = DEFAULT_DIVERGENCE_TOLERANCE; divergence_tolerance = DEFAULT_DIVERGENCE_TOLERANCE;
preconditioner_drop_tolerance = DEFAULT_PRECONDITIONER_DROP_TOLERANCE; preconditioner_drop_tolerance = DEFAULT_PRECONDITIONER_DROP_TOLERANCE;
preconditioner_reuse_tolerance = DEFAULT_PRECONDITIONER_REUSE_TOLERANCE; preconditioner_reuse_tolerance = DEFAULT_PRECONDITIONER_REUSE_TOLERANCE;
preconditioner_rescale_iterations = DEFAULT_PRECONDITIONER_RESCALE_ITERS; preconditioner_rescale_iterations = DEFAULT_PRECONDITIONER_RESCALE_ITERS;
preconditioner_fill_level = DEFAULT_PRECONDITIONER_FILL_LEVEL; preconditioner_fill_level = DEFAULT_PRECONDITIONER_FILL_LEVEL;
Method *prec = new ILU2_preconditioner(info); Method *prec = new ILU2_preconditioner(info);
solver = new BCGS_solver(prec, info); solver = new BCGS_solver(prec, info);
matrix = NULL; matrix = NULL;
} }
SolverILU2::SolverILU2(const SolverInterface* other) { SolverILU2::SolverILU2(const SolverInterface *other) {
//You should not really want to copy solver's information //You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation; throw INMOST::SolverUnsupportedOperation;
}
void SolverILU2::Assign(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
void SolverILU2::Initialize(int *argc, char ***argv, const char *parameters_file, std::string prefix) {
}
void SolverILU2::SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner) {
Sparse::Matrix *m = new Sparse::Matrix(A);
info.PrepareMatrix(*m, additive_schwartz_overlap);
solver->ReplaceMAT(*m);
if (matrix != NULL) {
delete matrix;
} }
matrix = m;
void SolverILU2::Assign(const SolverInterface* other) { solver->RealParameter(":tau") = preconditioner_drop_tolerance;
//You should not really want to copy solver's information solver->RealParameter(":tau2") = preconditioner_reuse_tolerance;
throw INMOST::SolverUnsupportedOperation; solver->EnumParameter(":scale_iters") = preconditioner_rescale_iterations;
} solver->EnumParameter(":fill") = static_cast<INMOST_DATA_ENUM_TYPE>(preconditioner_fill_level);
void SolverILU2::Initialize(int *argc, char ***argv, const char *parameters_file, std::string prefix) { if (!solver->isInitialized()) {
solver->Initialize();
}
void SolverILU2::SetMatrix(Sparse::Matrix & A, bool ModifiedPattern, bool OldPreconditioner) {
Sparse::Matrix *m = new Sparse::Matrix(A);
info.PrepareMatrix(*m, additive_schwartz_overlap);
solver->ReplaceMAT(*m);
if (matrix != NULL) {
delete matrix;
}
matrix = m;
solver->RealParameter(":tau") = preconditioner_drop_tolerance;
solver->RealParameter(":tau2") = preconditioner_reuse_tolerance;
solver->EnumParameter(":scale_iters") = preconditioner_rescale_iterations;
solver->EnumParameter(":fill") = static_cast<INMOST_DATA_ENUM_TYPE>(preconditioner_fill_level);
if (!solver->isInitialized()) {
solver->Initialize();
}
}
bool SolverILU2::Solve(Sparse::Vector &RHS, Sparse::Vector &SOL) {
solver->EnumParameter("maxits") = maximum_iterations;
solver->RealParameter("rtol") = relative_tolerance;
solver->RealParameter("atol") = absolute_tolerance;
solver->RealParameter("divtol") = divergence_tolerance;
return solver->Solve(RHS,SOL);
} }
}
bool SolverILU2::Clear() {
info.Clear(); bool SolverILU2::Solve(Sparse::Vector &RHS, Sparse::Vector &SOL) {
if (matrix != NULL) { solver->EnumParameter("maxits") = maximum_iterations;
delete matrix; solver->RealParameter("rtol") = relative_tolerance;
matrix = NULL; solver->RealParameter("atol") = absolute_tolerance;
} solver->RealParameter("divtol") = divergence_tolerance;
if (solver != NULL) {
delete solver; return solver->Solve(RHS, SOL);
solver = NULL; }
}
return true; bool SolverILU2::Clear() {
info.Clear();
if (matrix != NULL) {
delete matrix;
matrix = NULL;
} }
if (solver != NULL) {
bool SolverILU2::isMatrixSet() { delete solver;
return matrix != NULL; solver = NULL;
}
INMOST_DATA_REAL_TYPE SolverILU2::GetPropertyReal(std::string property) const {
return solver->RealParameter(property);
}
INMOST_DATA_ENUM_TYPE SolverILU2::GetPropertyEnum(std::string property) const {
return solver->EnumParameter(property);
}
void SolverILU2::SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value) {
//Maybe we should use explicit names?, like maxits ..etc
//like solver->RealParameter(property) = value;
if (property == "absolute_tolerance") {
absolute_tolerance = value;
} else if (property == "relative_tolerance") {
relative_tolerance = value;
} else if (property == "divergence_tolerance") {
divergence_tolerance = value;
} else if (property == "drop_tolerance") {
preconditioner_drop_tolerance = value;
} else if (property == "reuse_tolerance") {
preconditioner_reuse_tolerance = value;
} else if (property == "fill_level") {
preconditioner_fill_level = value;
} else {
std::cout << "Parameter " << property << " of real type is unknown" << std::endl;
}
}
void SolverILU2::SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value) {
//Maybe we should use explicit names?, like maxits ..etc
//like solver->EnumParameter(property) = value;
if (property == "maximum_iterations") {
maximum_iterations = value;
} else if (property == "rescale_iterations") {
preconditioner_rescale_iterations = value;
} else if (property == "schwartz_overlap") {
additive_schwartz_overlap = value;
} else std::cout << "Parameter " << property << " of integral type is unknown" << std::endl;
} }
return true;
const INMOST_DATA_ENUM_TYPE SolverILU2::Iterations() const { }
return solver->GetIterations();
} bool SolverILU2::isMatrixSet() {
return matrix != NULL;
const INMOST_DATA_REAL_TYPE SolverILU2::Residual() const { }
return solver->GetResidual();
} INMOST_DATA_REAL_TYPE SolverILU2::GetPropertyReal(std::string property) const {
return solver->RealParameter(property);
const std::string SolverILU2::ReturnReason() const { }
return solver->GetReason();
} INMOST_DATA_ENUM_TYPE SolverILU2::GetPropertyEnum(std::string property) const {
return solver->EnumParameter(property);
const std::string SolverILU2::SolverName() const { }
return "inner_ilu2";
} void SolverILU2::SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value) {
//Maybe we should use explicit names?, like maxits ..etc
void SolverILU2::Finalize() { //like solver->RealParameter(property) = value;
if (property == "absolute_tolerance") {
} absolute_tolerance = value;
} else if (property == "relative_tolerance") {
SolverILU2::~SolverILU2() { relative_tolerance = value;
Clear(); } else if (property == "divergence_tolerance") {
divergence_tolerance = value;
} else if (property == "drop_tolerance") {
preconditioner_drop_tolerance = value;
} else if (property == "reuse_tolerance") {
preconditioner_reuse_tolerance = value;
} else if (property == "fill_level") {
preconditioner_fill_level = value;
} else {
std::cout << "Parameter " << property << " of real type is unknown" << std::endl;
} }
}
void SolverILU2::SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value) {
//Maybe we should use explicit names?, like maxits ..etc
//like solver->EnumParameter(property) = value;
if (property == "maximum_iterations") {
maximum_iterations = value;
} else if (property == "rescale_iterations") {
preconditioner_rescale_iterations = value;
} else if (property == "schwartz_overlap") {
additive_schwartz_overlap = value;
} else std::cout << "Parameter " << property << " of integral type is unknown" << std::endl;
}
const INMOST_DATA_ENUM_TYPE SolverILU2::Iterations() const {
return solver->GetIterations();
}
const INMOST_DATA_REAL_TYPE SolverILU2::Residual() const {
return solver->GetResidual();
}
const std::string SolverILU2::ReturnReason() const {
return solver->GetReason();
}
const std::string SolverILU2::SolverName() const {
return "inner_ilu2";
}
void SolverILU2::Finalize() {
}
SolverILU2::~SolverILU2() {
Clear();
}
} }
\ No newline at end of file
...@@ -12,19 +12,19 @@ namespace INMOST { ...@@ -12,19 +12,19 @@ namespace INMOST {
SolverPETSc::SolverPETSc(const SolverInterface *other) { SolverPETSc::SolverPETSc(const SolverInterface *other) {
petscSolversCount++; petscSolversCount++;
const SolverPETSc *solver = static_cast<const SolverPETSc*>(other); const SolverPETSc *solver = static_cast<const SolverPETSc *>(other);
this->ksp = NULL; this->ksp = NULL;
this->matrix = NULL; this->matrix = NULL;
SolverCopyDataPetsc(&ksp, solver->ksp, solver->communicator); SolverCopyDataPetsc(&ksp, solver->ksp, solver->communicator);
if (solver->matrix != NULL) { if (solver->matrix != NULL) {
MatrixCopyDataPetsc(&matrix, solver->matrix); MatrixCopyDataPetsc(&matrix, solver->matrix);
SolverSetMatrixPetsc(ksp, matrix,false,false); SolverSetMatrixPetsc(ksp, matrix, false, false);
} }
} }
void SolverPETSc::Assign(const SolverInterface *other) { void SolverPETSc::Assign(const SolverInterface *other) {
const SolverPETSc *other_solver = static_cast<const SolverPETSc*>(other); const SolverPETSc *other_solver = static_cast<const SolverPETSc *>(other);
this->parametersFile = other_solver->parametersFile; this->parametersFile = other_solver->parametersFile;
SolverAssignDataPetsc(ksp, other_solver->ksp); SolverAssignDataPetsc(ksp, other_solver->ksp);
if (other_solver->matrix != NULL) { if (other_solver->matrix != NULL) {
...@@ -43,53 +43,53 @@ namespace INMOST { ...@@ -43,53 +43,53 @@ namespace INMOST {
SolverInitDataPetsc(&ksp, this->communicator, prefix.c_str()); SolverInitDataPetsc(&ksp, this->communicator, prefix.c_str());
} }
void SolverPETSc::SetMatrix(Sparse::Matrix & A, bool ModifiedPattern, bool OldPreconditioner) { void SolverPETSc::SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner) {
bool modified_pattern = ModifiedPattern; bool modified_pattern = ModifiedPattern;
if( !isMatrixSet()) { if (!isMatrixSet()) {
MatrixInitDataPetsc(&matrix, A.GetCommunicator(),A.GetName().c_str()); MatrixInitDataPetsc(&matrix, A.GetCommunicator(), A.GetName().c_str());
modified_pattern = true; modified_pattern = true;
} }
INMOST_DATA_ENUM_TYPE mbeg,mend; INMOST_DATA_ENUM_TYPE mbeg, mend;
A.GetInterval(mbeg,mend); A.GetInterval(mbeg, mend);
if( modified_pattern ) { if (modified_pattern) {
local_size = A.Size(); local_size = A.Size();
#if defined(USE_MPI) #if defined(USE_MPI)
MPI_Allreduce(&local_size,&global_size,1,INMOST_MPI_DATA_ENUM_TYPE,MPI_SUM, this->communicator); MPI_Allreduce(&local_size, &global_size, 1, INMOST_MPI_DATA_ENUM_TYPE, MPI_SUM, this->communicator);
#else #else
global_size = local_size; global_size = local_size;
#endif #endif
int max = 0; int max = 0;
{ {
int * diag_nonzeroes = new int[local_size]; int *diag_nonzeroes = new int[local_size];
int * off_diag_nonzeroes = new int[local_size]; int *off_diag_nonzeroes = new int[local_size];
unsigned k = 0; unsigned k = 0;
for(Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) { for (Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) {
diag_nonzeroes[k] = off_diag_nonzeroes[k] = 0; diag_nonzeroes[k] = off_diag_nonzeroes[k] = 0;
for(INMOST_DATA_ENUM_TYPE i = 0; i < it->Size(); i++) { for (INMOST_DATA_ENUM_TYPE i = 0; i < it->Size(); i++) {
INMOST_DATA_ENUM_TYPE index = it->GetIndex(i); INMOST_DATA_ENUM_TYPE index = it->GetIndex(i);
if( index < mbeg || index > mend-1 ) { if (index < mbeg || index > mend - 1) {
off_diag_nonzeroes[k]++; off_diag_nonzeroes[k]++;
} else { } else {
diag_nonzeroes[k]++; diag_nonzeroes[k]++;
} }
} }
if( diag_nonzeroes[k] + off_diag_nonzeroes[k] > max ) { if (diag_nonzeroes[k] + off_diag_nonzeroes[k] > max) {
max = diag_nonzeroes[k] + off_diag_nonzeroes[k]; max = diag_nonzeroes[k] + off_diag_nonzeroes[k];
} }
k++; k++;
} }
MatrixPreallocatePetsc(matrix, local_size, global_size, diag_nonzeroes, off_diag_nonzeroes); MatrixPreallocatePetsc(matrix, local_size, global_size, diag_nonzeroes, off_diag_nonzeroes);
delete [] diag_nonzeroes; delete[] diag_nonzeroes;
delete [] off_diag_nonzeroes; delete[] off_diag_nonzeroes;
} }
if( max > 0 ) { if (max > 0) {
int * col_positions = new int[max]; int *col_positions = new int[max];
double * col_values = new double[max]; double *col_values = new double[max];
unsigned k = 0, m; unsigned k = 0, m;
for(Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) { for (Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) {
m = 0; m = 0;
for(INMOST_DATA_ENUM_TYPE i = 0; i < it->Size(); i++) { for (INMOST_DATA_ENUM_TYPE i = 0; i < it->Size(); i++) {
col_positions[m] = it->GetIndex(i); col_positions[m] = it->GetIndex(i);
col_values[m] = it->GetValue(i); col_values[m] = it->GetValue(i);
m++; m++;
...@@ -97,22 +97,22 @@ namespace INMOST { ...@@ -97,22 +97,22 @@ namespace INMOST {
MatrixFillPetsc(matrix, mbeg + k, m, col_positions, col_values); MatrixFillPetsc(matrix, mbeg + k, m, col_positions, col_values);
k++; k++;
} }
delete [] col_positions; delete[] col_positions;
delete [] col_values; delete[] col_values;
} }
} else { } else {
unsigned max = 0; unsigned max = 0;
for(Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) { for (Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) {
if( it->Size() > max ) { if (it->Size() > max) {
max = it->Size(); max = it->Size();
} }
} }
int * col_positions = new int[max]; int *col_positions = new int[max];
double * col_values = new double[max]; double *col_values = new double[max];
unsigned k = 0, m; unsigned k = 0, m;
for(Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) { for (Sparse::Matrix::iterator it = A.Begin(); it != A.End(); ++it) {
m = 0; m = 0;
for(INMOST_DATA_ENUM_TYPE i = 0; i < it->Size(); i++) { for (INMOST_DATA_ENUM_TYPE i = 0; i < it->Size(); i++) {
col_positions[m] = it->GetIndex(i); col_positions[m] = it->GetIndex(i);
col_values[m] = it->GetValue(i); col_values[m] = it->GetValue(i);
m++; m++;
...@@ -120,8 +120,8 @@ namespace INMOST { ...@@ -120,8 +120,8 @@ namespace INMOST {
MatrixFillPetsc(matrix, mbeg + k, m, col_positions, col_values); MatrixFillPetsc(matrix, mbeg + k, m, col_positions, col_values);
k++; k++;
} }
delete [] col_positions; delete[] col_positions;
delete [] col_values; delete[] col_values;
} }
MatrixFinalizePetsc(matrix); MatrixFinalizePetsc(matrix);
...@@ -141,13 +141,13 @@ namespace INMOST { ...@@ -141,13 +141,13 @@ namespace INMOST {
Vec *solution = NULL; Vec *solution = NULL;
VectorInitDataPetsc(&solution, SOL.GetCommunicator(), SOL.GetName().c_str()); VectorInitDataPetsc(&solution, SOL.GetCommunicator(), SOL.GetName().c_str());
VectorPreallocatePetsc(solution, local_size, global_size); VectorPreallocatePetsc(solution, local_size, global_size);
INMOST_DATA_ENUM_TYPE vbeg,vend; INMOST_DATA_ENUM_TYPE vbeg, vend;
RHS.GetInterval(vbeg,vend); RHS.GetInterval(vbeg, vend);
int * positions = new int[local_size]; int *positions = new int[local_size];
double * values = new double[local_size]; double *values = new double[local_size];
unsigned int k = 0; unsigned int k = 0;
for(Sparse::Vector::iterator it = RHS.Begin(); it != RHS.End(); ++it) { for (Sparse::Vector::iterator it = RHS.Begin(); it != RHS.End(); ++it) {
positions[k] = vbeg+k; positions[k] = vbeg + k;
values[k] = *it; values[k] = *it;
k++; k++;
} }
...@@ -155,7 +155,7 @@ namespace INMOST { ...@@ -155,7 +155,7 @@ namespace INMOST {
VectorFinalizePetsc(rhs); VectorFinalizePetsc(rhs);
k = 0; k = 0;
for(Sparse::Vector::iterator it = SOL.Begin(); it != SOL.End(); ++it)