# HMatrix/BEM in FreeFem++ on Mac: MPI error ‘Attempting to use an MPI routine before initializing or after finalizing MPICH'

**URL:** https://community.freefem.org/t/hmatrix-bem-in-freefem-on-mac-mpi-error-attempting-to-use-an-mpi-routine-before-initializing-or-after-finalizing-mpich/4069
**Category:** FreeFEM installation
**Created:** [September 18, 2025, 6:16am UTC](https://community.freefem.org/t/hmatrix-bem-in-freefem-on-mac-mpi-error-attempting-to-use-an-mpi-routine-before-initializing-or-after-finalizing-mpich/4069 "2025-09-18T06:16:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kamjd](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@Kamjd](https://community.freefem.org/u/Kamjd)
#### Post date: [September 18, 2025, 6:16am UTC](https://community.freefem.org/t/hmatrix-bem-in-freefem-on-mac-mpi-error-attempting-to-use-an-mpi-routine-before-initializing-or-after-finalizing-mpich/4069/1 "2025-09-18T06:16:14Z")

</div>

Hello,

I am trying to run a 2D BEM (Boundary Element Method) simulation in FreeFem++ v4.15 on my Mac. My code uses `HMatrix<complex>` to assemble the system and solve for the boundary unknowns. When I run the script normally, it fails with the following error:

_“Attempting to use an MPI routine (internal\_Comm\_size) before initializing or after finalizing MPICH”_

I have tried running it with `mpirun -np 1`, but the same error appears. I suspect the issue comes from the `bem` plugin or the HMatrix operator trying to call MPI routines without proper initialization. I have installed all dependencies, including LAPACK, BLAS, and Boost, but I cannot get past this error. I am looking for guidance on how to correctly run BEM/HMatrix computations in FreeFem++ on macOS, especially regarding MPI usage.

Any help or suggestions would be greatly appreciated.

Thank you in advance!

---

<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: [September 18, 2025, 6:16am UTC](https://community.freefem.org/t/hmatrix-bem-in-freefem-on-mac-mpi-error-attempting-to-use-an-mpi-routine-before-initializing-or-after-finalizing-mpich/4069/2 "2025-09-18T06:16:47Z")

</div>

Use `ff-mpirun`, not `mpirun`. You likely have multiple MPI implementations mixed up in your system.

---

<div class="post-metadata">

### Author: ![Kamjd](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@Kamjd](https://community.freefem.org/u/Kamjd)
#### Post date: [September 23, 2025, 3:37am UTC](https://community.freefem.org/t/hmatrix-bem-in-freefem-on-mac-mpi-error-attempting-to-use-an-mpi-routine-before-initializing-or-after-finalizing-mpich/4069/3 "2025-09-23T03:37:11Z")

</div>

thank you for your response !
