Commit b26c7ec3 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

PetscSolverGlobalMatrix works now for multiple rhs.

parent e73db218
...@@ -94,6 +94,20 @@ namespace AMDiS { ...@@ -94,6 +94,20 @@ namespace AMDiS {
MatAssemblyBegin(petscMatrix, MAT_FINAL_ASSEMBLY); MatAssemblyBegin(petscMatrix, MAT_FINAL_ASSEMBLY);
MatAssemblyEnd(petscMatrix, MAT_FINAL_ASSEMBLY); MatAssemblyEnd(petscMatrix, MAT_FINAL_ASSEMBLY);
// === Init PETSc solver. ===
KSPCreate(PETSC_COMM_WORLD, &solver);
KSPGetPC(solver, &pc);
KSPSetOperators(solver, petscMatrix, petscMatrix, SAME_NONZERO_PATTERN);
KSPSetTolerances(solver, 0.0, 1e-8, PETSC_DEFAULT, PETSC_DEFAULT);
KSPSetType(solver, KSPBCGS);
KSPMonitorSet(solver, myKSPMonitor, PETSC_NULL, 0);
KSPSetFromOptions(solver);
PCSetFromOptions(pc);
// Do not delete the solution vector, use it for the initial guess.
if (!zeroStartVector)
KSPSetInitialGuessNonzero(solver, PETSC_TRUE);
MSG("Fill petsc matrix needed %.5f seconds\n", MPI::Wtime() - wtime); MSG("Fill petsc matrix needed %.5f seconds\n", MPI::Wtime() - wtime);
} }
...@@ -138,20 +152,6 @@ namespace AMDiS { ...@@ -138,20 +152,6 @@ namespace AMDiS {
VecAssemblyEnd(petscSolVec); VecAssemblyEnd(petscSolVec);
} }
// === Init PETSc solver. ===
KSPCreate(PETSC_COMM_WORLD, &solver);
KSPGetPC(solver, &pc);
KSPSetOperators(solver, petscMatrix, petscMatrix, SAME_NONZERO_PATTERN);
KSPSetTolerances(solver, 0.0, 1e-8, PETSC_DEFAULT, PETSC_DEFAULT);
KSPSetType(solver, KSPBCGS);
KSPMonitorSet(solver, myKSPMonitor, PETSC_NULL, 0);
KSPSetFromOptions(solver);
PCSetFromOptions(pc);
// Do not delete the solution vector, use it for the initial guess.
if (!zeroStartVector)
KSPSetInitialGuessNonzero(solver, PETSC_TRUE);
// PETSc. // PETSc.
KSPSolve(solver, petscRhsVec, petscSolVec); KSPSolve(solver, petscRhsVec, petscSolVec);
...@@ -182,17 +182,27 @@ namespace AMDiS { ...@@ -182,17 +182,27 @@ namespace AMDiS {
// === Destroy PETSc's variables. === // === Destroy PETSc's variables. ===
#ifdef HAVE_PETSC_DEV #ifdef HAVE_PETSC_DEV
MatDestroy(&petscMatrix);
VecDestroy(&petscRhsVec); VecDestroy(&petscRhsVec);
#else
VecDestroy(petscRhsVec);
#endif
}
void PetscSolverGlobalMatrix::destroyMatrixData()
{
FUNCNAME("PetscSolverGlobalMatrix::destroyMatrixData()");
#ifdef HAVE_PETSC_DEV
MatDestroy(&petscMatrix);
KSPDestroy(&solver);
VecDestroy(&petscSolVec); VecDestroy(&petscSolVec);
VecDestroy(&petscTmpVec); VecDestroy(&petscTmpVec);
KSPDestroy(&solver);
#else #else
MatDestroy(petscMatrix); MatDestroy(petscMatrix);
VecDestroy(petscRhsVec); KSPDestroy(solver);
VecDestroy(petscSolVec); VecDestroy(petscSolVec);
VecDestroy(petscTmpVec); VecDestroy(petscTmpVec);
KSPDestroy(solver);
#endif #endif
} }
......
...@@ -50,8 +50,7 @@ namespace AMDiS { ...@@ -50,8 +50,7 @@ namespace AMDiS {
void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo); void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo);
void destroyMatrixData() void destroyMatrixData();
{}
protected: protected:
/// Creates a new non zero pattern structure for the PETSc matrix. /// Creates a new non zero pattern structure for the PETSc matrix.
......
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