我尝试在以下c#例程中调用英特尔的MKL。 LapackE与Lapack的接口略有不同(第一个参数是额外的)。 我得到-1作为返回值,应该为零(0)。显然我做错了,但是我找不到我的错误。
-1可能意味着第一个元素LAPACK_ROW_MAJOR是错误的。但是我认为我正确地遵循了文档(MKL的输出显示“ LAPACKE_dsygv中的参数1错误”)。
所示程序确实在dll中找到了MKL例程。 更改CallingConvention无效。
以下是相关代码:
const string mkl = @"C:\.....\mkl_rt.dll";
[DllImport(mkl, CallingConvention = CallingConvention.Cdecl, EntryPoint = "LAPACKE_dgesvx", ExactSpelling =true)]
static public extern int Solve(ref int matrix_layout, ref char fact, ref char trans, ref int n,
ref int nrhs, [In, Out] double[] a, ref int lda, [Out] double[] af, ref int ldaf,
[Out] int[] ipiv, ref char equed,[Out] double[] r, [Out] double[] c, [In,Out] double[] b, ref int ldb,
[Out] double[] x, ref int ldx, ref double rcond, [Out] double[] ferr, [Out] double[] berr, ref double rpivot);
和:
static void test2a()
{
// a posdef, symm matrix
var A = new double[100] {
13.5227 , 3.1212 , 3.2529 , 2.6585 , 3.4137 , 2.4130 , 2.8550 , 2.7798 , 3.4402 , 2.5503 ,
3.1212 , 13.4281 , 3.2305 , 2.6748 , 3.3425 , 2.3306 , 2.7420 , 2.9142 , 3.3068 , 2.4412 ,
3.2529 , 3.2305 , 13.7697 , 2.8702 , 3.4297 , 2.8870 , 3.3513 , 2.9031 , 3.5689 , 2.5747 ,
2.6585 , 2.6748 , 2.8702 , 12.8256 , 2.9177 , 2.2536 , 2.6223 , 2.5055 , 2.6388 , 2.0222 ,
3.4137 , 3.3425 , 3.4297 , 2.9177 , 13.9256 , 2.6981 , 2.8698 , 2.7950 , 3.2938 , 2.3925 ,
2.4130 , 2.3306 , 2.8870 , 2.2536 , 2.6981 , 12.5476 , 2.5550 , 1.9752 , 2.6165 , 1.8440 ,
2.8550 , 2.7420 , 3.3513 , 2.6223 , 2.8698 , 2.5550 , 13.3263 , 2.6239 , 3.1382 , 2.2518 ,
2.7798 , 2.9142 , 2.9031 , 2.5055 , 2.7950 , 1.9752 , 2.6239 , 12.7882 , 2.9495 , 2.2545 ,
3.4402 , 3.3068 , 3.5689 , 2.6388 , 3.2938 , 2.6165 , 3.1382 , 2.9495 , 13.7888 , 2.7565 ,
2.5503 , 2.4412 , 2.5747 , 2.0222 , 2.3925 , 1.8440 , 2.2518 , 2.2545 , 2.7565 , 12.1510
};
int lda = 10;
int n = 10;
var X = new double[10] { 3, 4, 5, 6, 1, 6, 7, 3, 4, 5 };
// resulting B must be equal to Y:
//var Y = new double[10] { -0.0207, 0.0839, 0.1313, 0.3000, -0.2262, 0.3123, 0.3561, 0.0061, 0.0481, 0.2403 };
var B = new double[10] { 3, 4, 5, 6, 1, 6, 7, 3, 4, 5 };
int info = 0;
int nrhs = 1;
int ldb = 10;
int ldx = 10;
int LAPACK_ROW_MAJOR = 101;
int LAPACK_COL_MAJOR = 102;
char fact = 'N',
equed = ' ',
trans = 'N';
double[] af = new double[100],
r = new double[100],
x = new double[ldx * nrhs],
ferr = new double[nrhs],
berr = new double[nrhs],
c = new double[100];
int[] ipiv = new int[100];
double rcond = 0,
rpivot = 0;
try
{
info = Mkl.NativeMethods.Solve(ref LAPACK_ROW_MAJOR, ref fact, ref trans, ref n,
ref nrhs, A, ref lda, af, ref n,
ipiv, ref equed,r , c, B, ref ldb,
x, ref ldx, ref rcond, ferr, berr, ref rpivot);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
有人可以帮助我更正代码吗? 或以某种方式将我指向正确的方向?