- 1 Licensing
- 2 Eigen and other libraries
- 3 Compilation
- 4 Vectorization
How is Eigen licensed?
Eigen is dual-licensed: it can be redistributed and/or modified, at your choice,
Note that this is an OR, not an AND. You do not need to conform to both licenses, you just pick the one that you prefer. Typically, GPL projects will regard Eigen as GPL-licensed while non-GPL projects will regard Eigen as LGPL-licensed.
May my project use Eigen?
Yes. The LGPL license is very liberal, it lets anybody use Eigen. Even closed-source software may use Eigen without having to release any of its own source code.
Why not just license Eigen under the LGPL, since anyway it is more liberal than the GPL?
A library licensed under the LGPL3 cannot be used by a program licensed under the GPL2 (see here for details). Therefore, we offer the GPL2 as an alternative license choice for Eigen, in order to allow GPL2 programs to use it.
Why require the LGPL version to be at least 3?
Because up to version 2.1, the LGPL does not handle the case of C++ template libraries, where all the code is in headers. This problem was solved in version 3 of the LGPL.
Are you sure that the old LGPL's issues with template libraries are solved in version 3?
Eigen and other libraries
Why another matrix library? What is the need for Eigen?
First of all, see the Overview. No other library provides all of the features and benefits listed there.
The Eigen project started when some hackers from the large KDE meta-project realized the need for a single unified matrix library.
Some other libraries do satisfy very well certain specialized needs, but none is as versatile as Eigen, has such a nice API, etc.
The fact that so many projects are quickly adopting Eigen 2, shows that it fills a gap.
The state of existing matrix libraries before Eigen is that:
- some are Free Software
- some are fast
- some have a decent API
- some handle fixed-size matrices, some handle dynamic-size dense matrices, some handle sparse matrices
- some provide linear algebra algorithms (LU, QR, ...)
- some provide a geometry framework (quaternions, rotations...)
However Eigen is the first library to satisfy all these criteria.
How does Eigen compare to BLAS/LAPACK?
Eigen covers many things that BLAS/LAPACK don't:
- Eigen handles fixed-size matrices and vectors, which are very widely used.
- Eigen has built-in (experimental) support for sparse matrices and vectors.
- Eigen provides a lot of convenience features (see Geometry module, Array module, etc), which are also very widely used.
- Eigen is much faster than every Free BLAS, such as ATLAS or Boost::uBlas.
- Eigen is overall of comparable speed (faster or slower depending on what you do) to the best BLAS, namely Intel MKL and GOTO, both of which are non-Free.
Eigen has an incomparably better API than BLAS and LAPACK.
- See the API Showcase.
- For operations involving complex expressions, Eigen is inherently faster than any BLAS implementation because it can handle and optimize a whole operation globally -- while BLAS forces the programmer to split complex operations into small steps that match the BLAS fixed-function API, which incurs inefficiency due to introduction of temporaries.
Miscellaneous advantages (not specifically against BLAS/LAPACK):
- Eigen is only a compile-time dependency for your project. No need to redistribute, or ask your user to install, any library.
- Eigen is small, so it is feasible to include a copy of it in your own source tree, if you want to.
- Eigen, compared to certain other C++ template libraries, is relatively easy on the compiler. Compilation times stay reasonable -- we are very careful about that.
- Eigen is multi-platform, and is actually being used on a number of different operating systems, hardware platforms, and compilers.
I need help with compiler errors!
- Did you forget to include a module? Certain Eigen features are not in Core but in other modules. Normally this is always explained in the documentation but we may have forgotten some places. For example, in order to use random matrices, you need to do:
- Did you check if you triggered a static assertion ? These are compile-time checks guarding from programming mistakes. Eigen has many of those. So even if you got a kilometer of compiler output, you might still find useful information from static assertion messages. Search for "static_assert". The static assertion messages themselves are UPPERCASE_SO_THEY_REALLY_STAND_OUT.
Which SIMD instruction sets are supported by Eigen?
Eigen supports SSE and AltiVec.
With SSE, at least SSE2 is required. SSE3 and SSSE3 are optional. SSE4 and newer are ignored.
Of course vectorization is not mandatory -- you can use Eigen on any old CPU.
How can I enable vectorization?
You just need to tell your compiler to enable the corresponding instruction set, and Eigen will then detect it. If it is enabled by default, then you don't need to do anything.
On the x86 architecture, SSE is not enabled by default by most compilers. You need to enable SSE2 (or newer) manually. For example, with GCC, you would pass the -msse2 command-line option.
On the x86-64 architecture, SSE2 is generally enabled by default.
How can I disable vectorization?
You can forcibly disable vectorization by defining the EIGEN_DONT_VECTORIZE preprocessor symbol.
How does vectorization depend on the compiler?
Eigen has its own vectorization system, it does not at all rely on the compiler to automatically vectorize. However it still needs some support from the compiler, in the form of intrinsic functions representing a single SIMD instruction each.
Eigen will automatically enable its vectorization if a supported SIMD instruction set and a supported compiler are detected. Otherwise, Eigen will automatically disable its vectorization and go on.
Eigen vectorization supports the following compilers:
- GCC 4.2 and newer,
- MSVC 2008 and newer,
- All other compilers (for example it works with ICC).
Of course the reason why we "support all other compilers" is that so far we haven't seen other examples of compilers on which we should disable Eigen vectorization. If you know some, please let us know.
What can't be vectorized?
SSE and AltiVec work with packets of 128 bits, or 16 bytes. This means 4 ints, or 4 floats, or 2 doubles. Moreover, it is often required that the packets themselves be 128-bit aligned. Eigen takes care automatically of all that for you, but there are a few cases where it really can't vectorize. It will then automatically fall back to non-vectorized code, so that again is transparent to you, except of course that the resulting code isn't as fast as if it were vectorized.
The bad cases are fixed sizes that are not multiples of 16 bytes. For example, Vector2f, Vector3f, Vector3d, Matrix3f, Matrix3d.
All other cases are good cases and are successfully vectorized by Eigen:
- fixed sizes that are multiples of 16 bytes. For example, Vector2d, Vector4f, Vector4d, Matrix2f, Matrix2d, Matrix4f, Matrix4d, Transform3f, Transform3d.
- all dynamic sizes (typically larger). Here, the size is not even required to be a multiple of 16 bytes. For example, VectorXf, VectorXd, MatrixXf, MatrixXd.
Eigen also has some current limitations that can and will be overcome in the future:
- complex numbers aren't currently vectorized (this would require us to have our own complex class or wait for GCC to improve)
- some advanced operations, such as visitors, aren't currently vectorized (this is on our to-do).
How can I check that vectorization is actually being used?
First you can check that Eigen vectorization is enabled: the EIGEN_VECTORIZE preprocessor symbol is then defined.
Then, you may want to check the resulting assembly code. This is the best way to check that vectorization actually happened for a specific operation. Add some asm comments in your code around a line of code you're interested in, and tell your compiler to output assembly code. With GCC you could do:
Vector4f a, b; asm("#it begins here!") a += b; asm("#it ends here!")