Thread: Run code on specific CPU?

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    15

    Run code on specific CPU?

    Hi,

    is there a way to select the CPU on which a program will run from within this program?
    I'm looking for a way to run some test with the CPUID instruction on every logical CPU in the system, but the CPU that runs my program will be "randomly" selected by the scheduler...

    Peter

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you're looking for some way to execute a program as if it were running on a different processor, then the only way I can think of to do that is to use emulation of some sort. Emulation is slow and a often pain to set up. Why do you need to do this?

    /proc/cpuinfo seems to be the easiest way . . . . http://cboard.cprogramming.com/showthread.php?t=95788
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Yes, Intel processor supports selecting one specific core of available in the system. I do not remeber exactly how it is done - You probably need to look on the intel's site...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  2. Code compiles but doesn't run
    By dbyte in forum C Programming
    Replies: 5
    Last Post: 07-22-2003, 08:25 PM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM