Skip to content
Snippets Groups Projects

Fix memory leaks when using PETSc

Merged Stéphane Del Pino requested to merge issue/petsc-memory-leaks into develop
1 file
+ 6
6
Compare changes
  • Side-by-side
  • Inline
@@ -179,12 +179,6 @@ struct LinearSolver::Internals
Vec petscX;
VecCreateMPIWithArray(PETSC_COMM_WORLD, 1, x.size(), x.size(), &x[0], &petscX);
Mat petscMat;
MatCreate(PETSC_COMM_WORLD, &petscMat);
MatSetSizes(petscMat, PETSC_DECIDE, PETSC_DECIDE, x.size(), x.size());
MatSetType(petscMat, MATAIJ);
Array<PetscScalar> values = copy(A.values());
const auto A_row_indices = A.rowIndices();
@@ -202,6 +196,7 @@ struct LinearSolver::Internals
}
}
Mat petscMat;
MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD, x.size(), x.size(), &row_indices[0], &column_indices[0], &values[0],
&petscMat);
@@ -292,7 +287,12 @@ struct LinearSolver::Internals
}
KSPSolve(ksp, petscB, petscX);
// free used memory
MatDestroy(&petscMat);
VecDestroy(&petscB);
VecDestroy(&petscX);
KSPDestroy(&ksp);
}
#else // PUGS_HAS_PETSC
Loading