# A simple question of PETSc

**URL:** <https://community.freefem.org/t/a-simple-question-of-petsc/2566>\
**Category:** General Discussion\
**Created:** [June 29, 2023, 6:44am UTC](https://community.freefem.org/t/a-simple-question-of-petsc/2566 "2023-06-29T06:44:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![m31phy](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/m31phy/32/1216_2.png) [@m31phy](https://community.freefem.org/u/m31phy)\
**Post date:** [June 29, 2023, 6:44am UTC](https://community.freefem.org/t/a-simple-question-of-petsc/2566/1 "2023-06-29T06:44:31Z")

</div>

Hello Everyone

I have studied FreeFEM++ and its parallelization with lectures in Youtube made by Pierre Jolivet and TuxRiders. During self-studies, I got a simple question but making me slightly confused of.

The thing is, `buildDmesh` and `createMat`

As far as I know, `buildDmesh` is a function of decomposing the whole domain to subdomains based on the number of allocated MPI processors. One the other hand, `createMat` is to distribute a PETSc matrix from “Mat” in PETSc library for parallel computation.

So, I could see that in Pierre’s lecture, he used buildDmesh and createMesh together while TuxRiders’s recent video ([[FreeFEM 11] Domain decomposition and high-performance finite element simulations - YouTube](https://www.youtube.com/watch?v=Phpce6teWAA)) used createMesh without buildDMesh. This makes me slightly confused.

Thus, my question is, is it fine to use createMesh only without buildDmesh?

Thanks

---

<div class="post-metadata">

**Author:** ![henkel](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@henkel](https://community.freefem.org/u/henkel)\
**Post date:** [June 29, 2023, 12:24pm UTC](https://community.freefem.org/t/a-simple-question-of-petsc/2566/2 "2023-06-29T12:24:58Z")

</div>

Both macros are defined in [macro\_ddm.idp](https://github.com/FreeFem/FreeFem-sources/blob/master/idp/macro_ddm.idp) and this is also the place where you can find the answer to your question.

If I get this right, `createMat` checks if `buildDmesh` has been executed previously and if not, then it automatically calls `buildDmesh`. So it is indeed fine to use `createMat` only without `buildDmesh`.

---

<div class="post-metadata">

**Author:** ![m31phy](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/m31phy/32/1216_2.png) [@m31phy](https://community.freefem.org/u/m31phy)\
**Post date:** [June 30, 2023, 10:40am UTC](https://community.freefem.org/t/a-simple-question-of-petsc/2566/3 "2023-06-30T10:40:37Z")

</div>

Thank you so much. It helps a lot!

---

<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:** [June 30, 2023, 11:11am UTC](https://community.freefem.org/t/a-simple-question-of-petsc/2566/4 "2023-06-30T11:11:23Z")

</div>

Just to further expand on the accepted answer, this will be true only if this is on the same scope.  
I.e.,

```auto
buildDmesh(Th, ...);
{
  createMat(Th, ...);
}

```

is equivalent to just:

```auto
createMat(Th, ...);

```

but different than:

```auto
{
  buildDmesh(Th, ...);
}
{
  createMat(Th, ...);
}

```

---

<div class="post-metadata">

**Author:** ![m31phy](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/m31phy/32/1216_2.png) [@m31phy](https://community.freefem.org/u/m31phy)\
**Post date:** [July 2, 2023, 3:25am UTC](https://community.freefem.org/t/a-simple-question-of-petsc/2566/5 "2023-07-02T03:25:26Z")

</div>

thank you for kind explanation!
