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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:07:06+00:00 2026-05-23T08:07:06+00:00

So I have some computationally heavy code that can happily chug along using 32

  • 0

So I have some computationally heavy code that can happily chug along using 32 threads or more efficiently. I also have access to a cluster through my school that has 32 processor cores. “Sweet!” you might say.

But, alas, the code gets very unhappy if you don’t have each thread paired in a dedicated way to a processor. For the numerically inclined, my BLAS implementation takes major hits to efficiency if the thread it’s running on gets swapped out for another. This wouldn’t be an issue, except that the cluster is in a state of anarchy.

There’s no job scheduler or queue, and the cluster won’t stop people from launching jobs, even if all of the resources are already spoken for.

Here’s my question: When I log on and want to run my code, I see four people already on. They might be running some combination of serial and parallel jobs. I’d like to use as many threads as I can efficiently (that is to say all of the remaining resources on the cluster). How can I determine some measure of what I can use, either the number of threads in use by all the other users, the peak computational load they’re generating, or some other quickly available measure?

Currently, my solution is to run a section of my code with 1 thread then 2 threads then …. then 32 threads and see where I hit a wall in real execution time. I back away from the wall by a couple of threads and then run a large job. This takes a few minutes and I’d like a faster way to find the appropriate number of threads to launch.

Thanks,

–Andrew

EDITS:

sehe’s answer definitely answered my original question about how to get the thread numbers. Turns out this is not as useful to have as I thought it would be. The comment from Phil put me onto the productive path. What I’m doing now is:

top -bn1 | grep load

to get the info. This is of advantage to me since my app is Matlab based and I can issue a UNIX call from the script to get this info every once in a while and adapt the number of threads I’m using to the available resources.

Thanks for putting me on the right track everyone.

–Andrew

  • 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-23T08:07:07+00:00Added an answer on May 23, 2026 at 8:07 am

    If you have enough permission, pin the thread to a core (thread affinity); otherwise

    perl -e 'map { ($u,$n)=split; $N{$u}+=$n } split /\n/, 
                  `ps --no-header -eo uid,nlwp=`; 
             print "$_\t$N{$_}\n" for keys %N' | sort -rn
    

    to show all threads owned per user (assuming linux); the following to limit to running threads:

    perl -e 'map { ($u,$n,$s)=split; $N{$u}+=$n } split /\n/, 
                  `ps --no-header -eo uid,nlwp,stat= | grep R`; 
             print "$_\t$N{$_}\n" for keys %N' | sort -rn
    

    You could run this (as a script) using watch(1):

    watch monitor.pl
    

    and have a graphical display of threads running.

    Tidied perl:

    #!/usr/bin/perl
    use strict;
    use warnings;
    
    open(my $PS, 'ps --no-header -eo uid,nlwp,stat=|') or die "oops, ps doesn't like that";
    
    my %users;
    map { my ($u,$n,$s)=split; $users{$u}+=$n } (<$PS>); 
    
    close ($PS);
    
    print "$_\t$users{$_}\n" 
        for sort { -($users{$a} <=> $users{$b}) } 
            keys %users;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some files on our website that users of our software can download.
I need to write code to do some realtime processing that is fairly computationally
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to
I just added some computationally expensive code to an Android game I am developing.
I'm thinking of using pure/const functions more heavily in my C++ code. ( pure/const
I have some code i'm revewing, which is used to convert some text into

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.