# Using Eigen Linear Algebra Library with Visual C++ 2010 Express 64bit

Eigen is a free and open source, relatively fast, very versatile linear algebra library written completely in C++ templates. It is very fast and in some cases produces code as fast as commercial implementations like Intel MKL, AMD ACML etc. The beauty of the Eigen is, it’s completely written in C++ templates and it’s very easy to plug it in to a project compiled with any supported compiler.

Here I describe the process of how to install Eigen with Microsoft Visual Studio 2010 Express and 64bit compilers from Microsoft Windows SDK 7.1 supporting OpenMP and vectorization with SSE2.  All these tools are free.

###### Install Microsoft Tools
```Install Visual C++ 2010 Express Edition &
Install Microsoft Windows SDK for Windows Version 7.1.

When WindowsSDK is installed,
Make sure to include Visual C++ Compilers as seen in the above picture```
###### Install Eigen Library
```
Just unzip the latest version of the Eigen template library to the hard disk.```
###### Creating New Project
```

Start Visual c++ 2010 Express and create a new
Visual C++ Empty Project. Give a name for the new project.```
###### Add a new c++ source file to the project

Add a new c++ source file to the project and copy-paste the code below. Visual C++ editor will highlight missing include files and datatypes in the source code. This is expected because Visual C++ environment still doesn’t know where the Eigen libraries, and this can be fixed very easily.

```
#include &lt;iostream&gt;
#include &lt;ctime&gt;
#include &lt;Eigen/Eigen&gt;

using namespace std;
using namespace Eigen;
int main()
{

MatrixXd A = MatrixXd::Random(5000,5000);
MatrixXd B = MatrixXd::Random(5000,2);

//cout &lt;&lt; "Here is the invertible matrix A:" &lt;&lt; endl &lt;&lt; A &lt;&lt; endl;
//cout &lt;&lt; "Here is the matrix B:" &lt;&lt; endl &lt;&lt; B &lt;&lt; endl;

clock_t clock_start=clock();

MatrixXd X = A.lu().solve(B);

double time_c=(double)(clock()- clock_start)/CLOCKS_PER_SEC;

//cout &lt;&lt; "Here is the (unique) solution X to the equation AX=B:" &lt;&lt; endl &lt;&lt; X &lt;&lt; endl;

cout &lt;&lt; "Relative error: " &lt;&lt; (A*X-B).norm() / B.norm() &lt;&lt; endl;

cout&lt;&lt; "Elapsed Time is: "&lt;&lt; time_c&lt;&lt; "s" &lt;&lt;endl;

cin.get();
}
```
###### Create 64bit solution platforms
```

Create 64bit "Solution platforms" for both
"Debug" and "Release" "Solution Configurations".```
##### Set Project Properties for ‘Release’ Configuration and ‘x64’ Platform
###### Platform Toolset – Windows7.1SDK
```
Set Platform Toolset to Windows7.1SDK```
###### Add Eigen Library to Include Path
```

Add Eigen library location to VC++ Include path.
Once this step is done, VC++ editor should no longer
highlight error in the sample code.```
###### Multi processor compilation
```
Turn on Multiprocessor Compilation if you have a multicore processor.```
###### Compiler Optimization
```
Make sure compiler optimization is set to 'Maximize Speed'```
###### Enable Enhance Instruction Set Support
```
Enable SSE2 support. Once enabled Eigen will
Make use of SSE2 to Vectorize it's code generation```
###### Turn on OpenMP support
```
Eigen uses OpenMP when possible. Eigen uses OpenMp specialy
during crucial Matrix-Matrix product calculations.```
###### Build and Run the Project

Build and run the project. The given example code solves a system linear equation with 5000 equations. As you can see from above picture all processor core are occupied during calculation. You can turn on and off OpenMP and SSE2 support and test how fast the code completes when these features are turned on and off.

#### 3 thoughts on “Using Eigen Linear Algebra Library with Visual C++ 2010 Express 64bit”

1. Dietmar Warning says:

Hello,

is it really true that you can link a 64bit Version including openMP?

If I try to do so with an other Project I got an link error that vcomp.lib was not found. 32 bit linking is OK. I am using VC Studio 2010 Express with SDK 7.1 enabled and same configuration like in your Project.

Any hints?

Thanks

Dietmar

• Dietmar Warning says:

Thanks for answering. Yes, it seems that some files are missing as described in the Microsoft Report. But using the SP1 update did not Change the Situation. Don’t know why.

C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 10.0\VC\BIN\X86_AMD64\C2.DLL
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 10.0\VC\LIB\AMD64\MSVCPRT.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 10.0\VC\LIB\AMD64\MSVCRT.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 10.0\VC\LIB\AMD64\OLDNAMES.LIB
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 10.0\VC\LIB\AMD64\VCOMP.LIB

All the files I have except the AMD64\VCOMP.LIB. (And perhaps the .dll too!)

Best Regards

Dietmar