Skip to content
Snippets Groups Projects
Commit 3af3dc12 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Merge branch 'issue/petsc-memory-leaks' into 'develop'

Fix memory leaks when using PETSc

See merge request !73
parents 665c808d 8526bdc3
Branches
Tags
1 merge request!73Fix memory leaks when using PETSc
...@@ -179,12 +179,6 @@ struct LinearSolver::Internals ...@@ -179,12 +179,6 @@ struct LinearSolver::Internals
Vec petscX; Vec petscX;
VecCreateMPIWithArray(PETSC_COMM_WORLD, 1, x.size(), x.size(), &x[0], &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()); Array<PetscScalar> values = copy(A.values());
const auto A_row_indices = A.rowIndices(); const auto A_row_indices = A.rowIndices();
...@@ -202,6 +196,7 @@ struct LinearSolver::Internals ...@@ -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], MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD, x.size(), x.size(), &row_indices[0], &column_indices[0], &values[0],
&petscMat); &petscMat);
...@@ -292,7 +287,12 @@ struct LinearSolver::Internals ...@@ -292,7 +287,12 @@ struct LinearSolver::Internals
} }
KSPSolve(ksp, petscB, petscX); KSPSolve(ksp, petscB, petscX);
// free used memory
MatDestroy(&petscMat); MatDestroy(&petscMat);
VecDestroy(&petscB);
VecDestroy(&petscX);
KSPDestroy(&ksp);
} }
#else // PUGS_HAS_PETSC #else // PUGS_HAS_PETSC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment