# Error from the code with PETSc when the mesh is refined

**URL:** <https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080>\
**Category:** General Discussion\
**Created:** [October 23, 2022, 11:53am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080 "2022-10-23T11:53:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 23, 2022, 11:53am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/1 "2022-10-23T11:53:27Z")

</div>

Dear all,

I am facing a problem. I compiled a code with PETSc to solve the elastic problem of the 3D model. The code with PETSc can normally run when the mesh of the model is rough, while the code reports error when the mesh is refined. The size of the refined mesh file is about 854 MB. I know that the size of the refined mesh file is so big, but it is needed for my problem. The contents of the reported error are shown in the below figures:

 ![微信图片_20221023201520](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/b/b442504fd73785608437999f6e363a40d4d1c9de.png)  
 ![微信图片_20221023201540](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/c/ca16ecdc2fefd7e9c60c8d186d5a82e28cd6444f.png)  
Another problem is that the code cannot run when the number of processors is more than 8, there are 32 processors in my computer.  
Please give me some advice.  
The files of code and two mesh (rough and fine, respectively) are attached to this post.  
[Parallel\_11.edp](https://community.freefem.org/uploads/short-url/n8e43kR6kXMEaCYAS5vaKhiFX5x.edp) (5.4 KB)  
[Quartz\_water\_calcite6.edp](https://community.freefem.org/uploads/short-url/onBBe7W8aYd7jz348Uj8MR4DiWT.edp) (2.2 MB)  
The second file is the rough mesh file with the format of .msh.  
The size of the refined mesh file is about 854 MB, and hence cannot be uploaded. If you need this file, I can sent it to you by email.  
Thank you in advance.

Best,  
Liu

---

<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 23, 2022, 12:18pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/2 "2022-10-23T12:18:33Z")

</div>

There is a `nan` in the either the linear or the bilinear form, so the program cannot continue.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 23, 2022, 12:25pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/3 "2022-10-23T12:25:13Z")

</div>

Dear Professor,  
Thank you for your reply. Why the code can normally run when the mesh of the model is rough?

---

<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 23, 2022, 12:26pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/4 "2022-10-23T12:26:52Z")

</div>

Maybe the LU factorization cannot run properly because the matrix is too big?

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 23, 2022, 12:28pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/5 "2022-10-23T12:28:39Z")

</div>

Can I solve this problem if I increase the number of processors?

---

<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 23, 2022, 12:30pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/6 "2022-10-23T12:30:38Z")

</div>

You can try, or you could use another solver.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 23, 2022, 12:34pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/7 "2022-10-23T12:34:19Z")

</div>

Professor,  
The problem is that the code cannot run when the number of processors is more than 8 even using the rough mesh, there are 32 processors in my computer. Could you give me some advice?  
And which solver do you think can better 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:** [October 23, 2022, 12:37pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/8 "2022-10-23T12:37:39Z")

</div>

You can look at the PETSc manual for a list of available solvers: [KSP: Linear System Solvers — PETSc 3.18.0 documentation](https://petsc.org/release/docs/manual/ksp/).

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 23, 2022, 12:39pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/9 "2022-10-23T12:39:05Z")

</div>

Ok, Thank you very much professor.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 30, 2022, 6:18am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/10 "2022-10-30T06:18:35Z")

</div>

Dear Professor,

According to your previous advice, I have tried all the solvers from the site you provided. The code can run with 25 processors. However, the code would report the error when the iterations was about 44, as shown in the below figures,

 ![1](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/7/7700204cd3930a947a371b63419123979f18aae9.png)  
 ![2](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/5ea907cbaae934224232936f88a07b556fed61a1.png)  
Is this because the mesh (854 MB) is too large or the performance of the computer is still insufficient？  
Please give me some advice, thank you very much.  
Best,  
Liu

---

<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 30, 2022, 6:40am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/11 "2022-10-30T06:40:35Z")

</div>

That’s a plausible cause. You can try to use the additional command line option `-Dpartitioner=parmetis` to see if this fixes things.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 30, 2022, 6:54am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/12 "2022-10-30T06:54:51Z")

</div>

Many thanks for your reply.  
Is your mean that “set(B, sparams = “-ksp\_view -ksp\_max\_it 100 -Dpartitioner=parmetis -pc\_type ksp”, bs=3, );”?

---

<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 30, 2022, 6:56am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/13 "2022-10-30T06:56:10Z")

</div>

No, I mean on the command line that you use to launch your code.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 30, 2022, 6:57am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/14 "2022-10-30T06:57:22Z")

</div>

Ok, I see. I will try it.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 30, 2022, 12:22pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/15 "2022-10-30T12:22:11Z")

</div>

Professor, the additional command line option -Dpartitioner=parmetis can not solve the problem. Do you have another advice? Otherwise, I can only use a coarser grid, even if the result will be not ideal.

---

<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 30, 2022, 12:58pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/16 "2022-10-30T12:58:45Z")

</div>

I cannot give more advice without a proper back trace.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [October 30, 2022, 1:07pm UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/17 "2022-10-30T13:07:23Z")

</div>

Ok. Now, I am trying the other solvers. I would provide the feedback as soon as I get the new results. Thank you very much.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [November 2, 2022, 1:03am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/18 "2022-11-02T01:03:10Z")

</div>

Dear professor,

Sorry for my late reply. The additional command line option -Dpartitioner=parmetis can not solve the problem. The error is same to the reported error when the option -Dpartitioner=parmetis was not used, as shown

 ![1](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/7/7700204cd3930a947a371b63419123979f18aae9.png)  
 ![2](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/5ea907cbaae934224232936f88a07b556fed61a1.png)  
Could you give me more advice?

Best,  
Liu

---

<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:** [November 2, 2022, 5:54am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/19 "2022-11-02T05:54:58Z")

</div>

I cannot give more advice without a proper back trace.

---

<div class="post-metadata">

**Author:** ![SHENG](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@SHENG](https://community.freefem.org/u/SHENG)\
**Post date:** [November 2, 2022, 7:00am UTC](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080/20 "2022-11-02T07:00:49Z")

</div>

Sorry. Professor, what exactly does a proper back trace mean?

[Next page](https://community.freefem.org/t/error-from-the-code-with-petsc-when-the-mesh-is-refined/2080.md?page=2)
