[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Read the number of cpus on Linux
From: |
Francesco Potortì |
Subject: |
Re: Read the number of cpus on Linux |
Date: |
Tue, 20 Jul 2010 21:23:18 +0200 |
>> When using parcellfun, I want to know the number of processors
>> beforehand.
>>
>> This is the simplest way I have come up with on Linux:
>> pid=fopen("/proc/cpuinfo");
>> numprocs = length(strfind(char(fread(pid)'),"processor"));
>> fclose(pid);
>
>If you have GNU coreutils 8.1 or later, you can do
> [err,numprocs] = system("nproc")
Isn't this less efficient, systemwise? It forks and then execs a
process, twice, even if it is probably not worth worrying.
Wouldn't it be nice to have this inside Octave as a builtin function?
Or as an additional return value from computer()?
Or as an additional field in the struct returned by uname()?
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/