I've got a Problem building a DLL including a function in Intel's
Lapack, not sure if this function is actually causing the trouble or if
it's the way I build and call a DLL .
However here's a test case for the problem:
This code is built to be a dll..
#include<iostream>
#include<math.h>
#include <complex>
#include<intel/mkl_lapack.h>
#include<intel/mkl_blas.h>
using namespace std;
#ifdef __cplusplus // If used by C++ code,
extern "C" { // we need to export the C interface
//extern "C++" { does not work, but why??
#endif
__declspec(dllexport) void get_reflection(int matrix_size)
{
MKL_Complex16 *Y_inv;
int *piv;
int i;
int lda=matrix_size;
int info;
Y_inv=(MKL_Complex16*)malloc(matrix_size*matrix_size*sizeof(MKL_Complex16));
piv=(int*)malloc(matrix_size*sizeof(int));
for(i=0;i<(matrix_size*matrix_size);i++){
Y_inv[i].real=rand();
Y_inv[i].imag=rand();
}
zgetrf(&matrix_size,&matrix_size,Y_inv,&lda,piv,&info);
}
#ifdef __cplusplus
}
#endif
This Program is calling the function get_reflection(int) from the DLL. A
crash occurs when get_reflection is called with an Integer (which
determines the size of an array) bigger than 18 (20 does not work). The
message I get is: 0xC0000005: Access violation reading location
0x00000000. Debugging the program line by line showed that the issue
comes up during execution of the function zgetrf. This is part of an
Lapack version distributed in intel's math kernel.
//reading location 0x00000000
#include<iostream>
#include <stdio.h>
#include<windows.h>
using namespace std;
typedef int(__cdecl *MYPROC)(int);
VOID main(VOID)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("testcase.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "get_reflection");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd)(20); //: 0xC0000005: Access violation reading
location 0x00000000.
//(ProcAdd)(18); //Works fine
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("ERROR\n");
}
There is always a crash when calling get_reflection with a parameter
(matrix_size) that is bigger than 20.
Funny thing is that the whole thing works just fine when I do not create
a dll thing but just built a executable, which get_reflection() is part of.
Example:
#include<iostream>
#include<math.h>
#include <complex>
#include<intel/mkl_lapack.h>
#include<intel/mkl_blas.h>
using namespace std;
void get_reflection(int matrix_size)
{
MKL_Complex16 *Y_inv;
int *piv;
int i;
int lda=matrix_size;
int info;
Y_inv=(MKL_Complex16
*)malloc(matrix_size*matrix_size*sizeof(MKL_Complex16));
piv=(int*)malloc(matrix_size*sizeof(int));
for(i=0;i<(matrix_size*matrix_size);i++){
Y_inv[i].real=rand();
Y_inv[i].imag=rand();
}
zgetrf(&matrix_size,&matrix_size,Y_inv,&lda,piv,&info);
}
void main(){
get_reflection(20); //This call works
}
I would very much appreciate any help on that problem. Probably it's the
way I build/call the DLL, or there's some memory allocation issue in the
zgetrf routine.
Cheers
Sebastian
_______________________________________________
msvc mailing list
[email protected]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for
subscription changes, and list archive.