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

  • Home
  • SEARCH
  • 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 728923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:44:14+00:00 2026-05-14T06:44:14+00:00

I’m writing a program in C++ to perform a simulation of particular system. For

  • 0

I’m writing a program in C++ to perform a simulation of particular system. For each timestep, the biggest part of the execution is taking up by a single loop. Fortunately this is embarassingly parallel, so I decided to use Boost Threads to parallelize it (I’m running on a 2 core machine). I would expect at speedup close to 2 times the serial version, since there is no locking. However I am finding that there is no speedup at all.

I implemented the parallel version of the loop as follows:

  • Wake up the two threads (they are blocked on a barrier).
  • Each thread then performs the following:

    • Atomically fetch and increment a global counter.
    • Retrieve the particle with that index.
    • Perform the computation on that particle, storing the result in a separate array
    • Wait on a job finished barrier
  • The main thread waits on the job finished barrier.

I used this approach since it should provide good load balancing (since each computation may take differing amounts of time). I am really curious as to what could possibly cause this slowdown. I always read that atomic variables are fast, but now I’m starting to wonder whether they have their performance costs.

If anybody has some ideas what to look for or any hints I would really appreciate it. I’ve been bashing my head on it for a week, and profiling has not revealed much.

EDIT: Problem solved!
I’m going to detail how I solved this problem. I used gprof again, but this time compiled without the optimization flag (-O3). Immediately, the profiler indicated that I was spending an incredible amount of time in the function which performs the computation on each individual particle: much more than in the serial version.

This function is virtual and accessed polymorphically. I changed the code to access it directly rather than through the vtable and voila’ the parallel version produced a speedup of nearly 2! The same change on the serial version had little effect.

I’m not sure why this is so, and would be interested if anyone knows!

Thanks to all the posters. You all helped to some extent and it will be very difficult to accept one answer.

  • 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-05-14T06:44:15+00:00Added an answer on May 14, 2026 at 6:44 am

    Perform the computation on that particle, storing the result in a separate array

    How heavy are computations?

    • Generally speaking atomic counter may cost hundreds of clock cycles and it is quite important to
      see that you do not only increment counters.
    • Also try to see how much job each thread does – do they cooperate well (i.e. on each cycle each proceeds about half of particle).
    • Try to subdivide the job to bigger chunks then single particle (let’s say 100 particles and so on).
    • See how much job is done outside of threads.

    Honestly… it looks like what are you talking about is a bug.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.