0

Please give me inputs if my choice of using OpenMP is right. This is my use-case. We have a Windows C++ software that performs the same huge complex calculations on a set of inputs(each is independent and could be done independently by a thread, where I am planning to use OpenMP). The way this would happen is a loop that loops through the inputs(using a for loop) and calls a function with the input as a parameter(that does the complex calculation). Planning to use #pragma omp parallel for to parallelize the for loop. For some inputs, we might decide not to calculate the whole thing and so return from the function in the middle based on some criteria(requirement of quitting in the middle for some threads).

Also, what are the disadvantages of OpenMP? Why would someone not use OpenMP? Can we use it in a commercial software?

quickdraw
  • 247
  • 1
  • 2
  • 12
  • 1
    I am not familiar with OpenMP implementation in MSVC. Generally, according to your description, `#pragma omp parallel for` is exactly what you want with some dynamic scheduling policy `schedule(dynamic)` possibly with chunk size specification. Disadvantages of OpenMP is that you need a compiler that supports it, otherwise, I like it much more than C++11 threads or POSIX threads. OpenMP has both function-task and data parallelism, it supports thread pools, nowadays even offloading, etc. I am not aware of any obstacles that would hinder the usage of OpenMP in commercial software. – Daniel Langr Feb 23 '18 at 08:06
  • @DanielLangr thanks! I have a while loop with an iterator which I am trying to convert to a for loop and OpenMP would not let me do that easily.. – quickdraw Feb 23 '18 at 10:02
  • You can use OpenMP with iterators as well, at least with _random-access iterators_. See, e.g, my answer here: https://stackoverflow.com/a/36246386/580083. Or, this one: https://stackoverflow.com/a/17853547/580083 – Daniel Langr Feb 23 '18 at 11:18
  • The question is rather broad. Please be more specific about your code and the actual issues you faced, try to illustrate it with a [mcve]. – Zulan Feb 23 '18 at 11:21

0 Answers0