# Poisson equation with Lagrange multipliers in parallel

**URL:** https://community.freefem.org/t/poisson-equation-with-lagrange-multipliers-in-parallel/3866
**Category:** General Discussion
**Created:** [April 16, 2025, 6:30am UTC](https://community.freefem.org/t/poisson-equation-with-lagrange-multipliers-in-parallel/3866 "2025-04-16T06:30:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![maximefio](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@maximefio](https://community.freefem.org/u/maximefio)
#### Post date: [April 16, 2025, 6:30am UTC](https://community.freefem.org/t/poisson-equation-with-lagrange-multipliers-in-parallel/3866/1 "2025-04-16T06:30:28Z")

</div>

Hello,

I am currently using Freefem to solve a Poisson equation with a source term on an external mesh (contained in ffem-mesh.msh) and the source term is in ffem-drhodt.dat with Lagrange multipliers :

```auto
include "getARGV.idp"

string meshname = getARGV("-mesh", "BASE/ffem-mesh.msh");
string drhodtname = getARGV("-drhodt", "BASE/ffem-drhodt.dat");

mesh Th = readmesh(meshname);

fespace Vh(Th,P1); // P1 FE space
Vh drhodt;

{       
        ifstream fid(drhodtname);
        fid >> drhodt[];
}

int n = Vh.ndof;
int n1 = n+1;

Vh phi,vh; // unknown and test function.  

varf va(phi,vh) = // definition of the problem
    int2d(Th)( dx(phi)*dx(vh) + dy(phi)*dy(vh) ) // bilinear form
;

varf vL(phi,vh)= int2d(Th)( drhodt*vh ) ;
varf vb(phi,vh)= int2d(Th)(1.*vh);

matrix A=va(Vh,Vh);

real[int] b(n);
b = vL(0,Vh);

real[int] B = vb(0,Vh);
// the block matrix

matrix AA = [[ A , B] ,
              [B', 0] ] ;

real[int] bb(n+1),xx(n+1),b1(1),l(1);
b1=0;
// build the block rhs
bb = [b, b1];
set(AA,solver=sparsesolver, eps=1.0e-3);
xx = AA^-1*bb; // solve the linear system
[phi[],l] = xx; // set the value

```

The code works perfectly but since some meshes that I use are quite big, I was wondering if it would be possible to run the code in parallel using for example hpddm. I had a look at some implementations [FreeFem-sources/examples/hpddm/minimal-surface-Tao-2d-PETSc.edp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/minimal-surface-Tao-2d-PETSc.edp#L17-L22)  
but I was wondering if it would be possible to do that.

Thank you,

Maxime

---

<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: [April 16, 2025, 7:35am UTC](https://community.freefem.org/t/poisson-equation-with-lagrange-multipliers-in-parallel/3866/2 "2025-04-16T07:35:59Z")

</div>

> <https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/laplace-lagrange-PETSc.edp>

---

<div class="post-metadata">

### Author: ![maximefio](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@maximefio](https://community.freefem.org/u/maximefio)
#### Post date: [April 17, 2025, 5:48am UTC](https://community.freefem.org/t/poisson-equation-with-lagrange-multipliers-in-parallel/3866/3 "2025-04-17T05:48:09Z")

</div>

Hello,

Thank you very much for the script ! I had not well looked at the hpddm scripts in the example folder.

Have a good day,

Maxime
