0

I'm working with OpenBLAS on Windows and am experiencing crashes. I'm using test code bellow (entire program), taken from Intel MKL from here (I slightly modified it). The same problem is with other function calls. With step by step debugging, the crash occurs after return 0 in main. The loop that outputs the matrix print the correct result.

double *A, *B, *C;
int m, n, k, i, j;
double alpha, beta;

m = 2, k = 2, n = 2;
alpha = 1.0; beta = 0.0;

A = (double *) malloc(m*k*sizeof(double));
B = (double *) malloc(k*n*sizeof(double));
C = (double *) malloc(m*n*sizeof(double));

for (i = 0; i < (m*k); i++) A[i] = (double) (i + 1);
for (i = 0; i < (k*n); i++) B[i] = (double) (-i - 1);
for (i = 0; i < (m*n); i++) C[i] = (double) 0.0;


cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
    m, n, k, alpha, A, k, B, n, beta, C, n);


printf("\n Top left corner of matrix C: \n");
for (i = 0; i<min(m, 6); i++)
{
    for (j = 0; j<min(n, 6); j++)
        printf("%12.5G", C[j + i*n]);
    printf("\n");
}

free(A);
free(B);
free(C);

The crash occurs after exit(mainret) is executed.

 #else  /* !defined (_WINMAIN_) && defined (_CRT_APP) */
        if ( !managedapp )
        {
 #ifndef _CRT_APP
            exit(mainret);
 #else
            _exit_app();
 #endif  /* _CRT_APP */
 #if !defined(_WINMAIN_) && defined(_CRT_APP)
            /* WINAPI_FAMILY_APP "Windows" applications should never reach here,
             * but Console applications will if they do not exit the process.
             * So, terminate the process for Console apps only
             */
            ExitProcess(mainret);
 #endif
        }

The first thing I thought of was ESP value, which might get corrupted if function calling conventions do not match (I'm using prebuilt MinGW OpenBLAS 0.2.14 libraries), but all ESP checks in debug build pass successfully. I'm using MSVC++ compiler and built assembly is 32-bit.

How can I pinpoint the problem more precisely or what might be the cause behind this crashes?

Jaka Konda
  • 1,385
  • 3
  • 13
  • 35
  • It's not easy to tell what's going on without debugging, here some checks you can do (likely you already have): 1)Be sure it's the call to cblas_dgemm the problem by commenting it 2) With a debugger check ESP before the call and after 3) Check that ESP is kept aligned 4)I can't see any possible buffer overflow but do a quick check anyway. 5)Step into cblas_dgemm to see the prolog and the epilog and guess the calling convention 6) Reproduce the crash with the smallest code possible and investigate from there –  Jun 14 '15 at 14:52
  • I already done all of the above but with no luck. I made a new solution where it worked without any problems from the start. Strange... – Jaka Konda Jun 16 '15 at 14:19
  • btw what is meant by %12.5G. why not use %12.5f? – stats con chris Jan 29 '23 at 14:36

0 Answers0