Intel MKL 在VS中的配置与安装笔记

Intel MKL 在VS中的配置与安装笔记

mkl 使用手册下载:http://download.csdn.net/detail/caoenze/8855821


  1. 从intel官网下载c_studio_xe_2013_sp1_update3_setup.exe文件(完全离线安装包)
  2. 双击.exe文件,自动提取文件并进入安装引导
  3. 安装完成后,配置VS2010(前提是本机已正确安装过VS2010)
  4. 新建一C++项目,比如win32控制台项目:MKL_TEST
  5. 点击菜单栏 项目——》MKL_TEST属性——》配置属性——》VC++目录:
    可执行文件目录添加:C:\Program Files (x86)\Intel\Composer XE\mkl\bin\ia32
    包含目录添加:C:\Program Files (x86)\Intel\Composer XE\mkl\include
    库目录添加:C:\Program Files (x86)\Intel\Composer XE\mkl\lib\ia32
    注意:包含目录不区分ia32和intel64
    Bin和lib目录区分ia32和intel64根据自己的CPU架构选择。
    IA32可以认为是X86或者X86-32
    Intel64:intel与HP联合开发的64-bits全新架构,与X86不兼容,没有太大市场。
    6 、连接器——》输入
    附加依赖项:添加
    mkl_intel_c.lib
    mkl_intel_thread.lib
    mkl_core.lib
    libiomp5mt.lib//我只添加了前三个,添加第4个,编译时提示找不到此库
    7、配置属性——Intel Performance Library
    右侧Use Intel MKL :
    选择Parallel
    其它两项可以选择性配置,不配置也可以。
    8、至此,VS2010调用MKL已配置完毕,可在MKL_TEST项目里添加源文件main.c 测试代码如下:
#define min(x,y) (((x) < (y)) ? (x) : (y))

#include 
#include 
#include "mkl.h"

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® MKL function dgemm, where A, B, and  C are matrices and \n"
            " alpha and beta are double precision scalars\n\n");

    m = 2000, k = 200, n = 1000;
    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 ), 64 );
    B = (double *)mkl_malloc( k*n*sizeof( double ), 64 );
    C = (double *)mkl_malloc( m*n*sizeof( double ), 64 );
    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 1;
    }

    printf (" Intializing matrix data \n\n");
    for (i = 0; i < (m*k); i++) {
        A[i] = (double)(i+1);
    }

    for (i = 0; i < (k*n); i++) {
        B[i] = (double)(-i-1);
    }

    for (i = 0; i < (m*n); i++) {
        C[i] = 0.0;
    }

    printf (" Computing matrix product using Intel® 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=0; im,6); i++) {
      for (j=0; j6); j++) {
        printf ("%12.0f", A[j+i*k]);
      }
      printf ("\n");
    }

    printf ("\n Top left corner of matrix B: \n");
    for (i=0; i6); i++) {
      for (j=0; j6); j++) {
        printf ("%12.0f", B[j+i*n]);
      }
      printf ("\n");
    }

    printf ("\n Top left corner of matrix C: \n");
    for (i=0; im,6); i++) {
      for (j=0; j6); j++) {
        printf ("%12.5G", C[j+i*n]);
      }
      printf ("\n");
    }

    getchar();
    printf ("\n Deallocating memory \n\n");
    mkl_free(A);
    mkl_free(B);
    mkl_free(C);

    printf (" Example completed. \n\n");
    return 0;
}

Intel MKL 在VS中的配置与安装笔记_第1张图片

你可能感兴趣的:(论文笔记)