Big overhead when using MPI


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

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!

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

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.

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

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.

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.