I am wondering if I can parallelize this code using OpenMP. Will OpenMP make the code run faster? Is there a better way to achieve this?
vector<int> t; // already initialized
do{
// Something with current permutation
} while(next_permutation(t.begin(), t.end()));
I know I can easily parallelize a for instruction, but here I have a while (condition = true).
Use Finding n-th permutation without computing others to get the kth permutation, for
k=i*n/count,ifrom0tocount, wherenis the number of permutations,iis an index, andcountis the number of threads.This gives you
countblocks or intervals. Iterate within each interval in a separate thread in parallel, callingnext_permutationrepeatedly in each thread.