I just installed GSL and BLAS on Visual Studio 2010 successfully using this guide:
However the matrix multiplications using cblas are ridicously slow. A friend on Linux had the same problem. Instead of linking via GSL to BLAS, he linked directly to cBLAS (I don't exactly understand what this means but maybe you do?) and it got about ten times as fast.
How can I do this in Visual Studio? In the file I downloaded I couldn't find any more files that I could build with Visual Studio.
BLAS was the fortran mathematics library of simple operations, like multiplying or adding vectors and matrices. It implemented the vector-vector, vector-matrix, and matrix-matrix operations.
Later, different libraries was created which do the same as original BLAS but with more performance. The interface was saved, so you can use any of BLAS-compatible library, e.g. from your CPU vendor.
This FAQ http://www.netlib.org/blas/faq.html has some libraries listed; wikipedia has another list: http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms
The only problem with GSL - is in using C language. Interface of BLAS may be converted to C in various ways (the problem is in fortran functions name translation to c functions name, e.g. fortran DGEMM may be called DGEMM or DGEMM in C). GSL uses CBLAS convention: cblas_ prefix, e.g. GEMM will be named cblas_gemm.
So, try some libraries, from the lists, and check, is there cblas_ function aliases in the library. If yes, gsl may use this library.
Related
There exist C++ libraries such as Eigen or Boost::uBlas that implement matrix types and computations.
There also exist libraries such as LAPACK, Goto-BLAS, OpenBLAS and ATLAS that implement highly optimized dense matrix computations over floating-point types.
I was wondering whether some C++ libraries, perhaps through specialization, call OpenBLAS for the types supported by OpenBLAS. It would seem the best of both worlds.
I don't know about Boost::uBlas, but using the current version (3.3 or higher) of Eigen it is possible to link to "any F77 compatible BLAS or LAPACK libraries" so assuming OpenBLAS is F77 compatible, yes. See this for details.
I compiled GSL and OpenBLAS from source with all default options in both cases. My GSL libraries are installed in /usr/local/lib and OpenBLAS in /opt/OpenBLAS/lib. How do I use OpenBLAS with GSL in C++?
The main reason I am doing this is because OpenBLAS utilizes all cores which Atlas does not in default configuration. My main aim is to multiply two large matrices (10000 x 10000) and perform 2D convolutions. Is there a better alternative to OpenBLAS or GSL for this?
I am using:
Linux Mint 17.2
GCC version 4.8.4
20 Core Intel CPU
I have been experimenting with the same thing in Octave with OpenBLAS. Will I get a significant performance improvement by using C++?
I would use an existing linear algebra library like Armadillo. AFAIK it wraps your BLAS implementation for matrix multiplications. I like it because it provides you with a syntax very similar to the one in Matlab or Octave.
Other linear algebra libraries like Eigen will also do the job.
But i do not expect them to perform (much) better than Octave or Matlab as long as the call to the underlying library remains same. Also checkout why matlab is so fast and how armadillo is parallelized.
I'm porting some code from MATLAB to C++ and discovered that MATLAB's sin() and cos() functions produce slightly different results from the sin() and cos() functions in the C++ library. To eliminate these differences, I would like my C++ code to call the sin() and cos() functions from the fdlibm 5.3 library, which is what I think MATLAB uses for sin() and cos() operations.
However, I have been having some difficulty using the fdlibm library. I am using Visual Studio 2010, and downloaded the fdlibm header file and source codes from http://www.validlab.com/software/, but am not sure the best way to use these files. Do I need to first build the files into a static or dynamic library, and then link it to my code? Also, how do I specify that I want to use the sin() from fdlibm, rather than from C++ library? Do I need to modify the fdlibm source code so that the sin() and cos() functions are within a namespace?
Any guidance is greatly appreciated.
Essentially, you have two tasks to complete:
You must compile the fdlibm source to produce an object module suitable for your purpose.
You must link the object module with your other object modules.
I see two issues with the first task. One, sources from projects like fdlibm are typically written to be portable to many systems and may involve a fair amount of work to configure. Rather than being very simple C or C++ code, they may use a number of preprocessor conditionals to select certain options, and the package the sources come in may have scripts to make various preparations for compiling.
Two, you want the sources to match the C++ standard’s specification for declaring sin and cos. If the fdlibm package you have supports C++, this might not require any work on your part. Otherwise, you may have to modify the sources to wrap the sin and cos definitions inside the std namespace, or otherwise modify the sources.
The second issue is linking. Using a library is not required. You can simply compile the source file(s) containing sin and cos to produce an object module (or modules), then link that object module (or modules) with your other object modules. If you wish, you can instead create a library, put the object module(s) with sin and cos into the library, and link the library with your object modules. With most common linkers, you can link a library with your object modules simply by listing it as input the linker, the same way object modules are listed. (Some linkers also have other options for referring to libraries, but simply giving its normal file path is usually sufficient.) You can create and link either a static or a dynamic library, as you prefer. If you use a dynamic library, it must be present when the executable runs. For a simple application for your own use, there is no need to use a dynamic library (or even to use a static library; object modules are fine). (Essentially, the purpose of libraries is to make distributing object modules to other people easier, or to organize large projects. Simple applications do not need libraries.)
Another note about linking: When you supply your own sin and cos, the linker has two implementations to choose from: Your implementations of sin and cos and the standard library implementations of sin and cos. Usually, standard libraries are linked in after any user-specified files, so merely specifying your object module or library will suffice to ensure your sin and cos are used, not the library’s sin and cos. In the event this is not the case, there should be linker options to change the order in which libraries are considered.
in my quest to solve eigenvector problems of symmetric, real matrices quickly (I only need the first N eigenvalues and vectors, where "first" refers to the one with largest (real) value), I'm trying to get ARPack++ running on Windows. I use MSVS 2010 for development.
I'm currently in linker hell. I'm also not a 99 years C++ professional who eats bits for breakfast.
First, ARPACK++ is a header-only library, that's good! It depends on ARPACK, and ARPACK again has required dependencies on BLAS and LAPACK. Luckily, for windows users, the .lib and .dll files are available for BLAS, LAPACK and ARPACK, and ARPACK++ has been patched such that it works with modern compilers (and includes some bug-fixes).
As it seems, ARPACK++ introduces the required dependency to the SuperLU library. This is because, in my case I need to use the
ARluSymStdEig<ARFLOAT> prob(nev, matrix, which, ncv, tol,
maxit, resid, AutoShift);
class/CTOR, which has "lu" in its name, and I do indeed get missing symbols.
The next thing I tried was to grab the SuperLU library from around that time (2000ish), which is SuperLU 2.0. This one can be compiled using MSVS2010 directly (compared to ARPACK for example which has to be compiled with MinGW/MSys, unless you pay for Intel's FORTRAN compilers). I included the static superlu2.lib I created, but it seems SuperLU itself has methods that are just declared but not implemented, particularly
void cusolve(int, int, complex*, complex*);
void clsolve(int, int, complex*, complex*);
void cmatvec(int, int, int, complex*, complex*, complex*);
in cgstrs.c. Now I'm stuck and don't know how to continue :/ It seems like SuperLU has dependencies again, but they're not mentioned.
It turns out all I forgot to do was to add not only all .c and .h files from "src" of SuperLU to the VS project, but ALSO add the files from "cblas" directory. All dependencies are thus solved.
I want to use lapack and make C++ matrix wrapper for it, but lapack is written in Fortran, there are some clapack but I want to use it from source. compile firstly *.f and *.cpp files to object files then link it into a application..
the following apps and sources that I have.
visual studio proff edition,dev c++,ultimate++,mingw whatever
g95 and gfortran (under mingw) compiler
lapack (latest source)
blas (included in lapack)
How can I make an application please help...
My Operating System is Windows 7 and CPU Core2Duo and I dont have Intel math kernel
You can use the official C bindings for LAPACK, and then build your C++ wrapper around that. That avoids the issue of having to worry about the Fortran calling conventions, and the C bindings are a bit friendlier for C/C++ programmers than calling the Fortran routines directly.
Additionally, you could use one of the C++ matrix libraries that are already available, instead of rolling your own. I recommend Eigen.
PS.: Eigen matrices/vectors have a data() member that allows calling LAPACK without having to make temporary copies.