Skip to content

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 <iostream>
#include <ctime>
#include <Eigen/Eigen>

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

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

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

clock_t clock_start=clock();

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

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

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

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

cout<< "Elapsed Time is: "<< time_c<< "s" <<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

    Reply
      • 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.

        If I look in your link.read.1.log file from dropbox I see:

        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

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *