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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:20:01+00:00 2026-05-28T17:20:01+00:00

I can’t figure out the problem in the following short script which should compare

  • 0

I can’t figure out the problem in the following short script which should compare a single CPU computation with a parallelization concerning computation time.

parfor
Link to full image: LINK

The code is:

n = 700;
ranksSingle = zeros(1,n);
tic
for ind = 1:n
    ranksSingle(ind) = rank(magic(ind));
end
toc

matlabpool local 4
tic
ranks = zeros(1,n);
parfor (ind = 1:n)
    ranks(ind) = rank(magic(ind));
end
toc
isequal(ranksSingle, ranks)
matlabpool close

I also tried it with matlabpool 2. As you can clearly see from the process window, all cores are busy to 100% when running the parallel computation (marked red).

When running the single-cpu computation (marked blue), strangly the 4 cores are also more busy than before. I would have expected only ONE core to go up. I searched the internet to see, if perhaps the magic() or rank function are built-in parallelized, but as you can read from here: http://www.walkingrandomly.com/?p=1894 it’s not the case. So it’s okay that those 4 cores are not fully busy, but still I’m wondering why ALL cores go up.

Secondly, I really wonder the computation time of the parallelized version. I know there’s some sort of overhead by distributing the jobs to the single cores, but this shouldn’t be so high that there’s no benefit at all in the end 🙁

Perhaps anybody can tell me something about it 🙁 I’m really stuck at this since I want to speed up some of my for-loops. Second question is, if there’s any command to always set the worker size to the number of physical cores I have in my computer? (and also using Hyper Threading if that’s an additional benefit?)

Thanks a lot!

  • 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-28T17:20:02+00:00Added an answer on May 28, 2026 at 5:20 pm

    When you want to run a parallel job, you should remember that it’s bad to have too many fast iterations, and that it’s bad to have too few slow iterations. If you do a million iterations that each take a few miliseconds, the overhead from parallelization will destroy any possible gain. If you do nine iterations that take an hour each, and you run it on eight processors in parallel, seven processors will be idling for an hour waiting for iteration #9 to finish.

    Thus, your example is pretty bad for testing the impact of parallelization, because both magic and rank are way too fast.

        function testParfor2
        tic
        for i=1:4
            pause(1); %# wait for 1 second
        end
        toc
        matlabpool open 4
        tic
        parfor i=1:4
            pause(1); %# wait for 1 second
        end
        toc
    
    Elapsed time is 4.050287 seconds.
    Elapsed time is 1.534534 seconds.
    

    Note that I was running a second parallel job at the same time, but roughly, the result should be reproducible: There is a bit of overhead (note that I didn’t count the time used by matlabpool!), but the speed-up is there. You should be seeing the same amount of overhead if you increase the pause length. Also, you should be testing with your actual loops (try to parallelize the outermost loop, btw).

    To your second question:

     matlabpool open
    

    Will create as many workers as there are physical cores. Hyperthreading will help you ensure that the computer remains responsive when the parallel job is running.

    Finally, while magic and rank may not be fully multithreaded by themselves, they may make calls to multithreaded routines.

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

Sidebar

Related Questions

can you recommend some good ASP.NET tutorials or a good book? Should I jump
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can anyone give me an example of how to return the following json simply
Can someone tell me why the following does not match: >>> re.search(r'(\d{2, 10})', '153')
Can't work out a way to make an array of buttons in android. This
Can anyone help me trying to find out why this doesn't work. The brushes
Can someone help me? I am trying to do something like the following: #include
Can anyone please send me the script to delete the old backup files greater
Can we do following in SQL Server 2005 query with convert function. MaxRegID =
Can anybody help me? What should be the datatype for this type -07:00:00 of

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.