# How to decompose a mesh of huge size effectively?

**URL:** <https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126>\
**Category:** General Discussion\
**Created:** [November 5, 2025, 1:58pm UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126 "2025-11-05T13:58:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lzjqingao](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@lzjqingao](https://community.freefem.org/u/lzjqingao)\
**Post date:** [November 5, 2025, 1:58pm UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/1 "2025-11-05T13:58:42Z")

</div>

Hi FreeFem Community,

I am working on a code to decompose a 3D mesh by calling FFDDM. The mesh was generated with Gmsh, and has about 46 million elements. The code is running on the HPC of our Lab, and each node has 1T memeory and 56 cores. The key codes read:

_include “ffddm.idp”  
include “macro\_ddm.idp”  
load “gmsh”  
load “msh3”  
mesh3 ThGlobal = gmshload3(“xxx.msh”);  
ffddmbuildDmesh(M3d, ThGlobal, mpiCommWorld);_

The related options in the command line are: _-ffddm\_overlap 10 -ffddm\_partitioner 1_.

I tried to run the code on 1 or 2 nodes to partition the mesh into 56 or 112 subdomains, it terminates with the error: _Failed to allocate memory for adjncy_.

I also launched the task by allocating 4 nodes, but the log stays at the building stage for over 4 hours: _Building decomposition from mesh of 45826143 elements_.

Is there more effective method to decompose such a big mesh?

---

<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 5, 2025, 2:21pm UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/2 "2025-11-05T14:21:22Z")

</div>

Use `macro_ddm.idp` with ParMETIS instead of METIS (`-Dpartitioner=parmetis`).

---

<div class="post-metadata">

**Author:** ![lzjqingao](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@lzjqingao](https://community.freefem.org/u/lzjqingao)\
**Post date:** [November 5, 2025, 2:46pm UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/3 "2025-11-05T14:46:05Z")

</div>

Thanks to your quick reply.

Is there a complete example to illustrate the usage of ParMETIS?

---

<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 5, 2025, 2:48pm UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/4 "2025-11-05T14:48:45Z")

</div>

There is nothing to illustrate beside setting the macro `partitioner` to `parmetis` as shown above.

---

<div class="post-metadata">

**Author:** ![lzjqingao](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@lzjqingao](https://community.freefem.org/u/lzjqingao)\
**Post date:** [November 7, 2025, 11:22am UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/5 "2025-11-07T11:22:51Z")

</div>

Hi prj, I’m sorry to bother you again. I have tested the method of inserting a macro in the beginning of the code like:

macro dimension 3 // EOM, 2D or 3D  
macro partitioner() parmetis // EOM

include “ffddm.idp”  
include “macro\_ddm.idp”  
load “gmsh”  
load “msh3”  
load “iovtk”  
load “hpddm”

The code works for the mesh of moderate size (about 7 million), but still fails for the mesh having 56 million by allocating 2 nodes (2T memory). When allocating 4 nodes, the log stays at the building stage for over 2 hours: _Building decomposition from mesh of 45826143 elements_.

Could you give me some suggestions, or are there more options for improving the performance?

---

<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 7, 2025, 12:25pm UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/6 "2025-11-07T12:25:27Z")

</div>

How are you partitioning the mesh? You have to call `DmeshCreate()`, as of today, `ffddmbuildDmesh()` cannot use ParMETIS.

---

<div class="post-metadata">

**Author:** ![lzjqingao](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@lzjqingao](https://community.freefem.org/u/lzjqingao)\
**Post date:** [November 10, 2025, 11:22am UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/7 "2025-11-10T11:22:23Z")

</div>

I have tested this method, and it really works.

But I have some more problems. Suppose ThGlobal is the global mesh to be partitioned. By calling

_macro partitioner() parmetis // EOM  
…….  
DmeshCreate(ThGlobal);_

how can I get the local mesh in each subdomain? In addition, is there a convenient way to incorporate DmeshCreate into ffddm or hpddm?

---

<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 10, 2025, 12:53pm UTC](https://community.freefem.org/t/how-to-decompose-a-mesh-of-huge-size-effectively/4126/8 "2025-11-10T12:53:41Z")

</div>

`ThGlobal` will be replaced by just the local mesh (it is your duty to save `ThGlobal` into a backup mesh if you need the global mesh).
