Here's a interesting mathematical question: Is there a way to define a range object that lets us write a parallel_for that iterates over permutations of a set of N objects? Better yet, can it be done so that subranges are always in lexicographic order?
Here's how it might be used. The parallel_for invocation might look something like:
parallel_for( perm_range(N), Body() );
and Body::operator() might look something like:
void Body::operator()( const perm_range& r ) {
permutation p = r.begin();
while( p!=r.end() ) {
...process the permutation...
...get the next permutation...
std::next_permutation( p.begin(), p.end() );
};
}
For example, for N=3, we would want the permutations:
0 1 2
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0
to be generated. The hard part is figuring out how to divide a permutation range into two roughly equal subranges.
- Arch
P.S. TBB does support recursive parallelism, so it's straightforward to write a recursive program that does permutations in parallel, using a parallel_for at each recursion level. I can post that code if anyone cares.



