Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Declaring BLAS functions from mkl_rt.dll in VBA Excel

Mikhail_K_
초급자
3,662 조회수

Hi,

The stdcall requirement normally needed for dlls to work in VBA only applies to 32bit dlls. In 64bit dlls there is only one calling convention, I think.

So, for example, With 64-bits OpenBLAS I am able to do declare a call to a fortran BLAS function (not cblas) and it works fine:

Public Declare PtrSafe Sub dgemm Lib "libopenblas.dll" (ByVal transa As String, _
                                                        ByVal transb As String, _
                                                        ByRef m As Long, _
                                                        ByRef n As Long, _
                                                        ByRef k As Long, _
                                                        ByRef alpha As Double, _
                                                        ByRef a As Double, _
                                                        ByRef lda As Long, _
                                                        ByRef b As Double, _
                                                        ByRef ldb As Long, _
                                                        ByRef beta As Double, _
                                                        ByRef c As Double, _
                                                        ByRef ldc As Long)

But whichever way I tried the same does not work with 64bit mkl_rt.dll. Excel just quietly quits.

Do I have to compile a BLAS-only 64bit dll to be used with VBA Excel? If yes, how exaclty (I urge you to explain in detail)?

 

MKL headers are slightly different from OpenBLAS, not sure if its somehow related to this:

MKL:

void __stdcall DGEMM(const char *transa, int transa_len, const char *transb, int transb_len, const MKL_INT *m, const MKL_INT *n, const MKL_INT *k,
                     const double *alpha, const double *a, const MKL_INT *lda, const double *b, const MKL_INT *ldb,
                     const double *beta, double *c, const MKL_INT *ldc);

 

OpenBLAS:

void BLASFUNC(dgemm)(char *, char *, blasint *, blasint *, blasint *, double *,
	   double *, blasint *, double *, blasint *, double *, double *, blasint *);

 

Any tips?

0 포인트
4 응답
Mikhail_K_
초급자
3,663 조회수

Hi, false alarm figured it out.

Dependecy Walker showed that mkl_rt.dll does not rely on other dlls, but I gathered all MKL dlls in one directory anyway. When looking at what other dlls load up when calling for example cblas_drotg, the following shows up:

libiomp5md.dll
mkl_avx2.dll
mkl_core.dll
mkl_intel_thread.dll
mkl_rt.dll
0 포인트
Ngo__Nhan
초보자
3,645 조회수

Hi Mikhail,

I have the same problem, my excel is crashed when the call is made too.

I have posted the question: https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Cannot-Invert-Matrix-using-Lapack-DGETRF-DGETRI-in-VBA/m-p/1188023#M29646

Could you review and give the instruction?

Thank you a lot.

0 포인트
Gennady_F_Intel
중재자
3,622 조회수

one notes regarding the single dynamic library - this mode, by default provides support of LP64 and Intel threading mode. Please refer to the MKL's Developer Guide follow this link:https://software.intel.com/content/www/us/en/develop/documentation/mkl-linux-developer-guide/top/linking-your-application-with-the-intel-math-kernel-library/linking-quick-start/using-the-single-dynamic-library.html

Ngo__Nhan
초보자
3,596 조회수

Hi Gennady,

Could you help me to provide the documents which show how we declare the function in mkl_rt for window and excel 32bit? I used ByRel for all variables used for DGETRF/DGETR which work in Window and Excel 64bit but 32 bit.

Thank you for giving instructions.

0 포인트
응답