diff --git a/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc b/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc index 0bf7c516ee113bb3cac828d7bcd0e3424808dc9d..bacbef5861d7fbfac5b31da1c977cad45ab2c354 100644 --- a/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc +++ b/AMDiS/src/parallel/PetscSolverGlobalMatrix.cc @@ -94,6 +94,20 @@ namespace AMDiS { MatAssemblyBegin(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); } @@ -138,20 +152,6 @@ namespace AMDiS { 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. KSPSolve(solver, petscRhsVec, petscSolVec); @@ -182,17 +182,27 @@ namespace AMDiS { // === Destroy PETSc's variables. === #ifdef HAVE_PETSC_DEV - MatDestroy(&petscMatrix); VecDestroy(&petscRhsVec); +#else + VecDestroy(petscRhsVec); +#endif + } + + + void PetscSolverGlobalMatrix::destroyMatrixData() + { + FUNCNAME("PetscSolverGlobalMatrix::destroyMatrixData()"); + +#ifdef HAVE_PETSC_DEV + MatDestroy(&petscMatrix); + KSPDestroy(&solver); VecDestroy(&petscSolVec); VecDestroy(&petscTmpVec); - KSPDestroy(&solver); #else MatDestroy(petscMatrix); - VecDestroy(petscRhsVec); + KSPDestroy(solver); VecDestroy(petscSolVec); VecDestroy(petscTmpVec); - KSPDestroy(solver); #endif } diff --git a/AMDiS/src/parallel/PetscSolverGlobalMatrix.h b/AMDiS/src/parallel/PetscSolverGlobalMatrix.h index 34bc9af1ba7962699ecfbcee4a9d23dfe9cb6d63..252b27615a370727ac23adf2340324035decdc0d 100644 --- a/AMDiS/src/parallel/PetscSolverGlobalMatrix.h +++ b/AMDiS/src/parallel/PetscSolverGlobalMatrix.h @@ -50,8 +50,7 @@ namespace AMDiS { void solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo); - void destroyMatrixData() - {} + void destroyMatrixData(); protected: /// Creates a new non zero pattern structure for the PETSc matrix.