Skip to content

Commit 846bb4d

Browse files
committed
Do not recommend to set MAKE=make -jX
Setting MAKE=make -jX can lead to an exponential growth of build processes (as noted during SD128.) It's better to rely on make's jobserver that is available on macOS and all relevant Linux distributions. We also recommend a sane default for MAKEFLAGS that people can just copy & paste. Unfortunately, a lot of non-developers of SageMath still have to build from source and they appreciate not having to think about these things and just being able to copy a good default value.
1 parent 535f4b8 commit 846bb4d

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

Diff for: README.md

+12-20
Original file line numberDiff line numberDiff line change
@@ -334,26 +334,18 @@ in the Installation Guide.
334334
11. Optional, but highly recommended: Set some environment variables to
335335
customize the build.
336336

337-
For example, the `MAKE` environment variable controls whether to
338-
run several jobs in parallel. On a machine with 4 processors, say,
339-
typing `export MAKE="make -j4"` will configure the build script to
340-
perform a parallel compilation of Sage using 4 jobs. On some
341-
powerful machines, you might even consider `-j16`, as building with
342-
more jobs than CPU cores can speed things up further.
343-
344-
Alternatively, the `MAKEFLAGS` environment variable can be used.
345-
In this case, only provide the flag itself, for example
346-
`export MAKEFLAGS="-j4"`.
347-
348-
Note that the compilation may nonetheless uses a different number of
349-
threads, because sometimes `ninja` is used.
350-
Unfortunately, [there is no way to control number of jobs `ninja` uses
351-
from environment variables](https://github.com/ninja-build/ninja/issues/1482).
352-
See also https://github.com/sagemath/sage/issues/38950.
353-
354-
If the [Meson build system](https://doc-release--sagemath.netlify.app/html/en/installation/meson)
355-
is used, the number of jobs running in parallel passed to `meson compile` will be respected,
356-
because everything are managed by `ninja`.
337+
The `MAKEFLAGS` variable controls whether to run several jobs in parallel.
338+
To saturate all the execution threads of your CPU, we recommend to run
339+
`export MAKEFLAGS="-j$(nproc) -l$(nproc).5"` if you are on Linux, and
340+
`export MAKEFLAGS="-j$(sysctl -n hw.ncpu) -l$(sysctl -n hw.ncpu).5"` if you
341+
are on macOS.
342+
343+
Note that the compilation may nonetheless use a different number of
344+
processes, e.g., for parts that are built with `ninja` which automatically
345+
decides on the amount of parallelity to use. In practice, you might
346+
therefore see twice as many processes during the build process than your
347+
CPU has execution threads. Unless your system is low on RAM, this should
348+
not affect the time the compilation takes substantially.
357349

358350
To reduce the terminal output during the build, type `export V=0`.
359351
(`V` stands for "verbosity".)

Diff for: src/doc/en/installation/source.rst

+20-13
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ Environment variables
669669
Sage uses several environment variables to control its build process.
670670
Most users won't need to set any of these: the build process just works on many
671671
platforms.
672-
(Note though that setting :envvar:`MAKE`, as described below, can significantly
673-
speed up the process.)
672+
(Note though that setting :envvar:`MAKEFLAGS`, as described below, can
673+
significantly speed up the process.)
674674
Building Sage involves building many packages, each of which has its own
675675
compilation instructions.
676676

@@ -680,19 +680,26 @@ Standard environment controlling the build process
680680

681681
Here are some of the more commonly used variables affecting the build process:
682682

683-
.. envvar:: MAKE
683+
.. envvar:: MAKEFLAGS
684684

685-
One useful setting for this variable when building Sage is
686-
``MAKE='make -jNUM'`` to tell the ``make`` program to run ``NUM`` jobs in
687-
parallel when building.
688-
Note that some Sage packages may not support this variable.
685+
This variable can be set to tell the ``make`` program to build things in
686+
parallel. Set it to ``-jNUM`` to run ``NUM`` jobs in parallel when building.
687+
Add ``-lNUM`` to tell make not to spawn more processes when the load exceeds
688+
``NUM``.
689+
690+
A good value for this variable is ``MAKEFLAGS="-j$(nproc) -l$(nproc).5"`` on
691+
Linux and ``MAKEFLAGS="-j$(sysctl -n hw.ncpu) -l$(sysctl -n hw.ncpu).5"`` on
692+
macOS. This instructs make to use all the execution threads of your CPU while
693+
bounding the load if there are other processes generating load. If your
694+
system does not have a lot of RAM, you might want to choose lower limits, if
695+
you have lots of RAM, it can sometimes be benificial to set these limits
696+
slightly higher.
697+
698+
Note that some parts of the SageMath build system do not respect this
699+
variable, e.g., when ninja gets invoked, it figures out the number of
700+
processes to use on its own so the number of processes and the system load
701+
you see might exceed the number configured here.
689702

690-
Some people advise using more jobs than there are CPU cores, at least if the
691-
system is not heavily loaded and has plenty of RAM; for example, a good
692-
setting for ``NUM`` might be between 1 and 1.5 times the number of cores.
693-
In addition, the ``-l`` option sets a load limit: ``MAKE='make -j4 -l5.5``,
694-
for example, tells ``make`` to try to use four jobs, but to not start more
695-
than one job if the system load average is above 5.5.
696703
See the manual page for GNU ``make``: `Command-line options
697704
<https://www.gnu.org/software/make/manual/make.html#Options-Summary>`_
698705
and `Parallel building

0 commit comments

Comments
 (0)