c++ armadillo with openblas on windows 8 - c++

I am trying to install and use Armadillo with OpenBlas on Windows8 / Visual Studio.
I managed to install Armadillo and run a small program without problem. However it is using the default supplied-with-Armadillo 32 bit LAPACK and BLAS binaries which are too slow. I witnessed on linux that the speed improvement when using OpenBlas (compared to default Armadillo or BLAS) is huge when multiplying large matrices and would like to be able to use it on Win8 as well.
When I try to replace BLAS lib with OpenBlas from there:
http://sourceforge.net/projects/openblas/files/v0.2.8/
and try to link with libopenblas.lib, I get a lot of blas-related unresolved external (again, not the case when I link with the armadillo supplied blas_win32_MT.lib) and really have no idea how to solve the problem.
Any help much appreciated.
JPN

Related

Eigen Library + Intel MKL + Visual Studio 2022 not working

I am trying to enable Intel MKL (2023.0.0) on Eigen C++ (3.4.0) library using Visual Studio++, so far I am able to run Eigen library in Visual Studio 2022 with no issues.
But as stated on this other thread and official Eigen documentation, when I try to enable Intel MKL by adding
#define EIGEN_USE_BLAS
#include <Eigen/src/Core/util/MKL_support.h>
I manage to compile and execute, but throws this error
Intel MKL ERROR: Parameter 6 was incorrect on entry to SGEMV .
Intel MKL ERROR: Parameter 2 was incorrect on entry to SGEMV .
To enable Intel MKL on my Visual Studio project I added the include directories and library directories as stated here and the Intel MKL linker advisor, the libraries that the linker advisor recommends are
mkl_intel_ilp64.lib mkl_sequential.lib mkl_core.lib
For those who are curious, the line of code that throws this error is
Eigen::EigenSolver<Eigen::MatrixXf> es(eig_cov);
I am basically trying to compute the eigen vectors for a matrix of 8192x8192 (the matrix is symmetric and has been validated with other libraries like OpenCV and Armadillo, they just take so long, I have another thread about this in case you are curious)
Since my program is able to compile and execute and fail at the line above, I would say I have my dev environment setup but I am not really sure why Intel MKL is not liking Eigen, any pointers will be appreciated
PD: I tried to use EIGEN_USE_MKL_ALL instead of EIGEN_USE_BLAS, but I open a can of worms, looks more scary to solve that way.

How to locate and link with the exact same Intel MKL that MATLAB is shipped with?

The question in the header summarizes what I aim to achieve, which is more precisely detailed as below.
The goal is to compile C++ based mex files that rely on Intel MKL function calls (e.g. matrix inverse calculation).
In order to do so, I would like to ensure that I use the exact same Intel MKL libraries which MATLAB is shipped with, so as to avoid any compatibility issues. In this particular case, this is:
>> version('-blas')
ans =
'Intel(R) Math Kernel Library Version 2018.0.3 Product Build 20180406 for Intel(R) 64 architecture applications, CNR branch AVX
'
>> version('-lapack')
ans =
'Intel(R) Math Kernel Library Version 2018.0.3 Product Build 20180406 for Intel(R) 64 architecture applications, CNR branch AVX
Linear Algebra PACKage Version 3.7.0
'
Warning: the above Intel MKL BLAS & LAPACK are not the same as the ones that are available for download from Intel’s official website. The latter ones I would prefer not to use for the above-mentioned potential compatibility reasons.
In which MATLAB folder(s) are the above reference static/dynamic Intel MKL libraries are located?
I have extensively searched after them in the many MATLAB folders, but I unfortunately could not find them. It seems that they are ‘buried’ somewhere deep in MATLAB.
How is it possible to do this at all?
My setup: Windows 10, MATLAB R2091b, Intel MKL.
I am very grateful for any help. Thank you in advance.
On my Win64 machine I find them here
[matlabroot '/extern/lib/win64/microsoft']
and here
[matlabroot '/extern/lib/win64/mingw64']
The BLAS library is named libmwblas.lib, and the LAPACK library is named libmwlapack.lib
For reference, note that in R2007a and earlier, The Mathworks shipped the BLAS and LAPACK libraries as a single combined library. They weren't shipped as two separate libraries until R2007b and later.

