Ask Your Question

@Parallel - how to use all CPUs

asked 2018-05-26 01:39:46 +0200

Softy gravatar image

I am currently working on a parallelised implementation of Pollard-Rho.

For the parallelization of the program I want to use @parallel. But how can I allow Sage to use all the CPUs I have? When I put what they propose in '''' :

Using all the cores available on the computer to parallelize tensor computations:

sage: Parallelism().set('tensor')
sage: Parallelism() # random (depends on the computer)

I get back:

Number of processes for parallelization:
- tensor computations: 1

But my computer has more. (Windows tells me: Processor: Intel(R) Core(TM)i5CPU M560 @2.67GHz 2.67 GHz). How do I activate these?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-26 16:01:39 +0200

eric_g gravatar image

This is due to a change that occured in Sage 8.1: all parallelism in Sage is now governed by the environment variable SAGE_NUM_THREADS. In particular, the function ncpus(), which is called by Parallelism().set(), does no longer report the actual number of available CPU's on the computer, but simply reflects SAGE_NUM_THREADS (this new behavior was implemented in #23713 and critized in #24937).

There are two possible workarounds: you may set the environment variable SAGE_NUM_THREADS prior to the Sage session, by


or, in the Sage session, you pass the number of CPU's to Parallelism(), via the keyword argument nproc:

sage: Parallelism().set('tensor', nproc=4)
sage: Parallelism()
Number of processes for parallelization:
 - tensor computations: 4
edit flag offensive delete link more


Or set MAKEFLAGS to -j4, for example. This should cause make to use 4 threads, and Sage will also detect it and then use that as its default number of threads for parallel computation.

John Palmieri gravatar imageJohn Palmieri ( 2018-05-27 17:36:50 +0200 )edit

Thank you very much! Where do I type the 'export' comment in?

Softy gravatar imageSofty ( 2018-06-08 18:38:46 +0200 )edit

At the shell command line, before starting Sage.

John Palmieri gravatar imageJohn Palmieri ( 2018-06-09 17:34:03 +0200 )edit

Or you can achieve the same effect within Sage by evaluating os.environ['SAGE_NUM_THREADS'] = '4'.

John Palmieri gravatar imageJohn Palmieri ( 2018-06-10 00:13:40 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-05-26 01:39:46 +0200

Seen: 1,346 times

Last updated: May 26 '18