CPU Detection - Parallel Computing

Skip to content
Back to top
View this page
Edit this page

# CPU Detection

sage.parallel.ncpus.ncpus()

  Return the number of available CPUs in the system.

  ALGORITHM: `os.sched_getaffinity()` or `os.cpu_count()`

  EXAMPLES:

  Sage

      sage: sage.parallel.ncpus.ncpus()  # random output -- depends on machine
      2

  Python

      >>> from sage.all import *
      >>> sage.parallel.ncpus.ncpus()  # random output -- depends on machine
      2