Easily importing c++ libraries and dependencies on windows

I want to use some of the great libraries out there (e.g. cgal), but don't know how (have been exclusively writing my own code so far).
It seems every library requires a different process in order to use it (at least on windows)
I'm currently using Clion as an IDE in Windows 10 with minGW. I've tried using the Conan dependency manager but couldn't get it to work (and the documentation/video tutorials are not done very well).
Is there a recommended simple way to do it?
Is using vcpkg with visual studio a good way to go about it?
edit: for clarification, I am an academic physicist developing scientific simulations mostly to be used by myself, so I don't have to package my code with all the dependencies included.
Thanks.

Running a LAPACK build on different processors

If I build LAPACK on Windows / VS2010 using an Intel processor, will I be able to run the compiled code on another processor? I ask this, because I see that there are different instructions for compiling LAPACK on Intel or non-Intel processors.
I am thinking of using LAPACK as part of my project. I was going to build my project on my computer which has an Intel processor and then take the executable and simply run it on any other PC, regardless of the type of the processor it has. I have already considered using packages such as Eigen or MKL; but MKL is not cheap and Eigen was not fast enough for my application, so I decided to go with LAPACK / LAPACKE.

OpenCV, Matlab and STL containers

Many functions in the latest release of OpenCV require the use of STL containers. I run into problems when trying to use them in a Matlab MEX file. I am compiling the MEX files from within Matlab. Both OpenCV and Matlab use the "/MD" flag which is "Multithreaded DLL" for code generation.
Compiler: MSVC++ 9.0
Matlab 2010a
OpenCV latest from SVN, 2.11 I think.
The code I am using is very simple:
vector<KeyPoint> keypoints_vec;
SurfFeatureDetector surf;
surf.detect(cvImg,keypoints_vec);
This compiles but crashes when run in a Matlab MEX file. The crash is within OpenCV in vector::resize. The old interface (without STL containers) works fine but is deprecated. How can I use STL containers between Matlab and OpenCV?
I fought with this very problem in the last two days. The problem is this:
libmex.dll (and a whole Matlab) uses Microsoft.VC80.CRT (version=8.0.50727.4053)
But your OpenCV uses Microsoft.VC90.CRT (version=9.0.21022.8)
So you can use the previous version of VC (VS 2005 with SP1 as far as I know), or as a workaround, you can use gcc (MINGW) (in this case they use totally different stl, so they can't interfere).
I did the latter and it works, and it will work with the next versions of Matlab (hopefully).
A long time ago I had problems with Matlab <-> VS interop. It might be some microsoft visual c++ runtime library discrepancy. Check what runtime lib is required by matlab and what version does your visual studio have. I remember using Depends to get the dll dependencies for my program. Check your call stack after crashing (by attaching your msdev debugger) it might give you some hints.
It was a long time ago so I'm just giving hints of what I remember.
I had a similar problem in the past few days, and was able to resolve the issue with some help from the friendly folks at MathWorks.
From the original post at http://www.mathworks.com/matlabcentral/answers/9294-mex-dynamic-memory-management-issue-with-std-vector-in-linked-external-dll-segmentation-error :
You are probably seeing an incompatibility between the stl library and or compiler options used by your pre-compiled dll and those used by MATLAB and the MEX command. MATLAB 2009b was built with MSVC 2005.
You may be able to fix the problem by changing the options used by mex or by building your mex file directly with MSVC. One example of an option that may effect things is SECURE_SCL=0. I would start by building your test program with the options MATLAB is using to find the problematic option then try removing that option when building the mex file.
Because of this sort of incompatibility use of stl objects in the api's of third party compiled libraries is usually a bad idea.
Following his advice, I removed the SECURE_SCL=0 option from the mex options file at
C:\Users\ThePit\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat
Then recompiled the mex file, now everything works like a charm - the function is returning the correct data and segmentation error no longer occurs.
The data in a vector should still be stored as a single contiguous block
std::vector<int> data;
int *array = &data[0];
int *array = &data.front();
Should give you 'c' style pointers to the data, try passing these to matlab
see also: How does the C++ STL vector template store its objects in the Visual Studio compiler implementation?