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

Fix memory leaks when using PETSc

parent 665c808d
No related branches found
No related tags found
1 merge request!73Fix memory leaks when using PETSc
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment