VS2019配置MKL教程

VS2019配置MKL教程,第1张

VS2019配置MKL教程(Windows)

下载链接:https://software.intel.com/en-us/mkl

文件下载

官网注册后,选择MKL下载下来,安装到指定目录就行,不在多说。


配置文件

首先创建一个Windows桌面项目,再添加一个CPP源文件。


打开项目属性页--配置属性,会多出Intel Performance...这一项,看下图配置

打开VC++目录,进行配置。


我安装MKL的地方在D:\IntelSWTools

打开D:\IntelSWTools\compilers_and_libraries_2019.5.281\windows,由于版本不同,可能后面的版本更新日期可能不同。


按照下面根据你的情况添加。


可执行文件目录:D:\IntelSWTools\compilers_and_libraries_2019.5.281\windows\mkl\bin

包含目录:D:\IntelSWTools\compilers_and_libraries_2019.5.281\windows\mkl\include

库目录:

D:\IntelSWTools\compilers_and_libraries_2019.5.281\windows\compiler\lib\ia32_win

D:\IntelSWTools\compilers_and_libraries_2019.5.281\windows\mkl\lib\ia32_win

注意:在选择生成程序时,选择生成x86程序。


如果要生成x64程序,那么库文件那里选择intel64_win。


打开链接器,在附加依赖项添加(如果配置64位程序,需要将mkl_intel_c.lib改成mkl_intel_lp64.lib

mkl_intel_c.lib;mkl_intel_thread.lib;mkl_core.lib;libiomp5md.lib;

配置测试
#include <stdio.h>
#include <stdlib.h> #include "mkl.h" #define min(x,y) (((x) < (y)) ? (x) : (y)) int main()
{
double* A, * B, * C;
int m, n, k, i, j;
double alpha, beta; printf("\n This example computes real matrix C=alpha*A*B+beta*C using \n"
" Intel(R) MKL function dgemm, where A, B, and C are matrices and \n"
" alpha and beta are double precision scalars\n\n"); m = , k = , n = ;
printf(" Initializing data for matrix multiplication C=A*B for matrix \n"
" A(%ix%i) and matrix B(%ix%i)\n\n", m, k, k, n);
alpha = 1.0; beta = 0.0; printf(" Allocating memory for matrices aligned on 64-byte boundary for better \n"
" performance \n\n");
A = (double*)mkl_malloc(m * k * sizeof(double), );
B = (double*)mkl_malloc(k * n * sizeof(double), );
C = (double*)mkl_malloc(m * n * sizeof(double), );
if (A == NULL || B == NULL || C == NULL) {
printf("\n ERROR: Can't allocate memory for matrices. Aborting... \n\n");
mkl_free(A);
mkl_free(B);
mkl_free(C);
return ;
} printf(" Intializing matrix data \n\n");
for (i = ; i < (m * k); i++) {
A[i] = (double)(i + );
} for (i = ; i < (k * n); i++) {
B[i] = (double)(-i - );
} for (i = ; i < (m * n); i++) {
C[i] = 0.0;
} printf(" Computing matrix product using Intel(R) MKL dgemm function via CBLAS interface \n\n");
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
m, n, k, alpha, A, k, B, n, beta, C, n);
printf("\n Computations completed.\n\n"); printf(" Top left corner of matrix A: \n");
for (i = ; i < min(m, ); i++) {
for (j = ; j < min(k, ); j++) {
printf("%12.0f", A[j + i * k]);
}
printf("\n");
} printf("\n Top left corner of matrix B: \n");
for (i = ; i < min(k, ); i++) {
for (j = ; j < min(n, ); j++) {
printf("%12.0f", B[j + i * n]);
}
printf("\n");
} printf("\n Top left corner of matrix C: \n");
for (i = ; i < min(m, ); i++) {
for (j = ; j < min(n, ); j++) {
printf("%12.5G", C[j + i * n]);
}
printf("\n");
} printf("\n Deallocating memory \n\n");
mkl_free(A);
mkl_free(B);
mkl_free(C); printf(" Example completed. \n\n"); system("PAUSE");
return ;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/588788.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存