bayesmix-dev / bayesmix

Flexible Bayesian nonparametric mixture models in C++
https://bayesmix.rtfd.io
BSD 3-Clause "New" or "Revised" License
22 stars 18 forks source link

Parallel dens #114

Closed mberaha closed 2 years ago

mberaha commented 2 years ago

This will close #59. Many things are needed for parallel density evaluation and, in particular, the possibility to perform a "deep clone" of the hierarchy and basically of the algorithm.

The last part is actually crucial and it's not clear to me if what we're doing right now results in a deep copy of the data matrix. What do you guys think?

At the moment the code works only for the MemoryCollector (I will dig into this) but provides a stable 60% speedup. There is a better parallelisation strategy that would get all the chains, split the MCMC chains into #(parallel core) shards and process these shards in parallel. In this way we avoid cloning the Algorithm num_iteration times, but need to load all the chains in memory... Again, what do you think?

brunoguindani commented 2 years ago

I will look into this once you've merged master into this branch, so that it's a little easier to parse. 😅 (Maybe let's also merge #108 first?)

mberaha commented 2 years ago

There is a better parallelisation strategy that would get all the chains, split the MCMC chains into #(parallel core) shards and process these shards in parallel. In this way we avoid cloning the Algorithm num_iteration times, but need to load all the chains in memory... Again, what do you think?

Now we have both strategies available using a bool low_memory flag. The second strategy is 20-50% faster than the first one but requires much more memory

mberaha commented 2 years ago

Still a draft (need to check that with dependent stuff everything works), but seems to run fire also with the FileCollector. I think you guys can proceed with a first round of review

brunoguindani commented 2 years ago

Sure, thank you. I will read it in the next couple days