GeometryCollective / boundary-first-flattening

MIT License
761 stars 97 forks source link

Crash when running multiple instances of BFF on a multi-threaded environment #48

Open calvariomind opened 5 years ago

calvariomind commented 5 years ago

Hi there, What a great piece of software! I've been using other flattening algorithms on my applications and this one really makes a big difference in speed, stability and quality on the result flattening.

Unfortunately, it doesn't apear to support a multithreaded environment. I'm trying to flatten multiple meshes concurrently on multiple threads, and I always get a crash during the flattening. The crash doesn't happen if I run the flattenings sequentially. Looking at the call stack, it appears that the crash is somewhere inside a choldmod library function.

Does anyone run into this problem and knows hot to solve it? Is there any known limitation regarding BFF and multithreading?

Thanks in advance, José Calvário

rohan-sawhney commented 5 years ago

Thanks @calvariomind! Unfortunately, the current version is not thread safe because of how it is linked with Cholmod. However, it is possible to make the Cholmod dependency thread safe. I've listed this issue as an enhancement :)

calvariomind commented 5 years ago

Thanks for the quick reply rohan :) If I understand correctly, the limitation is on cholmod library, not on BFF. Can I do something on my side to resolve the problem without changing BFF code? Maybe linking with a different version of cholmod? Thanks

rohan-sawhney commented 5 years ago

I should correct myself - some of the BFF linear algebra code will have to be modified, starting with not declaring a global cholmod Common object but rather cholmod Common objects local to each thread. I'll have to put some more thought on how exactly to architect this within the BFF codebase. If you don't want to dig into cholmod, another option might be to replace the implementation of the BFF linear algebra wrappers (such as DenseMatrix, SparseMatrix, Cholesky) with another library such as Eigen.

calvariomind commented 5 years ago

Thanks again for your answers. I will continue using BFF as is, without multi-threading. It is fast enough for my current purposes. I will be watching for new versions, and reactivate the multi-threading in case you decide to make those changes. Congratulations for a great library :)