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

Replacing XERBLA

johnwavemetrics_com
785 Views
The MKL docs talk about replacing the BLAS error handler XERBLA, but don't provide much (any?) guidance.

I am writing in C/C++, using Visual Studio 2005 to build my application, linking statically to MKL 10.1.0.018.

If I simply write a function called xerbla (may xerbla_?) will it be linked in preference to the MKL version? Would I use cdecl calling convention for it?
0 Kudos
7 Replies
TimP
Honored Contributor III
785 Views
The MKL docs talk about replacing the BLAS error handler XERBLA, but don't provide much (any?) guidance.

I am writing in C/C++, using Visual Studio 2005 to build my application, linking statically to MKL 10.1.0.018.

If I simply write a function called xerbla (may xerbla_?) will it be linked in preference to the MKL version? Would I use cdecl calling convention for it?
Your xerbla would have compatible calling interface to legacy Fortran/f2c/ as you would see if you ran f2c on the netlib source version, with one exception: the Windows default linkage is cdecl, as you suggested, but with upper case identifiers and no trailing underscore. You could use dumpbin /symbols or equivalent method to check the one from MKL. If you put it ahead of the mkl_core library in the link command, and use static linking, yours would be used in preference.
The XERBLA has Fortran linkage, so the parameters should be pointer to string, pointer to int, string length (6) by value. At least, this is what I expect to see. If you confirm whether you are writing for 32-bit or X64, I could try to confirm it.
0 Kudos
Vladimir_Lunev
New Contributor I
785 Views
On Windows you need to use upper-case XERBLA to replace BLAS error handler.
void XERBLA (char * Name, int * Num, int Len) {
printf("n*** My XERBLA is called :%s: %dn",Name,*Num);
return;
}
-Vladimir


0 Kudos
bb_12_bb_12
Beginner
785 Views
The MKL docs talk about replacing the BLAS error handler XERBLA, but don't provide much (any?) guidance.

I am writing in C/C++, using Visual Studio 2005 to build my application, linking statically to MKL 10.1.0.018.

If I simply write a function called xerbla (may xerbla_?) will it be linked in preference to the MKL version? Would I use cdecl calling convention for it?
Hi John, did you ever get this to work? I am using the same setup and adding a function XERBLA didn't do anything.
What worked for me was implementing the following function (cdecl, implementd as C (not C++))

void cblas_xerbla(const char *srname, const int *info, const int lsrname)
{
printf("n*** My xerbla is called :%s: %dn", srname, info);
return;
}

I do get a call back with that. I am wondering if it's the right way to do it.
And anybody there at Intel, why is it that XERBLA doesn't work? Also, is there a way to just check the error code for BLAS/LAPACK functions after they complete? I don't always want to deal with callback functions.

Thank you
0 Kudos
TimP
Honored Contributor III
785 Views
As long as your linker symbols match up, you can do whatever you wish. This seems fine if you chose the CBLAS interface. In order to replace XERBLA directly with a C function, you must take into account the Fortran name mangling of the compiler you choose, as we discussed earlier in the thread.
0 Kudos
Vladimir_Lunev
New Contributor I
785 Views


Since the version MKL 10.1 Update 2, you can use both xerbla and XERBLA to replace MKL error handler.
The correct interface of MKL cblas_xerbla() is:
void cblas_xerbla (const char * Name, const int Num);
Note, this function is undocumented and we can change its interface in any time without special warnings.

Please try such example:
#include
#include
#define buf_len 198
int main() {

char transa, transb;
double *a, *b, *c;
double alpha, beta;
int n = 100, N, i, j;
char buf[buf_len];

MKLGetVersionString(buf, buf_len);
printf("nMKL release version:n"); fflush(NULL);
printf("%sn",buf); fflush(NULL);

transa = 'N'; transb = 'N';
alpha = 1.1; beta = -1.2;
a = (double *)calloc( n*n, sizeof( double ) );
b = (double *)calloc( n*n, sizeof( double ) );
c = (double *)calloc( n*n, sizeof( double ) );

N = -n;
printf("nCall dgemmn"); fflush(NULL);
dgemm(&transa,&transb,&N,&N,&N,α,a,&N,b,&N,β,c,&N);

printf("nCall cblas_dgemm"); fflush(NULL);
cblas_dgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans,-N,N,N,alpha,a,N,b,N,beta,c,N);
}

void XERBLA (const char * Name, const int * Num, const int Len) {
printf("nUser xerbla is called :%s:%dn",Name,*Num); fflush(NULL);
return;
}

void cblas_xerbla (const char * Name, const int Num) {
printf("nUser cblas_xerbla is called :%s:%dn",Name,Num); fflush(NULL);
return;
}

You should see the output something like this:

MKL release version:
Intel Math Kernel Library Version 10.1.1 Product Build 082212.12 for Intel 64 architecture applications

Call dgemm
User xerbla is called :DGEMM :3

Call cblas_dgemm
User cblas_xerbla is called :cblas_dgemm:5


-Vladimir

0 Kudos
bb_12_bb_12
Beginner
785 Views
Thank you Vladimir.
Now I understand. dgemm() calls XERBLA and cblas_dgemm calls cblas_xerbla().

Is there a way to avoid getting the callbacks and check an error code instead after the function completes? I know that I can do it for vml (vmlGetErrStatus()). Is there a way to do it for BLAS, dgemm for example?
0 Kudos
Vladimir_Lunev
New Contributor I
785 Views
Quoting - bb_12_bb_12
Thank you Vladimir.
Now I understand. dgemm() calls XERBLA and cblas_dgemm calls cblas_xerbla().

Is there a way to avoid getting the callbacks and check an error code instead after the function completes? I know that I can do it for vml (vmlGetErrStatus()). Is there a way to do it for BLAS, dgemm for example?

Unfortunately, no. BLAS doesn't have such functionality.
-Vladimir
0 Kudos
Reply