5

I am currently working on a project that mixes high-performance computing (HPC) and interactivity.
As such, the HPC part relies on OpenMP (mainly for-loops with lots of identical computations) but it is included in a larger framework with a GUI and multithreading, currently achieved with c++11 threads (std::thread and std::async).

I have read Does OpenMP play nice with C++ promises and futures? and Why do c++11 threads become unjoinable when using nested OpenMP pragmas? that it is no good idea to mix OpenMP and C++11 threads, but so far it has been working for me.
For different reasons, I would like to improve on this, but I am not sure which strategy to adopt.

At OpenMP vs C++11 threads, I read that replacing OpenMP by std::thread has a considerable impact on performance due to creation and destruction of threads, but I couldn't find anything about replacing OpenMP acceleration by task-based parallelism with std::async. In my opinion, this should be faster than std::thread because then the thread managing is done by the operating system, but I am not convinced yet that this is applicable. I haven't tried it yet because it would involve loads of refactoring and I would have liked to hear other opinions first.

Do you have any experience with reconciling HPC and interactivity? In your eyes, should std::async be comparably fast to OpenMP?

Community
  • 1
  • 1
oLen
  • 5,177
  • 1
  • 32
  • 48
  • 4
    "this should be faster than std::thread because then the thread managing is done by the operating system" <-- `std::thread` is also "managed by the operating system". Ultimately, both OpenMP and `std::thread` are wrapping the OS native threading facilities. Nothing intrinsically makes either one of them more or less native. – ShadowRanger Dec 16 '15 at 16:04
  • What I meant is that the OS has more freedom how to execute the task with a call to `std::async` than with `std::thread`, if I remember correctly what Scott Meyers says in Effective Modern C++. Thus I thought that the OS looks itself whether thread creation, destruction, etc is needed or not and that in the end performance should be better. Isn't that correct? – oLen Dec 17 '15 at 07:23
  • Have you seen [this question](http://stackoverflow.com/questions/13837696/can-i-safely-use-openmp-with-c11)? On the topic of reconciliation, have you considered having your HPC code run in a separate process and then have the GUI talk to it via some sort of IPC? Also, OpenMP is not the only multiprocessing option - there are Intel TBB, Microsoft C++ AMP, etc. – Hristo Iliev Jan 15 '16 at 20:42
  • @HristoIliev Thanks, your answer there is definitely helpful! – oLen Jan 18 '16 at 16:46

0 Answers0