Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:12:48+00:00 2026-06-11T13:12:48+00:00

I have a dataset which I’d like to consume with tbb::parallel_for in intervals of

  • 0

I have a dataset which I’d like to consume with tbb::parallel_for in intervals of size interval_size. Each interval that my functor consumes should be interval_size, except for the last partial interval, which may be smaller when interval_size does not evenly divide my dataset.

Is there a way to use TBB to statically partition in this manner? This test produces several intervals smaller than interval_size on my system:

#include <tbb/parallel_for.h>
#include <iostream>

struct body
{
  void operator()(const tbb::blocked_range<size_t> &r) const
  {
    std::cout << "range size: " << r.end() - r.begin() << 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<size_t>(0, n, interval_size),
                    body(),
                    tbb::simple_partitioner());

  return 0;
}

The output:

$ 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:12:49+00:00Added an answer on June 11, 2026 at 1:12 pm

    The reason for the behaviour is that the simple partitioner partitions your range by the following criteria:

    ceil(grainsize/2) <= chunksize <= grainsize

    when used with tbb::blocked_range(i, j, grainsize) and chunksize is the size of your range.

    You can check the Tutorial for more information under 3.2.5 Partitioner Summary.

    There is no easy way to get a fixed size chunksize with TBB (you can easily achieve this with OpenMP). That is because this is against the concepts of TBB. TBB tries to abstract all those stuff away from you and the scheduler makes sure that your threads are used the best as possible on runtime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a dataset which has two columns that I'd like to compare.
I have a UltraWinGrid that is bound to a DataSet, in which a couple
i have a dataset which is like the following, however much larger: 5 6
I have a dataset with labels which I would like to plot with points
I have a DataSet which I get a DataTable from that I am being
If I have a dataset in R which looks like this below: ProjName,ProjLevel,Budget Proj1,Hardware,$100
I have DataSet which has 3 columns. Name - insurance comp. name - treatmentDate
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I have a 2-class dataset on which I should apply a binary classification algorithm.
I have created a dataset in my visual studio project which is connected to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.