diff --git a/MathLib/LinAlg/PETSc/PETScLinearSolver.h b/MathLib/LinAlg/PETSc/PETScLinearSolver.h index 1496df53a59d5ce404f5e5ae2b0a0ff16943eaa8..710194095ebb6c7d091a5b1a7f8bffcc802dd799 100644 --- a/MathLib/LinAlg/PETSc/PETScLinearSolver.h +++ b/MathLib/LinAlg/PETSc/PETScLinearSolver.h @@ -19,6 +19,8 @@ #include<string> +#include "logog/include/logog.hpp" + #include "petscksp.h" #include "PETScMatrix.h" @@ -47,6 +49,9 @@ class PETScLinearSolver ~PETScLinearSolver() { + INFO("info: Time elapsed in PETSc ksp solver for equation: %g s.\n", + _elapsed_ctime); + KSPDestroy(&_solver); } diff --git a/MathLib/LinAlg/PETSc/PETScMatrix.cpp b/MathLib/LinAlg/PETSc/PETScMatrix.cpp index 9b7d1dec0c4bb703a04796940d2e6032856a9182..5fa3c8cca8abb75fe4bd12ad69bbf6d4092d16ff 100644 --- a/MathLib/LinAlg/PETSc/PETScMatrix.cpp +++ b/MathLib/LinAlg/PETSc/PETScMatrix.cpp @@ -91,8 +91,11 @@ void PETScMatrix::create(const PetscInt d_nz, const PetscInt o_nz) MatSetFromOptions(_A); + MatSetType(_A, MATMPIAIJ); MatSeqAIJSetPreallocation(_A, d_nz, PETSC_NULL); MatMPIAIJSetPreallocation(_A, d_nz, PETSC_NULL, o_nz, PETSC_NULL); + // If pre-allocation does not work one can use MatSetUp(_A), which is much + // slower. MatGetOwnershipRange(_A, &_start_rank, &_end_rank); MatGetSize(_A, &_nrows, &_ncols); diff --git a/MathLib/LinAlg/PETSc/PETScMatrix.h b/MathLib/LinAlg/PETSc/PETScMatrix.h index b341a19c0efc5fc893637b48ffb3b53400a558d3..ee77b4e106d522f1bf88f4683e7c816a205458dc 100644 --- a/MathLib/LinAlg/PETSc/PETScMatrix.h +++ b/MathLib/LinAlg/PETSc/PETScMatrix.h @@ -21,6 +21,8 @@ #include "PETScMatrixOption.h" #include "PETScVector.h" +#include "MathLib/LinAlg/RowColumnIndices.h" + typedef Mat PETSc_Mat; namespace MathLib @@ -242,7 +244,7 @@ void PETScMatrix::add(std::vector<PetscInt> const& row_pos, const PetscInt nrows = static_cast<PetscInt> (row_pos.size()); const PetscInt ncols = static_cast<PetscInt> (col_pos.size()); - MatSetValues(_A, nrows, &row_pos[0], ncols, &col_pos[0], sub_mat.getEntries(), ADD_VALUES); + MatSetValues(_A, nrows, &row_pos[0], ncols, &col_pos[0], &sub_mat(0,0), ADD_VALUES); }; /*! diff --git a/MathLib/LinAlg/PETSc/PETScTools.cpp b/MathLib/LinAlg/PETSc/PETScTools.cpp index 00d5b7755622ae80545014b1376995b5e3a56112..09beeb20dafe40381fb0c5d0071f64d0a8566968 100644 --- a/MathLib/LinAlg/PETSc/PETScTools.cpp +++ b/MathLib/LinAlg/PETSc/PETScTools.cpp @@ -23,9 +23,13 @@ void applyKnownSolution(PETScMatrix &A, PETScVector &b, PETScVector &x, const std::vector<PetscInt> &vec_knownX_id, const std::vector<PetscScalar> &vec_knownX_x) { + A.finalizeAssembly(); + A.setRowsColumnsZero(vec_knownX_id); A.finalizeAssembly(); + x.finalizeAssembly(); + b.finalizeAssembly(); if(vec_knownX_id.size() > 0) { x.set(vec_knownX_id, vec_knownX_x); diff --git a/MathLib/LinAlg/PETSc/PETScVector.cpp b/MathLib/LinAlg/PETSc/PETScVector.cpp index 3f4265500862ac628ce96095f2f9b4b7f6d25697..7669745f11890d8cb764619506eae184030f3f6a 100644 --- a/MathLib/LinAlg/PETSc/PETScVector.cpp +++ b/MathLib/LinAlg/PETSc/PETScVector.cpp @@ -135,14 +135,12 @@ PetscScalar PETScVector::getNorm(MathLib::VecNormType nmtype) const return norm; } -void PETScVector::viewer(const std::string &file_name, const PetscViewerFormat vw_format) +void PETScVector::viewer(const std::string &file_name, const PetscViewerFormat vw_format) const { PetscViewer viewer; PetscViewerASCIIOpen(PETSC_COMM_WORLD, file_name.c_str(), &viewer); PetscViewerPushFormat(viewer, vw_format); - finalizeAssembly(); - PetscObjectSetName((PetscObject)_v, file_name.c_str()); VecView(_v, viewer); diff --git a/MathLib/LinAlg/PETSc/PETScVector.h b/MathLib/LinAlg/PETSc/PETScVector.h index 351a77f51b55828337825fb15d4ed0e9e752e3c9..33f6667961d8e6b190e9c9a5c68b9759091cc779 100644 --- a/MathLib/LinAlg/PETSc/PETScVector.h +++ b/MathLib/LinAlg/PETSc/PETScVector.h @@ -231,7 +231,7 @@ class PETScVector PETSC_VIEWER_DRAW_CONTOUR Views the vector with a contour plot */ void viewer(const std::string &file_name, - const PetscViewerFormat vw_format = PETSC_VIEWER_ASCII_MATLAB ); + const PetscViewerFormat vw_format = PETSC_VIEWER_ASCII_MATLAB ) const; private: PETSc_Vec _v;