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 7865547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:07:23+00:00 2026-06-03T00:07:23+00:00

I have a embarrassingly parallel problem that I want to execute on multiple processors.

  • 0

I have a embarrassingly parallel problem that I want to execute on multiple processors. I had supposed that boost::thread would automatically send new threads to new processors, but all of them are executing on the same core as the parent process. Is it possible to get each thread to run on a different processor, or do I need something like MPI?

My suspicion is that boost::thread is simply not a multi-processor tool, that I’m asking it to do something it’s not designed for.

EDIT: my question boils down to this: Why do all the threads execute on one processor? Is there a way to get boost::thread to send threads to different processors?

Here’s the relevant sample of my code:

size_t lim=1000;
std::deque<int> vals(lim);
std::deque<boost::thread *> threads;
int i=0; 
std::deque<int>::iterator it = vals.begin();
for (; it!=sigma.end(); it++, i++) {
  threads.push_back(new boost::thread(doWork, it, i));
  while (threads.size() >= maxConcurrentThreads) {
    threads.front()->join();
    delete threads.front();
    threads.pop_front();
  }
}
while(threads.size()) {
  threads.front()->join();
  threads.pop_front();
}

As should be clear, doWork does some calculation using the parameter i and stores the result in vals. My idea was that setting maxConncurrentThreads to be equal to the number of cores available, and then each thread would use the core that was idle. I just need someone to confirm that boost::thread cannot be made to work in this way.

(I’d guess that there’s a better way to limit the number of concurrent threads than using a queue; feel free to scold me for that as well.)


Here’s the doWork function:

void doWork(std::deque<int>::iterator it, int i) {
  int ret=0;
  int size = 1000; // originally 1000, later changed to 10,000,000
  for (int j=i; j<i+size; j++) {
    ret+=j;
  }
  *it=ret;
  return;
}

EDIT: As Martin James suggested, the problem was that the doWork function was initially only 1000 int additions. With such a small job, scheduling the thread took longer than executing the thread, so only one processor was in use. Making the job longer (adding 10,000,000 ints) yielded the desired behavior. The point being: boost::thread will use multiple cores by default, but if your threads do less work than scheduling the thread then you won’t see any benefit from multithreading.

Thanks to everyone for aiding my understanding in this.

  • 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-03T00:07:24+00:00Added an answer on June 3, 2026 at 12:07 am

    You are always joining the first thread in the queue. If this thread is taking a long time it might be the only thread left. I guess what you want is to start a new thread once any thread has completed.

    I don’t know why you only get an effective concurrency level of only one though.

    After having looked at the doWork function I think that it is doing so little work that it is taking less work than starting a thread in the first place. Try running it with more work (1000x).

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

Sidebar

Related Questions

I have what I believe to be an embarrassingly simple problem, but three hours
I have a simple request that I have spent much time on (embarrassingly).. I
Embarrassingly newbie question: I have a string field in my model that contains line
I have some embarrassingly-parallelizable work in a .NET 3.5 console app and I want
We have a client requirement that has stumped me, embarrassingly enough. The client has
Graphics is one of those embarrassingly parallel problems. Haskell is supposed to be really,
Have you guys had any experiences (positive or negative) by placing your source code/solution
I have a String Collection that is populated with ID's like so --> 12345
I run across a lot of embarrassingly parallel projects I'd like to parallelize with
I have a computational algebra task I need to code up. The problem is

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.