1. 软件版本信息
Windows 10
Visual Studio 2015 Professional
Intel MKL
2. 软件来源链接
Intel MKL下载链接:
方式 1:直接进入Intel Software官网,进行注册后下载Intel Math Kernel Library(MKL) Package.
下载链接:https://software.intel.com/en-us/performance-libraries
方式 2:点击进入网盘分享链接。
下载链接:https://pan.baidu.com/s/16RZsLyJawUrRkYis3HuemA
密码:9w7s
下载链接:https://pan.baidu.com/s/1ucrENxyEHsbjRWQSbquQqg
密码:fnna
3. 程序代码
3.1 图片形式
3.2 代码形式
代码主要源于Intel MKL Package - Examples.
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "mkl.h"
#include "mkl_dss.h"
#include "mkl_types.h"
/*
** Define the array and rhs vectors
*/
#define NROWS 5
#define NCOLS 5
#define NNONZEROS 9
#define NRHS 1
static const MKL_INT nRows = NROWS;
static const MKL_INT nCols = NCOLS;
static const MKL_INT nNonZeros = NNONZEROS;
static const MKL_INT nRhs = NRHS;
static MKL_INT rowIndex[NROWS + 1] = { 1, 3, 5, 7, 9, 10 };
static MKL_INT columns[NNONZEROS] = { 1, 2, 1, 2, 3, 4, 3, 4, 5 };
static double values[NNONZEROS] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
static _DOUBLE_PRECISION_t rhs[NCOLS * 2];
static _DOUBLE_PRECISION_t solValues[NROWS] = { 0, 1, 2, 3, 4 };
MKL_INT
main()
{
MKL_INT i, j;
/* Allocate storage for the solver handle and the right-hand side. */
_MKL_DSS_HANDLE_t handle;
_INTEGER_t error;
_CHARACTER_t statIn[] = "determinant";
_CHARACTER_t *uplo = "initialize";
_DOUBLE_PRECISION_t statOut[5], eps = 1e-6;
MKL_INT opt = MKL_DSS_DEFAULTS, opt1;
MKL_INT sym = MKL_DSS_NON_SYMMETRIC;
MKL_INT type = MKL_DSS_INDEFINITE;
/* --------------------- */
/* Initialize the solver */
/* --------------------- */
error = dss_create(handle, opt);
if (error != MKL_DSS_SUCCESS)
goto printError;
/* ------------------------------------------- */
/* Define the non-zero structure of the matrix */
/* ------------------------------------------- */
error = dss_define_structure(handle, sym, rowIndex, nRows, nCols, columns, nNonZeros);
if (error != MKL_DSS_SUCCESS)
goto printError;
/* ------------------ */
/* Reorder the matrix */
/* ------------------ */
error = dss_reorder(handle, opt, 0);
if (error != MKL_DSS_SUCCESS)
goto printError;
/* ------------------ */
/* Factor the matrix */
/* ------------------ */
error = dss_factor_real(handle, type, values);
if (error != MKL_DSS_SUCCESS)
goto printError;
/* ------------------------ */
/* Get the solution vector for Ax=b and ATx=b and check correctness */
/* ------------------------ */
for (i = 0; i < 3; i++)
{
if (i == 0)
{
uplo = "non-transposed";
opt1 = MKL_DSS_DEFAULTS;
}
else if (i == 1)
{
uplo = "transposed";
opt1 = MKL_DSS_TRANSPOSE_SOLVE;
}
else
// Conjugate transposed == transposed for real matrices
if (i == 2)
{
uplo = "conjugate transposed";
opt1 = MKL_DSS_CONJUGATE_SOLVE;
}
printf("\nSolving %s system...\n", uplo);
// Compute rhs respectively to uplo to have solution solValue
mkl_dcsrgemv(uplo, &nRows, values, rowIndex, columns, solValues, rhs);
// Nullify solution on entry (for sure)
for (j = 0; j < nCols; j++)
solValues[j] = 0.0;
// Apply trans or non-trans option, solve system
opt |= opt1;
error = dss_solve_real(handle, opt, rhs, nRhs, solValues);
if (error != MKL_DSS_SUCCESS)
goto printError;
opt &= ~opt1;
// Check solution vector: should be {0,1,2,3,4}
for (j = 0; j < nCols; j++)
{
if ((solValues[j] > j + eps) || (solValues[j] < j - eps))
{
printf("Incorrect solution\n");
error = 1000 + i;
goto printError;
}
}
printf("Print solution array: ");
for (j = 0; j < nCols; j++)
printf(" %g", solValues[j]);
printf("\n");
}
/* -------------------------- */
/* Deallocate solver storage */
/* -------------------------- */
error = dss_delete(handle, opt);
if (error != MKL_DSS_SUCCESS)
goto printError;
/* ---------------------- */
/* Print solution vector */
/* ---------------------- */
printf("\nExample successfully PASSED!\n");
getchar();
exit(0);
printError:
printf("Solver returned error code %d\n", error);
exit(1);
}
3.3 编译参数设置
因需采用C++语言调用Intel MKL包,所以需正确加载MKL的相关库文件和引用目录等文件。所需文件目录一览如下:
所需文件位置:
项目工程文件路径设置:
4. 结果显示
5. 重要链接
https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/index.htm
https://software.intel.com/en-us/mkl/documentation/code-samples
转:https://blog.csdn.net/santorinisu/article/details/80274112
来源:CSDN
作者:Allure_Allure
链接:https://blog.csdn.net/Allure392491308/article/details/104124917