ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 09 Jun 2018 17:13:40 -0500@Parallel - how to use all CPUshttp://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/ 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')<br/>
>sage: Parallelism() # random (depends on the computer)
I get back:
> Number of processes for parallelization:<br/>
> - 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? Fri, 25 May 2018 18:39:46 -0500http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/Answer by eric_g for <p>I am currently working on a parallelised implementation of Pollard-Rho.</p>
<p>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'' :</p>
<blockquote>
<p>Using all the cores available on the computer to parallelize tensor computations:</p>
<p>sage: Parallelism().set('tensor')<br>
sage: Parallelism() # random (depends on the computer)</p>
</blockquote>
<p>I get back:</p>
<blockquote>
<p>Number of processes for parallelization:<br>
- tensor computations: 1</p>
</blockquote>
<p>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? </p>
http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?answer=42442#post-id-42442This 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](https://trac.sagemath.org/ticket/23713) and critized in [#24937](https://trac.sagemath.org/ticket/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
Sat, 26 May 2018 09:01:39 -0500http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?answer=42442#post-id-42442Comment by John Palmieri for <p>This is due to a change that occured in Sage 8.1: all parallelism in Sage is now governed by the environment variable <code>SAGE_NUM_THREADS</code>. In particular, the function <code>ncpus()</code>, which is called by <code>Parallelism().set()</code>, does no longer report the actual number of available CPU's on the computer, but simply reflects <code>SAGE_NUM_THREADS</code> (this new behavior was implemented in <a href="https://trac.sagemath.org/ticket/23713">#23713</a> and critized in <a href="https://trac.sagemath.org/ticket/24937">#24937</a>).</p>
<p>There are two possible workarounds: you may set the environment variable <code>SAGE_NUM_THREADS</code> prior to the Sage session, by</p>
<pre><code>export SAGE_NUM_THREADS=4
</code></pre>
<p>or, in the Sage session, you pass the number of CPU's to <code>Parallelism()</code>, via the keyword argument <code>nproc</code>:</p>
<pre><code>sage: Parallelism().set('tensor', nproc=4)
sage: Parallelism()
Number of processes for parallelization:
- tensor computations: 4
</code></pre>
http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42559#post-id-42559Or you can achieve the same effect within Sage by evaluating `os.environ['SAGE_NUM_THREADS'] = '4'`.Sat, 09 Jun 2018 17:13:40 -0500http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42559#post-id-42559Comment by John Palmieri for <p>This is due to a change that occured in Sage 8.1: all parallelism in Sage is now governed by the environment variable <code>SAGE_NUM_THREADS</code>. In particular, the function <code>ncpus()</code>, which is called by <code>Parallelism().set()</code>, does no longer report the actual number of available CPU's on the computer, but simply reflects <code>SAGE_NUM_THREADS</code> (this new behavior was implemented in <a href="https://trac.sagemath.org/ticket/23713">#23713</a> and critized in <a href="https://trac.sagemath.org/ticket/24937">#24937</a>).</p>
<p>There are two possible workarounds: you may set the environment variable <code>SAGE_NUM_THREADS</code> prior to the Sage session, by</p>
<pre><code>export SAGE_NUM_THREADS=4
</code></pre>
<p>or, in the Sage session, you pass the number of CPU's to <code>Parallelism()</code>, via the keyword argument <code>nproc</code>:</p>
<pre><code>sage: Parallelism().set('tensor', nproc=4)
sage: Parallelism()
Number of processes for parallelization:
- tensor computations: 4
</code></pre>
http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42558#post-id-42558At the shell command line, before starting Sage.Sat, 09 Jun 2018 10:34:03 -0500http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42558#post-id-42558Comment by Softy for <p>This is due to a change that occured in Sage 8.1: all parallelism in Sage is now governed by the environment variable <code>SAGE_NUM_THREADS</code>. In particular, the function <code>ncpus()</code>, which is called by <code>Parallelism().set()</code>, does no longer report the actual number of available CPU's on the computer, but simply reflects <code>SAGE_NUM_THREADS</code> (this new behavior was implemented in <a href="https://trac.sagemath.org/ticket/23713">#23713</a> and critized in <a href="https://trac.sagemath.org/ticket/24937">#24937</a>).</p>
<p>There are two possible workarounds: you may set the environment variable <code>SAGE_NUM_THREADS</code> prior to the Sage session, by</p>
<pre><code>export SAGE_NUM_THREADS=4
</code></pre>
<p>or, in the Sage session, you pass the number of CPU's to <code>Parallelism()</code>, via the keyword argument <code>nproc</code>:</p>
<pre><code>sage: Parallelism().set('tensor', nproc=4)
sage: Parallelism()
Number of processes for parallelization:
- tensor computations: 4
</code></pre>
http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42551#post-id-42551Thank you very much! Where do I type the 'export' comment in?Fri, 08 Jun 2018 11:38:46 -0500http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42551#post-id-42551Comment by John Palmieri for <p>This is due to a change that occured in Sage 8.1: all parallelism in Sage is now governed by the environment variable <code>SAGE_NUM_THREADS</code>. In particular, the function <code>ncpus()</code>, which is called by <code>Parallelism().set()</code>, does no longer report the actual number of available CPU's on the computer, but simply reflects <code>SAGE_NUM_THREADS</code> (this new behavior was implemented in <a href="https://trac.sagemath.org/ticket/23713">#23713</a> and critized in <a href="https://trac.sagemath.org/ticket/24937">#24937</a>).</p>
<p>There are two possible workarounds: you may set the environment variable <code>SAGE_NUM_THREADS</code> prior to the Sage session, by</p>
<pre><code>export SAGE_NUM_THREADS=4
</code></pre>
<p>or, in the Sage session, you pass the number of CPU's to <code>Parallelism()</code>, via the keyword argument <code>nproc</code>:</p>
<pre><code>sage: Parallelism().set('tensor', nproc=4)
sage: Parallelism()
Number of processes for parallelization:
- tensor computations: 4
</code></pre>
http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42450#post-id-42450Or 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.Sun, 27 May 2018 10:36:50 -0500http://ask.sagemath.org/question/42439/parallel-how-to-use-all-cpus/?comment=42450#post-id-42450