0

I am using Visual Studio 2015 and need to compile some tree code, which is parallelized with OpenMP tasks like this:

void recursiveFunction(Object *input_obj) {
    for(Obj * loop_obj=input_obj->child; loop_obj!= input_obj->child + input_obj->numChildren; loop_obj++) {
#pragma omp task untied if(loop_obj->numValues > 100)
        recursiveFunction(loop_obj);
    }
#pragma omp taskwait
}

As Visual Studio 2015 does not support OpenMP 3.0 tasks, I need to refactor it using OpenMP 2.0 functions. I do not know what is the best way to do it, i though of something like this

void recursiveFunction(Object *input_obj) {
#pragma omp parallel for
    for(int idx =0; idx < input_obj->numChildren;i++) {
    // TODO: some code to replace the numValues > 100 condition
        Object * loop_obj = obj + i;
        recursiveFunction(loop_obj);
    }
}

But I think OpenMP tasks will limit the number of threads during the recursion, while the parallel for construct spawns for each loop reached one process per processor (or the number of threads configured).

So what is the most elegant and efficient way to replace the original construct?

allo
  • 3,955
  • 8
  • 40
  • 71
  • 1
    Well, there's a reason that `task`s were added to the standard 9 years ago. Take a look at [this excellent answer](https://stackoverflow.com/a/13789119/620382), it might help you. There's also [this similar unanswered question](https://stackoverflow.com/questions/17347252/parallelize-recursive-function-with-openmp-v-2-0). – Zulan Sep 24 '17 at 08:51
  • 1
    The most elegant and efficient way to solve your problem is to use a compiler that supports modern OpenMP. GCC and Clang both do and are free, the Intel compiler does but costs cash (unless you fall into various categories like "student at a degree granting institution"). (The problem is not Visual Studio per se, but the Microsoft compiler which is a small component of VS. So you don't necessarily have to do away with your whole environment; theIntel compiler integrates into it just fine). Full disclosure: I work for Intel – Jim Cownie Sep 25 '17 at 08:29
  • 1
    I see the point and would like to, but this would be a big step and I do not know what from the legacy code base will fail to work then. And I would need to agree on such changes with the customer. So I am currently looking for a smaller change, if possible. I already thought about testing clang, but I think its a rather big step. The Intel compiler could be nice as well, but again we would need to get permission to by licences first. – allo Sep 25 '17 at 13:14

0 Answers0