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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:11:46+00:00 2026-06-07T16:11:46+00:00

I have a big array, iterating and doing my work over it takes about

  • 0

I have a big array, iterating and doing my work over it takes about 50ms.
App i am developing will run on tegra3 or other fast cpu.
I have divided my work for four threads, using pthread, i have taken
width of my array, divided it by total core count found in system, and i am iterating for 1/fourth of array in each thread, everything is ok, but it now need 80ms to do the work.
Any idea why multithread approach is slower than single thread? If i lower cpu count to 1 everything is back on 50ms.

for(int y = 0; y<height;y++)
{
    for(int x = 0; x<width; x++)
    {
        int index = (y*width)+x;
        int sourceIndex = source->getIndex(vertex_points[index].position[0]/ww, vertex_points[index].position[1]/hh);
        vertex_points[index].position[0]+=source->x[sourceIndex]*ww;
        vertex_points[index].position[1]+=source->y[sourceIndex]*hh;
    }   

};

i am dividing first for loop of above code into four parts based on cpu count.
vertex_points is a vector with positions.

so it looks like

for(int y=start;y<end;y++)

and start/end vary on each thread

  • 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-07T16:11:48+00:00Added an answer on June 7, 2026 at 4:11 pm

    Thread startup time is typically on the order of milliseconds – that’s what’s eating your time.

    With that in mind, 50 ms is not the kind of delay I’d worry about. If we were talking 5 seconds, that’d be a good candidate for paralellizing.

    If the loop needs to be performed often, consider a solution with threads that are spun up early on and kept dormant, waiting for work to do. That’ll run faster.

    Also, is the CPU really 4-core? Honest cores or hyperthreading?

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

Sidebar

Related Questions

I have a Boost.MultiIndex big array about 10Gb. In order to reduce the reading
I have big problem when I am trying to deploy my app over clickonce.
I have a very big constant array that is initialized at compile time. typedef
I need to create a big array in my code, I have the values
I have on array like: $myarray = array(color, red, size, big, flavor, bitter); where
I have a big array of voxels, a la Minecraft. The player/enemies are in
I have a big array which i need to display the latest 10 items
I am writing a PHP function that will need to loop over an array
I have a big array, that I would like to load into memory only
I have a very big array stored in memory after reading a whole file

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.