Skip to content

Instantly share code, notes, and snippets.

@sangheestyle
Last active July 25, 2024 02:40
Show Gist options
  • Save sangheestyle/ca8ef7796aefadad8773 to your computer and use it in GitHub Desktop.
Save sangheestyle/ca8ef7796aefadad8773 to your computer and use it in GitHub Desktop.
Build ATLAS in ubuntu

How to build ATLAS in uruntu

We can build ATLAS on a ubuntu machine.

Steps

First above all, you need to do disable 'Intel SpeedStep' in BIOS if you use Intel CPU. Then do the following:

# cpufreq-set -g performance -c  <CPU>

For example, I did the following because I used i5 which has quad cores.

# cpufreq-set -g performance -c 0
# cpufreq-set -g performance -c 1
# cpufreq-set -g performance -c 2
# cpufreq-set -g performance -c 3

After this part, you just need to follow the following excerpt from README.Debian says:

Building Optimized Atlas Packages on your ARCH

Building your own optimized packages of Atlas is straightforward. Just get the sources of the package and its build-dependencies:

# apt-get source atlas
# apt-get build-dep atlas
# apt-get install devscripts

and type the following from the atlas source subdir:

# fakeroot debian/rules custom

it should produce a package called:

../libatlas3-base_*.deb

which is optimized for the architecture Atlas has been built on. Then install the package using dpkg -i.

Remove openblas if you want.

$ sudo apt-get purge libopenblas-{base,dev}

Check

Choose blas and lapack.

$ sudo update-alternatives --config libblas.so.3
There are 2 choices for the alternative libblas.so.3 (providing /usr/lib/libblas.so.3).

  Selection    Path                                    Priority   Status
------------------------------------------------------------
  0            /usr/lib/atlas-base/atlas/libblas.so.3   35        auto mode
* 1            /usr/lib/atlas-base/atlas/libblas.so.3   35        manual mode
  2            /usr/lib/libblas/libblas.so.3            10        manual mode

Press enter to keep the current choice[*], or type selection number: 0

$ sudo update-alternatives --config liblapack.so.3
There are 2 choices for the alternative liblapack.so.3 (providing /usr/lib/liblapack.so.3).

  Selection    Path                                      Priority   Status
------------------------------------------------------------
  0            /usr/lib/lapack/liblapack.so.3             10        auto mode
* 1            /usr/lib/atlas-base/atlas/liblapack.so.3   5         manual mode
  2            /usr/lib/lapack/liblapack.so.3             10        manual mode

Press enter to keep the current choice[*], or type selection number: 1

You can display the BLAS / LAPACK implementation used by your NumPy / SciPy / scikit-learn install with the following commands:

from numpy.distutils.system_info import get_info
print(get_info('blas_opt'))
print(get_info('lapack_opt'))

Reference

CPU Throttling

You might need to read about CPU throttling excerpt from INSTALL.txt

********** Important Install Information: CPU THROTTLING ***********
Most OSes (including Linux) now turn on CPU throttling for power management
**even if you are using a desktop**.  CPU throttling makes pretty much all
timings completely random, and so any ATLAS install will be junk.  Therefore,
before installing ATLAS, turn off CPU throttling.  For most PCs, you can
switch it off in the BIOS (eg., on my Athlon-64 machine, I can say "No" to
"Cool and Quiet" under "Power Management").  Most OSes also provide a way
to do switch off CPU throttling, but that varies from OS to OS.  Under Fedora,
at any rate, the following command seemed to work:
     /usr/bin/cpufreq-selector -g performance
On my Core2Duo, cpufreq-selector only changes the parameters of the first CPU,
regardless if which cpu you specify.  I suspect this is a bug, because on
earlier systems, the remaining CPUs were controlled via a logical link to
/sys/devices/system/cpu/cpu0/.  In this case, the only way I found to force
the second processor to also run at its peak frequency was to issue the
following as root after setting CPU0 to performance:
   cp /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor \
      /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor

For non-broken systems, you instead issue the above command with -c <#> appended
to change the performance of each core in turn.  For example, to speedup both
processors of a dual system you would issue:
     /usr/bin/cpufreq-selector -g performance -c 0
     /usr/bin/cpufreq-selector -g performance -c 1
@fabriciorsf
Copy link

Error on fakeroot debian/rules custom:
/usr/bin/fakeroot: 175: debian/rules: not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment