0

I downloaded GotoBLAS library at http://www.tacc.utexas.edu/tacc-projects/gotoblas2/ and I want to use syev() function to calculate eigenvectors and eigenvalues of a matrix. But I'm a newbie with opensource library and I don't know how to use it? Can anyone help me?

David Manpearl
  • 12,362
  • 8
  • 55
  • 72

1 Answers1

1

First of all, as suggested by its name, GotoBLAS means to provide BLAS only, but its version 2.0 also distributes and compiles LAPACK, which contains the functions ssyev for single-precision float and dsyev for double-precision of your interests. In order words, it is equivalent to say that you want to use LAPACK in C++ with visual studio 2010.

I guess the problem is not how to use libraries in VS2010 but how to use LAPACK package with C++. Here is a little hint: LAPACK is written in Fortran. Due to historical reasons, libraries written by Fortran can be directly accessed by C. In C++, specifically, you need to declare the function, for instance, dot-product for double ddot by

extern "C"{ 
    double ddot_(
        const int*    n,   // dimension 
        const double* dx,  // []vector x
        const int*    incx,// index increment of each access of x
        const double* dy,  // []vector y
        const int*    incy // index increment of each access of y
    );
}

In Fortran, every function argument is passed by reference, so in C/C++, we need to pass arguments by pointers, even for scalars.

Once you declare the function prototypes, you can use it everywhere. In this case, we can call it by, for example,

double x[] = {1,2,3};
double y[] = {1,1,1};
int    inc = 1;
int    n   = 3;
std::cout << ddot_(&n, x, &inc, y, &inc) << std::endl;

The printed result should be 6. Pay extra attention at where to put & and where not to. It is very easy to make a mistake.

Make sure you put lapack (or the name of your GotoBLAS library) in project library setup. In command line with g++ for example,

g++ -llapack your_file_name.cpp -o output_file_name

Hope this helps!

Yo Hsiao
  • 678
  • 7
  • 12