我目前正在尝试将程序链接到英特尔 MKL 11.0 库,而不是使用 NetLIB 或 OpenBLAS。这样做我发现了以下错误,目前我无法向自己解释。考虑以下 C 代码示例,使用 计算复杂的标量积zdotc:
#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
double complex zdotc_(int *n, double complex *X, int *incx, double complex *Y, int *INCY );
int main ( ) {
int n = 5;
int incx = 1, incy = 1;
double complex x[5] = {1,I,2,2+I,3};
double complex y[5] = {I,3,I*3, 2+2*I, 9};
double complex ret;
ret = zdotc_(&n,x,&incx,y,&incy);
printf("n = %d\n", n);
printf("ret = %lg + %lgi\n", creal(ret), cimag(ret));
return 0;
}
我使用MKL Advisor给出的命令行标志编译了这个例子。我选择“GNU C/C++、32 位整数、动态链接、GNU OpenMP”。生成的命令行是:
gcc zdotc_test.c -o zdot_mkl_gcc -O2 -L$MKLROOT/lib/intel64 -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -ldl -lpthread -lm -fopenmp -m64 -I$MKLROOT/include
这个程序的输出是:
n = 0
ret = 0 + 1.07933e+21i
这显然是错误的,尤其是为什么要改变n?
如果我选择 GNU Fortran 而不是 GNU C/C++,我必须替换-lmkl_intel_lp64by-lmkl_gf_lp64然后正确的输出
n = 5
ret = 33 + 6i
被生产。
所以我的问题是:接口之间的详细区别在哪里,为什么第一个会产生这个错误?