Ask Your Question
0

@Parallel - how to use all CPUs

asked 2018-05-25 18:39:46 -0600

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 ''doc.sagemath.org/html/en/reference/parallel/sage/parallel/parallelism.html'' :

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
1

answered 2018-05-26 09:01:39 -0600

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

export SAGE_NUM_THREADS=4

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

Comments

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 10:36:50 -0600 )edit

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

Softy gravatar imageSofty ( 2018-06-08 11:38:46 -0600 )edit

At the shell command line, before starting Sage.

John Palmieri gravatar imageJohn Palmieri ( 2018-06-09 10:34:03 -0600 )edit
1

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

John Palmieri gravatar imageJohn Palmieri ( 2018-06-09 17:13:40 -0600 )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

Stats

Asked: 2018-05-25 18:39:46 -0600

Seen: 121 times

Last updated: May 26