Solving a lot of independent ODEs in parallel

Hi!

I am considering a time-dependent fluid-kinetic problem for which, at every time step, I have a PDE to solve (that’s ok, it takes 3 seconds and that is fine by me) and ODEs for 200 particles. In order to solve these independent ODEs, I need a quite small discretization (about 8000 iterations) which leads to very long computation times (800 seconds to solve the 200 ODEs, multiplied by about 600 global time steps…).

Since the ODEs are independent from one another (they only depend on the solution of the PDE I solve at each global time step and a few other global variables), I was thinking I could have them solved on different cores and retrieve the result after each global iteration (I need it for the next global step of the PDE).

Hence my question: how could I do that?

Thanks for any advice or reference!

David

(PS: if the solution would work on the version 3.430002 that would be great because of the issue I raised on git with the function convect in 3D)

Use MPI, it’s an embarrassingly parallel job, so trivial to parallelize.

int ntask = 200;
for(int i = (mpirank * ntask) / mpisize; i < ((mpirank + 1) * ntask) / mpisize; ++i) {
  cout << "process #" << mpirank << " dealing with task #" << i << endl;
}
mpiAllreduce(...); // for synchronization

Thanks for the quick answer!

Say the unknown of my ODE is the radius of the particle and that I want to write, at each global time-step, the result in a file, then I should do something like this:

real[int] radius(number_of_particle);
real[int] radiusLoc(number_of_part_per_proc);

for(int i = mpirank * number_of_part_per_proc ; i < (mpirank+1) * number_of_par_per_proc ; i++){
    //solve the ODE on radiusLoc[i-mpirank*number_of_part_per_proc]
}
mpiGather(radiusLoc, radius, processor(mpiCommWorld,0));

if(mpirank==0){
   string file0="radii.txt";
   ofstream .....
}