0

I know that OpenMP is a library that allows one to write multi-threaded applications.

However, I used to use pthread to build thread pools.

I came across someone else's code which uses OpenMP; is it necessary and in which cases is it better than a normal thread pool?

nick
  • 41
  • 6
  • You might want to rephrase your question. The only libraries that are *necessary* for certain functionality are, at most, those provided by your operating system with hooks into system calls. All other libraries can be re-created. That is, instead of using OpenMP, you could write your own version of it. – JaMiT May 21 '21 at 02:11
  • @JaMiT revise the title, thanks – nick May 21 '21 at 02:31
  • OpenMP is always superfluous fluff. But hey, that's just one opinion :-) – Jeffrey May 21 '21 at 02:51
  • 1
    Does this answer your question? [Pthreads vs. OpenMP](https://stackoverflow.com/questions/3949901/pthreads-vs-openmp) – ThivinAnandh May 21 '21 at 03:31
  • https://stackoverflow.com/questions/3949901/pthreads-vs-openmp#:~:text=Pthreads%20and%20OpenMP%20represent%20two,API%20for%20working%20with%20threads.&text=On%20the%20other%20hand%2C%20OpenMP,more%20easily%20scaled%20than%20pthreads. – ThivinAnandh May 21 '21 at 03:31
  • 1
    OpenMP is typically used in HPC. It still has some nice features when compared with pthreads/C++ threads, such as thread pools with task scheduling (we don't have them in C++), simple construct for loop parallelization, atomic access to non-atomic variables (in C++ since C++20), offloading, etc. – Daniel Langr May 21 '21 at 04:02
  • Outside of HPC one of the big pro arguments one hears often is portability. At least if you are only using pragmas and don't include the OpenMP header, your code should even compile and do the right thing (sequentially) on systems where OpenMP isn't available. Depending on what you are doing, pthreads are probably also not an issue, but they might be (at least they are not available natively on Windows?). – paleonix May 21 '21 at 11:04

0 Answers0