C语言 BLAS、LAPACK、ATLAS的关系是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17858104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the relation between BLAS, LAPACK and ATLAS
提问by makhlaghi
I don't understand how BLAS, LAPACK and ATLAS are related and how I should use them together! I have been looking through all of their manuals and I have a general idea of BLAS and LAPACK and how to use them with the very few examples I find, but I can't find any actual examples using ATLAS to see how it is related with these two.
我不明白 BLAS、LAPACK 和 ATLAS 之间的关系以及我应该如何将它们一起使用!我一直在浏览他们所有的手册,我对 BLAS 和 LAPACK 以及如何在我找到的极少数示例中使用它们有一个大致的了解,但是我找不到任何使用 ATLAS 的实际示例来了解它与这两个。
I am trying to do some low level work on matrixes and my primary language is C. First I wanted to use GSL, but it says that if you want the best performance you should use BLAS and ATLAS. Is there any good webpage giving some nice examples of how to use these (in C) all together? In other words I am looking for a tutorial on using these three (or any subset of them!). In short I am confused!
我正在尝试在矩阵上做一些低级工作,我的主要语言是 C。首先我想使用 GSL,但它说如果你想要最好的性能,你应该使用 BLAS 和 ATLAS。有没有什么好的网页给出了一些很好的例子来说明如何一起使用这些(在 C 中)?换句话说,我正在寻找有关使用这三个(或它们的任何子集!)的教程。总之我很困惑!
回答by Stephen Canon
BLAS is a collection of low-level matrix and vector arithmetic operations (“multiply a vector by a scalar”, “multiply two matrices and add to a third matrix”, etc ...).
BLAS 是低级矩阵和向量算术运算的集合(“将向量乘以标量”、“将两个矩阵相乘并添加到第三个矩阵”等......)。
LAPACK is a collection of higher-level linear algebra operations. Things like matrix factorizations (LU, LLt, QR, SVD, Schur, etc) that are used to do things like “find the eigenvalues of a matrix”, or “find the singular values of a matrix”, or “solve a linear system”. LAPACK is built on top of the BLAS; many users of LAPACK onlyuse the LAPACK interfaces and never need to be aware of the BLAS at all. LAPACK is generally compiled separately from the BLAS, and can use whatever highly-optimized BLAS implementation you have available.
LAPACK 是高级线性代数运算的集合。诸如矩阵分解(LU、LLt、QR、SVD、Schur 等)之类的东西,用于执行诸如“查找矩阵的特征值”、“查找矩阵的奇异值”或“求解线性系统”之类的事情”。LAPACK 建立在 BLAS 之上;许多 LAPACK 用户只使用 LAPACK 接口,根本不需要知道 BLAS。LAPACK 通常与 BLAS 分开编译,并且可以使用任何可用的高度优化的 BLAS 实现。
ATLAS is a portable reasonably good implementation of the BLAS interfaces, that also implements a few of the most commonly used LAPACK operations.
ATLAS 是 BLAS 接口的一个可移植的相当好的实现,它还实现了一些最常用的 LAPACK 操作。
What “you should use” depends somewhat on details of what you're trying to do and what platform you're using. You won't go too far wrong with “use ATLAS + LAPACK”, however.
“您应该使用”什么在某种程度上取决于您正在尝试做什么以及您正在使用什么平台的详细信息。但是,“使用 ATLAS + LAPACK”不会出错。
回答by Foad
While ago, when I started doing some linear algebra in C, it came to me as a surprise to see there are so few tutorials for BLAS, LAPACKand other fundamental APIs, despite the fact that they are somehow the cornerstones of many other libraries. For that reason I started collecting all the examples/tutorials I could find all over the internet for BLAS, CBLAS, LAPACK, CLAPACK, LAPACKE, ATLAS, OpenBLAS... in this Github repo.
前一阵子,当我开始在做一些线性代数C,它来到我作为一个惊喜地看到有这么几个教程BLAS,LAPACK和其他基本API,S尽管他们在某种程度上许多其他库的基石。出于这个原因,我开始收集所有的例子/教程我能找到所有在互联网上的BLAS,CBLAS,LAPACK,CLAPACK,LAPACKE,ATLAS,OpenBLAS...在这个Github上回购。
Well, I should warn you that as a mechanical engineer I have little experience in managing such a git repository or GitHub. It will first seem as a complete mess to you guys. However if you manage to get over the messy structure you will find all kind of examples and instructions which might be a help. I have tried most of them, to be sure they compile. And the ones which do not compile I have mentioned. I have modified many of them to be compilable with GNU compilers(gcc, g++and gfortran). I have made MakeFiles which you can read to learn how you can call individual Fortran/FORTRANroutines in a Cor C++program. I have also put some installations instructions for mac and linux (sorry windows guys!). I have also made some bash.shfiles for automatic compilation of some of these libraries.
好吧,我应该警告你,作为一名机械工程师,我在管理这样的 git 存储库或 GitHub 方面几乎没有经验。对你们来说,这首先看起来是一团糟。但是,如果您设法克服凌乱的结构,您会发现各种可能有帮助的示例和说明。我已经尝试了其中的大部分,以确保它们能够编译。以及我提到的那些不编译的。我已经修改了其中的许多以使用GNU compilers( gcc,g++和gfortran)进行编译。我制作了MakeFiles ,您可以阅读以了解如何Fortran/FORTRAN在C或C++程序中调用单个例程。我还为 mac 和 linux 提供了一些安装说明(对不起,windows 家伙!)。我也做了一些bash.sh用于自动编译其中一些库的文件。
But going to your other question: BLASand LAPACKare rather APIs not specific SDKs. They are just a list of specifications or language extensions rather than an implementations or libraries. With that said, there are original implementations by Netlibin FORTRAN 77, which most people refer to (confusingly!) when talking about BLASand LAPACK. So if you see a lot of strange things when using these APIs is because you were actually calling FORTRANroutines in Crather than Clibraries and functions. ATLASand OpenBLASare some of the best implementations of BLASand LACPACKas far as I know. They conform to the original API, even though, to my knowledge they are implemented on C/C++from scratch (not sure!). There are GPGPU implementations of the APIs using OpenCL: CLBlast, clBLAS, clMAGMA, ArrayFireand ViennaCLto mention some. There are also vendor specific implementations optimized for specific hardware or platform, which I strongly discourage anybody to use them.
但要你的另一个问题:BLAS和LAPACK相当API不是特定SDK秒。它们只是规范或语言扩展的列表,而不是实现或库。话虽如此,Netlib在 中有原始实现FORTRAN 77,大多数人在谈论BLAS和时都会提到(令人困惑!)LAPACK。因此,如果您在使用这些APIs时看到很多奇怪的事情,那是因为您实际上是在调用FORTRAN例程C而不是C库和函数。ATLAS并OpenBLAS有一些最好的实现BLAS,并LACPACK就我知道的。它们符合原版API,尽管据我所知,它们是在C/C++从头开始(不确定!)。有API使用 s 的GPGPU 实现OpenCL:CLBlast、clBLAS、clMAGMA、ArrayFire和ViennaCL 等等。还有针对特定硬件或平台优化的供应商特定实现,我强烈不鼓励任何人使用它们。
My recommendation to anyone who wants to learn using BLASand LAPACKin Cis to learn FORTRAN-Cmixed programming first. The first chapter of the mentioned repo is dedicated to this matter and there I have collected many different examples.
我对任何人谁想要使用学习的建议BLAS,并LAPACK在C是学习FORTRAN-C第一混合编程。提到的 repo 的第一章专门讨论这个问题,我在那里收集了许多不同的例子。
P.S.I have been working on the dev branch of the repositorytime to time. It seems slightly less messy!
PS我不时在存储库的 dev 分支上工作。看起来不那么凌乱了!
回答by Robert van de Geijn
ATLAS is by now quite outdated. It was developed at a time when it was thought that optimizing the BLAS for various platforms was beyond the ability of humans, and as a result autogeneration and autotuning was the way to go.
ATLAS 现在已经相当过时了。它是在认为为各种平台优化 BLAS 超出人类能力的时候开发的,因此自动生成和自动调整是要走的路。
In the early 2000s, along came Kazushige Goto, who showed how highly efficient implementations can be coded by hand. You may enjoy an interesting article in the New York Times: https://www.nytimes.com/2005/11/28/technology/writing-the-fastest-code-by-hand-for-fun-a-human-computer-keeps.html.
在 2000 年代初期,Kazushige Goto 出现了,他展示了如何高效地手动编码实现。您可能会喜欢纽约时报的一篇有趣文章:https: //www.nytimes.com/2005/11/28/technology/writing-the-fastest-code-by-hand-for-fun-a-human-电脑保持.html。
Kazushige's on the one hand had better insights into the theory behind high-performance implementations of matrix-matrix multiplication, and on the other hand engineered these better. His approach, which on current CPUs is usually the highest performing, is not in the search space that ATLAS autotunes. Hence, ATLAS is inherently inferior. Kazushige's implementation of the BLAS became known as the GotoBLAS. It was forked as the OpenBLAS when he joined industry.
一方面,Kazushige 对矩阵乘法的高性能实现背后的理论有更深入的了解,另一方面,对这些进行了更好的设计。他的方法在当前的 CPU 上通常是性能最高的,而不是在 ATLAS 自动调整的搜索空间中。因此,ATLAS 本质上是劣等的。Kazushige 对 BLAS 的实施被称为 GotoBLAS。当他加入行业时,它被分叉为 OpenBLAS。
The ideas behind the GotoBLAS were refactored into a new implementation, the BLAS-like Library Instantiation Software (BLIS) framework (https://github.com/flame/blis), which implements the same algorithms, but structures the code so that less needs to be custom implemented for a new architecture. BLIS is coded in C.
GotoBLAS 背后的想法被重构为一个新的实现,类似于 BLAS 的库实例化软件 (BLIS) 框架 ( https://github.com/flame/blis),它实现了相同的算法,但结构化了代码,以便更少需要为新架构定制实现。BLIS 是用 C 编码的。
What this discussion shows is that there are many implementation of the BLAS. The BLAS themselves are a de facto standard for the interface. ATLAS was once the state of the art. It is no longer.
这个讨论表明有很多 BLAS 实现。BLAS 本身是接口的事实上的标准。ATLAS 曾经是最先进的。它不再是。
回答by cdcdcd
As far as I'm aware, and after working through the ATLAS repository, it seems that it includes a re-implementation of BLAS in C. There's bit more to it than that but I hope it answers the question.
据我所知,在处理完 ATLAS 存储库之后,它似乎包括在 C 中重新实现 BLAS。除此之外还有更多内容,但我希望它回答了这个问题。

