MKL BLAS 功能未按预期运行

MKL BLAS functions not behaving as expected

我无法让英特尔 MKL 从 C 中正常工作。 我有以下测试程序:

#include "stdafx.h"
#include"mkl.h"
int main()
{
    int one = 1;
    int ten = 10;
    double copy[10];
    double threes[10];

    for (int i = 0; i < 10; ++i) threes[i] = 3;

    dcopy(&ten, threes, &one, copy, &one);
    double l1norm;
    l1norm = dasum(&ten, threes, &one);
    return 0;
}

构建和链接正常,但未达到我的预期。特别是在 return 行,数组 "copy" 仍然充满了声明时的内容,并且 l1norm 等于 0。 我正在链接到库:mkl_blas95_ilp64.lib、mkl_core_dll.lib、mkl_intel_ilp64_dll.lib 和 mkl_intel_thread_dll.lib.

当 运行 调用 MKL 的第三方代码时,我也遇到了类似的问题,所以我认为问题是我如何配置构建(在 Visual Studio 2015 年)。

等效的 Fortran 程序运行良好。

从 Fortran 移植到 C/C++ 时,请检查您 link 的库。 MKL 需要不同的库和具有不同编译器和设置的编译标志。 C 编译器至少不需要 mkl_blas95_ilp64.lib

与默认模型 LP64 相比,ILP64 并不常见。

MKL Link Line Advisor 是Intel 提供的解决这个问题的工具。您可以使用它来检查您的库和编译标志是否正确。

https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor