# Big overhead when using MPI

**URL:** <https://community.freefem.org/t/big-overhead-when-using-mpi/3211>\
**Category:** General Discussion\
**Created:** [May 4, 2024, 4:43pm UTC](https://community.freefem.org/t/big-overhead-when-using-mpi/3211 "2024-05-04T16:43:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcvillaquira](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/jcvillaquira/32/2016_2.png) [@jcvillaquira](https://community.freefem.org/u/jcvillaquira)\
**Post date:** [May 4, 2024, 4:43pm UTC](https://community.freefem.org/t/big-overhead-when-using-mpi/3211/1 "2024-05-04T16:43:54Z")

</div>

Hi,

I am coding a project in which I need to call a FF++ script multiple times. This is script is parallelized (and this saves a lot of time) but there is a big overhead. As a mwe, when running a single script with one line containing `int r = 0;` by executing

```auto
start=`date +%s%N`; mpiexec -n 1 FreeFem++-mpi ff_scripts/sandbox.edp -v 0; end=`date +%s%N`; echo `expr $end - $start`

```

it shows that the total running time was approximately 1.3 seconds, while compiling and running the script takes less than 0.007 seconds (`compile 0.006177s, execution 3e-05s`).

Is there any way to reduce such a big overhead? 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:** [May 4, 2024, 5:59pm UTC](https://community.freefem.org/t/big-overhead-when-using-mpi/3211/2 "2024-05-04T17:59:37Z")

</div>

Do not launch multiple times, and do the logic within the script instead of in the terminal.

---

<div class="post-metadata">

**Author:** ![jcvillaquira](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/jcvillaquira/32/2016_2.png) [@jcvillaquira](https://community.freefem.org/u/jcvillaquira)\
**Post date:** [May 4, 2024, 6:13pm UTC](https://community.freefem.org/t/big-overhead-when-using-mpi/3211/3 "2024-05-04T18:13:04Z")

</div>

I cannot do it since the inputs of the n-th call depend the output of the (n-1)-th call. The outputs need to be processed in another program (written in Julia) before passing them.

---

<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:** [May 4, 2024, 6:40pm UTC](https://community.freefem.org/t/big-overhead-when-using-mpi/3211/4 "2024-05-04T18:40:05Z")

</div>

Well… then you have your answer for the question `Is there any way to reduce such a big overhead?`

---

<div class="post-metadata">

**Author:** ![jcvillaquira](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/jcvillaquira/32/2016_2.png) [@jcvillaquira](https://community.freefem.org/u/jcvillaquira)\
**Post date:** [May 4, 2024, 9:37pm UTC](https://community.freefem.org/t/big-overhead-when-using-mpi/3211/5 "2024-05-04T21:37:01Z")

</div>

But the overhead is independent of that . . . Whether it is just a simple script called directly from bash or a complex one called from somewhere else.

---

<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:** [May 5, 2024, 5:59am UTC](https://community.freefem.org/t/big-overhead-when-using-mpi/3211/6 "2024-05-05T05:59:05Z")

</div>

If it’s a “complex” script, then it’s likely to take a few second to complete, thus the overhead if relatively tiny, so it’s not an issue. Using MPI to run extremely fine-grained computations does not make sense, it was not designed for that, hence why I told you to not invoke `FreeFem++-mpi` multiple times.
