maltezfaria / ImplicitIntegration.jl

MIT License
3 stars 0 forks source link

Add threading #11

Open antoine-levitt opened 1 month ago

antoine-levitt commented 1 month ago

Just spawn a task per box at the highest level and have them all accumulate their result somewhere should be enough, I think? Probably with a minimum box size to avoid spawning too many tasks, but the workload of each box should be big enough to avoid overhead.

maltezfaria commented 1 month ago

I think it would be better to simply split the original domain into a grid and add threads there. We could add such a functionality here, but we can also simply have an example (or just say it?) to the docs.

Threading directly the algorithm can be a bit tricky due to race conditions in several places. Certainly doable, but not sure it is worth it.

antoine-levitt commented 1 month ago

Definitely makes sense, except load balancing is tricky (@threads :greedy is probably appropriate) so you'd need to have much more tasks than threads, which limits parallelism, so true parallelism would definitely be better (but also more of a hassle). Good to think about in relation with the idea to split the algorithm in two stages (determine the boxes, then run on them)

maltezfaria commented 1 month ago

Yes, I think the two-stage method would be a good place to parallelise things, although parallelising the first pass of the algorithm, where bounds are computed and so on, will be tricky as well. In any case, for now I think the "split the domain and parallelise" seems like a reasonable approach/suggestion.