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?