title: Statically partitioning tbb::parallel_for
body: <p>I have a dataset which I'd like to consume with <code>tbb::parallel_for</code> in intervals of size <code>interval_size</code>. Each interval that my functor consumes should be <code>interval_size</code>, except for the last partial interval, which may be smaller when <code>interval_size</code> does not evenly divide my dataset.</p>
  
  <p>Is there a way to use TBB to statically partition in this manner? This test produces several intervals smaller than <code>interval_size</code> on my system:</p>
  
  <pre><code>#include &lt;tbb/parallel_for.h&gt;
  #include &lt;iostream&gt;
  
  struct body
  {
    void operator()(const tbb::blocked_range&lt;size_t&gt; &amp;r) const
    {
      std::cout &lt;&lt; "range size: " &lt;&lt; r.end() - r.begin() &lt;&lt; std::endl;
    }
  };
  
  int main()
  {
    size_t num_intervals = 4;
    size_t interval_size = 3;
  
    // consume num_intervals plus a partial interval in total
    size_t n = num_intervals * interval_size + (interval_size - 1);
    tbb::parallel_for(tbb::blocked_range&lt;size_t&gt;(0, n, interval_size),
                      body(),
                      tbb::simple_partitioner());
  
    return 0;
  }
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>$ g++ test_parallel_for.cpp -ltbb
  $ ./a.out 
  range size: 3
  range size: 2
  range size: 2
  range size: 3
  range size: 2
  range size: 2
  </code></pre>