# High memory usage in vector space problems using PETSc

**URL:** <https://community.freefem.org/t/high-memory-usage-in-vector-space-problems-using-petsc/617>\
**Category:** General Discussion\
**Created:** [October 16, 2020, 3:16pm UTC](https://community.freefem.org/t/high-memory-usage-in-vector-space-problems-using-petsc/617 "2020-10-16T15:16:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mojtaba.barzegari](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/mojtaba.barzegari/32/20_2.png) [@mojtaba.barzegari](https://community.freefem.org/u/mojtaba.barzegari)\
**Post date:** [October 16, 2020, 3:16pm UTC](https://community.freefem.org/t/high-memory-usage-in-vector-space-problems-using-petsc/617/1 "2020-10-16T15:16:38Z")

</div>

Hi,

During the development of simple Stokes and Navier-Stokes solvers using the PETSc interface in FF, I noticed that the suggested combination of GMRES KSP type and LU preconditioner (with MUMPS) utilizes a tremendous amount of memory on not-so-big problems.

This can be seen using the [stokes-3d-PETSc.edp](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/stokes-3d-PETSc.edp) example. If I run it using `-global 45` flag, the mesh will have ~350,000 elements, i.e. a DOF of ~1,600,000, but (if I’m right) it requires more than 50 GB of memory to be solved.

Is this a bug? If not, is there not any other suggestion for the KSP and preconditioner of Stokes equation that requires less memory?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [October 16, 2020, 3:26pm UTC](https://community.freefem.org/t/high-memory-usage-in-vector-space-problems-using-petsc/617/2 "2020-10-16T15:26:17Z")

</div>

I don’t think it’s a bug, memory scaling of exact factorizations is usually terrible. For Stokes and Navier–Stokes, your best bet is to use a fieldsplit preconditioner, see [this example](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/stokes-fieldsplit-3d-PETSc.edp) + [this tutorial](http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/main.pdf#page=162) + [section 2.3.5](https://www.mcs.anl.gov/petsc/petsc-current/docs/manual.pdf#page=82) of the PETSc manual.

---

<div class="post-metadata">

**Author:** ![mojtaba.barzegari](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/mojtaba.barzegari/32/20_2.png) [@mojtaba.barzegari](https://community.freefem.org/u/mojtaba.barzegari)\
**Post date:** [October 18, 2020, 3:14pm UTC](https://community.freefem.org/t/high-memory-usage-in-vector-space-problems-using-petsc/617/3 "2020-10-18T15:14:57Z")

</div>

Thanks @prj for your help. I had already tried the fieldsplit preconditioner via the [provided example](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/stokes-fieldsplit-3d-PETSc.edp), but it didn’t have a good performance. The configuration you have in [your tutorial](http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/section_8/example10.edp) works much better in my opinion, and I’m going to use that configuration in my solver.
