per question , answer -- python multiprocessing.cpu_count() returns '1' on 4-core nvidia jetson tk1 -- output of python's multiprocessing.cpu_count() function on systems reflects number of cpus actively in use, opposed number of cpus usable calling python program.
a common python idiom use return-value of cpu_count() initialize number of processes in pool. however, on systems use such "dynamic cpu activation" strategy, idiom breaks rather badly (at least on relatively quiescent system).
is there straightforward (and portable) way @ number of usable processors (as opposed number currently in use) python?
notes:
this question not answered accepted answer how find out number of cpus using python, since noted in question linked @ top of this question, printing contents of
/proc/self/statusshows 4 cores being available program.to mind, "portable" excludes approach involves parsing contents of
/proc/self/status, format may vary release release of linux, , doesn`t exist on os x. (the same goes other pseudo-file, well.)
i don't think portable answers, give correct one.
the correct* answer linux len(os.sched_getaffinity(pid)), pid may 0 current process. function exposed in python 3.3 , later; if need in earlier, you'll have fancy cffi coding.
edit: might try see if can use function int omp_get_num_procs(); if exists, meaningful answer found on this question haven't tried python.
Comments
Post a Comment