# Since MKL is not optimized for AMD hardware, should I use a math library specific to AMD, or would an open-source one be just as good?

The codes for quantum mechanical calculations make heavy use of linear algebra, and it seems most of them delegate this task to time-tested and highly optimized libraries, instead of trying to deploy their own. There is a plethora of options. For example, when we install Gamess-US in Ubuntu GNU/Linux, several options are listed, both proprietary and free / open source software:

In the past I used ATLAS, and then MKL, as we are nudged towards it by the (very fast) qualifier given in the install screen. But then I was doing some research on it, and found this information on its wikipedia page:

Intel MKL and other programs generated by the Intel C++ Compiler improve performance with a technique called function multi-versioning: a function is compiled or written for many of the x86 instruction set extensions, and at run-time a "master function" uses the CPUID instruction to select a version most appropriate for the current CPU. However, as long as the master function detects a non-Intel CPU, it almost always chooses the most basic (and slowest) function to use, regardless of what instruction sets the CPU claims to support. This has netted the system a nickname of "cripple AMD" routine since 2009.

This got me a bit worried, as I'm trying to do a Gamess-US install in a machine with a Ryzen processor, and so I'm afraid I will get a crippled install if I use intel MKL. Given the number of remaining choices, without a clear idea of relative performance between them, I got some analysis paralysis. The obvious alternative would be one of AMD, but in absence of a substantial speed advantage, I could as well use a open source one, as I try to favor free software whenever I can.

If someone more experienced could give some advice on this problem, I would be grateful. How does the several linear algebra libraries compare to each other, on the workloads typical of materials modeling? Is there a big difference from one to other, or they are all optimized to such degree that doesn't matter much which one is used. Is there one with good overall performance over a variety of hardware, not biased against alternative hardware like the MKL seems to be?

• Seems more appropriate for ComputationalScience.SE cause your question focouses on computational aspects instead of primarily materials modeling. – Alone Programmer May 27 at 20:03
• Neither the programming language under the hood is primarily materials modeling, yet that was one of the most upvoted questions here ever. See What is a good programming language to learn for materials modeling?. Also that is one of the first things people need to worry about modeling, because if they can't even install the software, what else can they do? Pen and paper modeling? – ksousa May 27 at 21:24
• I think the question is relevant (I even upvoted it), but on a second thought, off-topic here. It's a math library question that affects computing broadly (differently from the programming language question, which asked specifically "for MM"), not materials science or gamess in particular. – stafusa May 28 at 0:14
• FWIW, there's a workaround posted in Reddit for "cripple AMD"; and, according to this article it works very well and might lead to a performance (slightly?) superior to that of open source libraries. – stafusa May 28 at 0:19
• OpenBlas is one of the best alternatives, take a look at some comparisons in different contexts here, here (related: here), here and here (relevant to AMD hardware). – Felipe S. S. Schneider May 28 at 0:35

OpenBLAS is a free, open-source BLAS library that has fast support for even recent processors. (It is based on the earlier, famous GotoBLAS library which became obsolete years ago.) OpenBLAS is also multi-platform: in addition to x86 and x86_64 it also supports other architectures like ARM and PowerPC. OpenBLAS also has runtime CPU detection; if you compile it in, the resulting library supports all processors and picks the best kernel at runtime.

IIRC OpenBLAS is as fast (sometimes has been even faster!) as MKL on some Intel processors; I don't think I've seen benchmarks on AMD hardware. But, the nice thing about OpenBLAS is that it's free, so it typically comes built-in your linux distribution. E.g. OpenBLAS has been available on Fedora and Red Hat Enterprise for a few years now (courtesy of yours truly), and to use it you just need to install the package

# yum install openblas-devel

and then link to the flavor you want: on Fedora/Red Hat the available variants are

• libopenblas sequential library with 4-byte integers
• libopenblaso OpenMP parallel library with 4-byte integers
• libopenblasp pthreads parallel library with 4-byte integers
• libopenblas64 sequential library with 8-byte integers
• libopenblaso64 OpenMP parallel library with 8-byte integers
• libopenblasp64 pthreads parallel library with 8-byte integers
• Wow! You made OpenBLAS available on Fedora and Red Hat? – Nike Dattani May 28 at 14:23
• @NikeDattani yes, I've been a Fedora packager for over a decade... I've also packaged e.g. PyQuante, Psi4, PySCF, OpenMolcas, libint, libxc, etc. All of these come as system packages :) – Susi Lehtola May 28 at 15:43
• That is great @SusiLehtola. I think a considerable entry barrier for more people start using computational methods is the sheer amount of effort you need to install some of the tools. I think many people in the field learn unix just as they start their modeling activities, and it's a lot of things you need to learn at the same time, it can be a daunting task. It's awesome when we can just get it running out of the box with only a single-line command to the package manager. – ksousa May 28 at 16:28
• @NikeDattani that sounds like a problem that has a solution ;) – Susi Lehtola May 28 at 18:39
• @SusiLehtola It does! Since there's 20 million Ubuntu users and 1.5 million Fedora users, the solution is to package these for Ubuntu!!! I'm joking of course: the clusters I use in Canada all use CentOS and the ones in Germany all use SUSE, so the solution is to package them for these :) CentOS is similar enough to RedHat so you probably already did! – Nike Dattani May 28 at 20:11