在某些优化问题中,我必须使用intel mkl,因此在cygwin的Win7 64bit下测试以下标准代码,以确保我已正确设置它:
In [135]: res = np.empty((3,5), object)
In [136]: res
Out[136]:
array([[None, None, None, None, None],
[None, None, None, None, None],
[None, None, None, None, None]], dtype=object)
In [137]: res.flat[:11] = np.arange(1,12)
In [138]: res
Out[138]:
array([[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, None, None, None, None]], dtype=object)
为了进行编译,我首先必须链接MKL库,如文档的第3步所示: https://software.intel.com/en-us/articles/intel-math-kernel-library-intel-mkl-2018-getting-started
例如,在Windows下,我们已设置:
#define min(x,y) (((x) < (y)) ? (x) : (y))
#include <stdio.h>
#include <stdlib.h>
#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(R) 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(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=0; i<min(m,6); i++) {
for (j=0; j<min(k,6); j++) {
printf ("%12.0f", A[j+i*k]);
}
printf ("\n");
}
printf ("\n Top left corner of matrix B: \n");
for (i=0; i<min(k,6); i++) {
for (j=0; j<min(n,6); j++) {
printf ("%12.0f", B[j+i*n]);
}
printf ("\n");
}
printf ("\n Top left corner of matrix C: \n");
for (i=0; i<min(m,6); i++) {
for (j=0; j<min(n,6); 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");
return 0;
}
或在Linux下:
> ..\compilers_and_libraries_2018\windows\mkl\bin\mklvars.bat" ia32
> cl.exe mkl_lab_solution.c mkl_intel_c.lib mkl_core.lib mkl_intel_thread.lib libiomp5md.lib
但是我陷入了第一个命令行,即当我
1) if with gcc
$source /opt/intel/compilers_and_libraries_2018/linux/mkl/bin/mklvars.sh ia32
$gcc -m32 mkl_lab_solution.c -lmkl_intel -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm
它显示gcc -o temp temp.c -mkl
我知道这意味着我没有在第一个命令行中设置环境, 但是在谷歌搜索后现在不知道并尝试在Intel Parallel Studio XE 2018下进行编译。