Parallel for loop in freefem

Hi,

Is there any easy way to run a for loop in parallel in FreeFem++?

For example the majority of code below could be run in parallel:

int N = 1e6;
real[int] a(N), b(N);

// This loop could be parallel:
for (int i = 0; i < N; i++) {
  a(i) = i;
  b(i) = -i;
}

real[int] c(N);
// Also this could be parallel:
for (int i = 0; i < N; i++) {
  c(i) = a(i) - b(i);
}

you can use MPI and run each loop on a proc

Are there any simple examples on that?

1 Like

Hello, distractor. I am a starter and I want to run a for loop in parallel, too! It seems that you have succeeded and would you please show your codes to me? Thanks a lot!

You can look at the examples, search for “mpirank” but if you do this be sure
to check the wall clock time. AFAICT, this generates processes and
communicators etc. For something short you may benefit more from
thrads communicating with shared memory. In my c+ code I use openmp
compiler directives and they seem to generate some speed up although
I have not quantified it ( generally this is a last resort for me as parallel
has overhead even from threads but mpi processes don’t even have to run
on the same LAN lol )
And I’d also note that these things take over cores- at the end all the cores would
be at 100 percent CPU in spin wait lol.

Maybe someone can comment on thread vs process in FF as I have not looked
too closely at that yet.