0

I'm making an algorithm that could break a piece in sub-pieces... or not, and each sub-piece could be broken again etc. Yes it is the perfect example for a recursive function but due to performance reasons I tried to do it in a parallel for.

omp_set_num_threads(omp_get_num_procs());
#pragma omp parallel for schedule(dynamic)
for (int index = 0; index < toMakePartition.size(); index++)
{
    mItemClass* currItem = toMakePartition[index];
    makePartition(currItem);

    #pragma omp critical
    {
        for (int child = 0; child < currItem->children.size(); child++)
        {
            toMakePartition.push_back(currItem->children[child]);
        }  
        int numPartitionItems = toMakePartition.size();
        printf("END %i of %i   \n\n", index, numPartitionItems);
    }
}

The print shows that the numPartitionItems is growing correctly but unfortunately after the first loop it exits. Without the OpenMP parallelism the algorithm works without any problem.

Any idea on how could I make this parallel version work?

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Frank Escobar
  • 368
  • 4
  • 20
  • please provide a complete example -- how do you run it? – OrenIshShalom Jun 25 '18 at 17:57
  • Note: If you're considering to reformulate this as recursion, you could also use OpenMP tasks. But that would probably be a step back. From having the BFS-queue. – Zulan Jun 25 '18 at 18:39

0 Answers0