Multi-threaded Mex functions in the FEX
Afficher commentaires plus anciens
I've published some C-Mex functions in the FEX, which could benefit from multi-threading. I like to keep the function compatible with Windows, Linux and MacOS.
While I have some experiences with using _beginthreadex and _endthreadex under Windows, I have not worked with the pthread libraries under Linux. Although I can use pthread under Windows also, I do not want to increase the requirements for the users any further - even the compilation with the "mex" command is too confusing for some users already.
OpenMP is not available in the free MSVC Express compilers. And installing MinGW to compile the Mex files is not trivial also.
What are simple solutions for a platform independent multi-threading in C- or C++-Mex-functions?
2 commentaires
Jan
le 22 Déc 2011
Yair Altman
le 6 Mar 2014
I believe that using winpthreads-32 (which works on Win64 as well as Win32, despite the name) is easier than MinGW. See my latest article on UndocumentedMatlab.com. Since Pthreads are natively supported on Macs & Linux, this could be the winning combination.
Réponse acceptée
Plus de réponses (2)
Peter Li
le 3 Juil 2012
2 votes
With C++11 your general problem should be solved? Search stackoverflow (or perhaps Matlab answers) for how to compile mex with C++11.
Even if you get C++11 working, C++ multithreading is not much fun, so I recommend instead using the Theron Actors library. It's nice to do multithreading under the Actors model and this library is pretty efficient and very well documented. And it allows you to flexibly link in different threading solutions.
The only problem with this is that if you use boost-thread for the threading under Linux the linking step will conflict with the boost-thread Matlab uses internally, so that will require more struggling with mex to get working.
1 commentaire
Jan
le 3 Juil 2012
Catégories
En savoir plus sur Call C++ from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!