Is the following a valid use, if the first parallel_for works on data that the second parallel_for will use. I haven't seen any use of affinity_partitionershared between loops, which is why I was a bit unsure.
tbb::affinity_partitioner ap;
std::vector input;
std::generate_n(std::back_inserter(input), 4096, []{return rand();});
std::vector result(input.size();
std::vector result2(input.size();
// Do some calculations
tbb::parallel_for(tbb::blocked_range(0, input.size()), [&](const blocked_range& r)
{
for(int n = r.begin(); n != r.end(); ++n)
result[n] = do_some_calc(input[n]); // temporal store
}
, ap);
// Do some more calculations
tbb::parallel_for(tbb::blocked_range(0, input.size()), [&](const blocked_range& r)
{
for(int n = r.begin(); n != r.end(); ++n)
result2[n] = do_some_calc(result[n]);
}
, ap);
Basicly what I want is that second parallel_for will map its ranges in the same way as the first parallel_for in order to fully utilize the local caches.



