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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:26:45+00:00 2026-06-06T16:26:45+00:00

I have a function which is very parallelized in OpenMP, when launched from a

  • 0

I have a function which is very parallelized in OpenMP, when launched from a simple console executable it saturates every core of the machine and returns the result linearly faster in the number of processors.

void updateStateWithAParallelAlgorithm()
{
    #pragma omp parallel for
    {
    // do parallel things, update positions of particles in a physics simulation
    }
}

Now this function is also used inside a QThread in my Qt program. The problem is that I have to update screen positions of the particles every after a call of updateStateWithAParallelAlgorithm() function.

When launched inside my Qt main program, I see no improvement in speed of the algorithm and the 8 cores of my processor are not saturated.

I would rather believe that I should see a peak-pause behaviour on the graph of CPU usage, but this doesn’t happen.

Now, I’m giving you more informations.

class MyComputationThread :  public QThread
{
    Q_OBJECT
    // some methods
    // some variables
    void doComputation()
    { 

        this->setPriority(QThread::HighestPriority);

        #ifdef Q_WS_X11
          int s;
          cpu_set_t cpuset;
          CPU_ZERO(&cpuset);
          CPU_SET(1, &cpuset);
          s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
          if (s != 0) {
            perror("pthread_getaffinity_np");
          }
        #endif

        updateStateWithAParallelAlgorithm();
    }
}

I would like to understand how my thread MyComputationThread class can exploit the multicore, without being constraint to only one CPU as in the statement of pthread_set_affinity_np.

  • 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-06T16:26:47+00:00Added an answer on June 6, 2026 at 4:26 pm

    According to the pthread_setaffinity_np(3) manual page:

    A new thread created by pthread_create(3) inherits a copy of its creator’s CPU affinity mask.

    You are limiting the particular MyComputationThread instance to run on a single core only and thus are also limiting all threads spawned by the OpenMP run-time to also run on the same core. You should either remove the call to pthread_setaffinity_np() or move the call to updateStateWithAParallelAlgorithm() before the part that sets the affinity.

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

Sidebar

Related Questions

I have the following function which works very well within a $(document).ready(function(){ $('.threadWrapper >
I have a function which zips files and downloads them to the users machine.
I have the function below which I call very frequently in a loop. I
I have a function which returns an int value for a given key (from
I have a function which works a very slow for my task (it must
Let's say I want to have a function which reads data from the SerialPort
I have a JavaScript function buildTable which builds a very long HTML table. function
There is this simple function which I have used with C++ in the past
I'm trying to write a very simple function which displays a div that says
I have a function in which I'm trying to resize a photo twice from

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.