Find the answer to your Linux question:
Results 1 to 3 of 3
I have an application that tries to use as many threads as there are processors on the machine it is run on. It throttles back the number of active threads ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Location
    North East U.S.
    Posts
    27

    Portable way to find number of real CPUs

    I have an application that tries to use as many threads as there are processors on the machine it is run on. It throttles back the number of active threads when the CPU load exceeds the number of processors and increases threads when the load decreases over time. The problem I have is that on Intel processors that have hyper threading I get worse throughput than running a single thread. For example, when I run on a machine with 2 physical processors that each have HT enabled, my program sees 4 processors reported. Using 4 threads takes longer than a single thread to complete the circuit simulation task the program is performing. Using 2 threads it does beat a single thread on this machine. What I would like to be able to do is find out how many of the processors as reported by sysconf(_SC_NPROCESSORS_ONLN) are virtual processors via HT so I don't count them. I need a mechanism that is portable to Solaris and AIX if possible (I see a similar problem on AIX with HT enabled), so I'd prefer to use a system function rather than look through /proc/cpuinfo since that isn't portable. Thanks!

    Brion

  2. #2
    Linux Newbie
    Join Date
    Feb 2008
    Location
    Bangalore, India
    Posts
    112
    how does your program finds no. of processors available in machine ?
    bigunix.blogspot.com
    Registered Linux User: #476440

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Location
    North East U.S.
    Posts
    27
    Using this:

    numCPUs = sysconf(_SC_NPROCESSORS_ONLN);

    Brion

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...