# Solve the 3D-MHD model in parallel using PETSc

**URL:** https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004
**Category:** General Discussion
**Created:** [July 15, 2025, 10:20am UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004 "2025-07-15T10:20:49Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Dainy-Jia](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dainy-jia/32/3322_2.png) [@Dainy-Jia](https://community.freefem.org/u/Dainy-Jia)
#### Post date: [July 15, 2025, 10:20am UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/1 "2025-07-15T10:20:49Z")

</div>

Hi, everyone!  
I want to solve a 3D MHD model, but when I used solver=UMFPACK to solve it, an error occurred on the [16,16,16] grid, which exceeded the memory, and the running speed was extremely slow.  
My aim is to obtain the error convergence order of the solution model on meshes of different mesh sizes, with the finest mesh reaching [32,32,32]. I have learned that using PETSc parallel computing can speed up the operation and save memory.

But I’m a beginner at Freefem and not very good at converting the current code into PETSc parallel code. Can someone help me? Thank you and look forward to your valuable suggestions!

> Blockquote  
> [MHD3D\_varf.edp](https://community.freefem.org/uploads/short-url/oegCviMBPbtEpBKmh9ae6flaurb.edp) (17.4 KB)

---

<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: [July 15, 2025, 5:43pm UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/2 "2025-07-15T17:43:50Z")

</div>

What issue are you facing?

---

<div class="post-metadata">

### Author: ![Dainy-Jia](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dainy-jia/32/3322_2.png) [@Dainy-Jia](https://community.freefem.org/u/Dainy-Jia)
#### Post date: [July 16, 2025, 5:39am UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/3 "2025-07-16T05:39:22Z")

</div>

Thank you for your reply！  
When I run on the [16,16,16] grid, an error of：out of memory. Do you have any good suggestions to solve this problem?

---

<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: [July 16, 2025, 5:56am UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/4 "2025-07-16T05:56:58Z")

</div>

Could you please send the log in full?

---

<div class="post-metadata">

### Author: ![Dainy-Jia](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dainy-jia/32/3322_2.png) [@Dainy-Jia](https://community.freefem.org/u/Dainy-Jia)
#### Post date: [July 16, 2025, 6:34am UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/5 "2025-07-16T06:34:59Z")

</div>

Sure.

```auto
  406 : << errH1(i, 4) << " " << orderH1(i, 4) << " " << endl;
  407 : };
  408 : sizestack + 1024 =36372 ( 35348 )

 Error Umfpack -1 : out_of_memory current line = 313
Exec error : Error Umfpack -1 : out_of_memory
   -- number :1
Exec error : Error Umfpack -1 : out_of_memory
   -- number :1
 err code 8 , mpirank 0

```

---

<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: [July 16, 2025, 6:51am UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/6 "2025-07-16T06:51:21Z")

</div>

Well, you are still using UMFPACK.

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [July 17, 2025, 3:54pm UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/7 "2025-07-17T15:54:58Z")

</div>

Dear Dainy-Jia,  
you can do as  
[MHD3D-PETSc.edp](https://community.freefem.org/uploads/short-url/sPICoiDLFceu7b4CAA1ww6GfmzK.edp) (21.4 KB)

Probably there are some choices that are not good (prj will tell). In particular concerning the preconditioner (“lu” is used).  
It does not necessarily work better than with a single process.  
I think it would be worthwile do have a scheme with decoupled u,E,B to have smaller matrices.

---

<div class="post-metadata">

### Author: ![Dainy-Jia](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dainy-jia/32/3322_2.png) [@Dainy-Jia](https://community.freefem.org/u/Dainy-Jia)
#### Post date: [July 22, 2025, 7:39am UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/8 "2025-07-22T07:39:44Z")

</div>

Thank you for your reply.  
I am sorry for reading your message so late. I am not familiar with PETSc, and I will study the code you gave me well.

---

<div class="post-metadata">

### Author: ![Deepanshu](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@Deepanshu](https://community.freefem.org/u/Deepanshu)
#### Post date: [July 24, 2025, 1:06pm UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/9 "2025-07-24T13:06:35Z")

</div>

Hey, I was facing the same problem. If you are still getting this problem, you can try with iterative solver along with it’s convergence. It’s: “solver=GMRES, eps=1e-6, nbiter=5000” use it as an argument in the problem.

---

<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: [July 24, 2025, 2:13pm UTC](https://community.freefem.org/t/solve-the-3d-mhd-model-in-parallel-using-petsc/4004/10 "2025-07-24T14:13:19Z")

</div>

Those parameters are useless if you use PETSc.
