# How to set AttachCoarseOperator?

**URL:** <https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111>\
**Category:** General Discussion\
**Created:** [October 23, 2025, 12:00pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111 "2025-10-23T12:00:13Z")\
**Posts on this page:** 10\
**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:** [October 23, 2025, 12:00pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/1 "2025-10-23T12:00:13Z")

</div>

Hello, I am studying how to set the two-level GenEo algorithm by calling hpddm directly, and the code _elasticity.edp_ in ~/examples/hpddm is related closely to my purpose. My problem is about the setting of _AttachCoarseOperator_, and the involved code is line 81-84 in this edp file:

varf vPbNoPen(def(u), def(v)) = int3d(Th)(lambda \* div(u) \* div(v) + 2.0 \* mu \* (epsilon(u)’ \* epsilon(v))) + on(1, u = 0.0, uB = 0.0, uC = 0.0);  
matrix noPen = vPbNoPen(Wh, Wh, sym = 1);  
if(deflation == “geneo”)  
AttachCoarseOperator(mpiCommWorld, A, A = noPen/_, threshold = 2. \* h[].max / diam,_/, ret = ret);

The problem _vPbNoPen_ defined here is different to the one in line 54, and the term int3d(Th)(f \* vC) is not included here. Why does it work? And how to find the detailed usage of AttachCoarseOperator?

Thanks

---

<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, 2025, 12:56pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/2 "2025-10-23T12:56:53Z")

</div>

The linear form is irrelevant for building the coarse space. Are you sure that you know what you are looking for?

---

<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:** [October 23, 2025, 1:41pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/3 "2025-10-23T13:41:54Z")

</div>

My purpose is to solve a thermal stress problem of large size (~ 10^9 dof) with the two-level ddm algorithm (GenEo), but calling it via FFDDM is very memory consuming. It seems that calling hpddm directly is a better choice. According to the code _elasticity.edp_ in ~/examples/hpddm, the setting of AttachCoarseOperator is a key step.

---

<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, 2025, 1:45pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/4 "2025-10-23T13:45:33Z")

</div>

I’m not sure why ffddm would be more memory demanding (maybe you are keeping the global mesh?). Anyway, if you want performance, you should just use PETSc with `-pc_type hpddm`, it’s the most performance-oriented implementation, and there are examples in the same folder.

I’ll add that for a thermal stress problem, the odds of AMG working and greatly outperforming GenEO are close to 100%.

---

<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:** [October 23, 2025, 2:00pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/5 "2025-10-23T14:00:43Z")

</div>

I also tested the method of using PETSc with -pc\_type hpddm, but the consumed time is much larger than using PETSc with hybre/AMG (20 min vs 5.5 min for a test problem running on my desktop pc). The setting reads:

set(A, sparams = "-pc\_type hpddm " +  
"-pc\_hpddm\_levels\_1\_pc\_type asm " +  
"-pc\_hpddm\_levels\_1\_eps\_nev 10 -pc\_hpddm\_levels\_1\_eps\_type arpack " +  
"-pc\_hpddm\_levels\_1\_sub\_pc\_type cholesky " +  
"-pc\_hpddm\_levels\_1\_st\_ksp\_type gmres -pc\_hpddm\_levels\_1\_st\_share\_sub\_ksp " +  
"-pc\_hpddm\_levels\_1\_sub\_pc\_factor\_mat\_solver\_type mumps " +  
"-pc\_hpddm\_levels\_1\_st\_pc\_factor\_mat\_solver\_type mumps " +  
"-pc\_hpddm\_coarse\_p 2 -pc\_hpddm\_coarse\_correction balanced " +  
"-pc\_hpddm\_coarse\_pc\_type cholesky -pc\_hpddm\_coarse\_pc\_factor\_mat\_solver\_type mumps " +  
"-pc\_hpddm\_coarse\_ksp\_reuse\_preconditioner " +  
"-pc\_hpddm\_define\_subdomains true -pc\_hpddm\_has\_neumann true " +  
"-ksp\_max\_it 100 -ksp\_rtol 1.e-6 -ksp\_type gmres -ksp\_monitor -ksp\_converged\_reason ");

But I am not sure about it. Are there any errors or improvements?

---

<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:** [October 23, 2025, 2:25pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/6 "2025-10-23T14:25:57Z")

</div>

The code using PETSc/hybre has been moved to the HPC of my lab, and was run by loading the container file freefem\_latest.sif (version 4.12) via singularity. The key command is:

singularity exec -e ~/freefem\_latest.sif bash -c "/usr/freefem/ff-petsc/r/lib/petsc/bin/petscmpiexec -np 40 /usr/freefem/bin/FreeFem+±mpi -nw xxx.edp

But severe error occurs:

_MatCreate The Identifier MatCreate does not exist_

_Error line number 51:_

// line 50-51  
Mat A;  
MatCreate(Th, A, Pk);

Are there any errors in the command?

---

<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, 2025, 2:34pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/7 "2025-10-23T14:34:34Z")

</div>

> [@lzjqingao](#):
>
> Are there any errors or improvements?

Again, if either GAMG or BoomerAMG work, they will be hard to beat. How many iterations do they require to converge?

---

<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:** [October 23, 2025, 2:36pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/8 "2025-10-23T14:36:31Z")

</div>

About 90 iterations.

---

<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, 2025, 2:42pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/9 "2025-10-23T14:42:06Z")

</div>

> Are there any errors in the command?

There is no error, you are simply using an extremely outdated FreeFEM installation.

---

<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:** [October 23, 2025, 3:12pm UTC](https://community.freefem.org/t/how-to-set-attachcoarseoperator/4111/10 "2025-10-23T15:12:35Z")

</div>

Hi, prj. Let’s turn back to the beginning of this topic. The code calling hpddm directly can be run on the HPC normally (via singularity/ff\_v4.12), but it converges very slowly (relative error of 0.1 after 200 iterations). I suspect that the coarse space is not built correctly. Thus I pose the problem of setting AttachCoarseOperator, especially the meaning of vPbNoPen.
