Which core am I running on?

P

psaffrey

Is there some way I can get at this information at run-time? I'd like
to use it to tag diagnostic output dumped during runs using Parallel
Python.

Peter
 
G

Gerhard Häring

Is there some way I can get at this information at run-time? I'd like
to use it to tag diagnostic output dumped during runs using Parallel
Python.

There should be a way, but not with the Python standard library. It's
also platform-specific. What are you using? Linux, MacOS X, FreeBSD,
Solaris, or maybe Windows?

-- Gerhard
 
P

psaffrey

Looks like I have answered a similar question once, btw. ;-)

Ah, yes - thanks. I did Google for it, but obviously didn't have the
right search term.

Cheers,

Peter
 
P

psaffrey


Hmm. In fact, this doesn't seem to work for pp. When I run the code
below, it says everything is running on the one core.

import pp
import random
import time
from string import lowercase

ncpus = 3

def timedCharDump(waittime, char):
time.sleep(waittime)
mycore = open("/proc/%i/stat" % os.getpid()).read().split()[39]
print "I'm doing stuff!", mycore, char
return char

job_server = pp.Server(ncpus, ppservers=())

jobdetails = [ (random.random(), letter) for letter in lowercase ]

jobs = [ job_server.submit(timedCharDump,(jinput1, jinput2), (),
("os", "time",)) for jinput1, jinput2 in jobdetails ]

for job in jobs:
print job()


Peter
 
G

Gerhard Häring


Hmm. In fact, this doesn't seem to work for pp. When I run the code
below, it says everything is running on the one core.

import pp
import random
import time
from string import lowercase

ncpus = 3

def timedCharDump(waittime, char):
time.sleep(waittime)
mycore = open("/proc/%i/stat" % os.getpid()).read().split()[39]
print "I'm doing stuff!", mycore, char
return char

job_server = pp.Server(ncpus, ppservers=())

jobdetails = [ (random.random(), letter) for letter in lowercase ]

jobs = [ job_server.submit(timedCharDump,(jinput1, jinput2), (),
("os", "time",)) for jinput1, jinput2 in jobdetails ]

for job in jobs:
print job()

Quick look again found this:

http://brokestream.com/procstat.html

I guess I counted wrong and it's actually column 38, not 39.

-- Gerhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,279
Latest member
RedaBruno6

Latest Threads

Top