[Radiance-general] ...how many processors?

Randolph M. Fritz RFritz at lbl.gov
Fri Oct 8 11:26:11 PDT 2010


The following possibly-useful fragments ask most Unix systems (I've 
tried it on BSD and Mac) how many processors there are.

(t)csh:
  set nproc = `sysctl -n hw.ncpu`

bash/ksh:
  nproc=`sysctl -n hw.ncpu`

Python:
> from subprocess import Popen
> def getnproc():
>     GETN = 'sysctl -n hw.ncpu'
>     nproc = 1
>     sysc = Popen(GETN.split(), stdout=PIPE)
>     (out,junk) = sysc.communicate()
>     if sysc.returncode == 0:
>         nproc = int(out)
>     return nproc

-- 
Randolph





More information about the Radiance-general mailing list