如何在 Fortran 中使用(初始化、操作、获取输出)mkl 句柄?

How can I use (initialize, manipulate, get output from) mkl handles in Fortran?

我在 WSL 中使用 Intel Fortran 编译器,其安装目录为 /opt/intel。我想使用稀疏 BLAS 函数。 link to intel's documentation of the libaray.

这里是部分相关代码

double complex, allocatable ::  H(:,:),Hvert(:,:),Hstar(:,:)
allocate(H(dimH,dimH),Hvert(dimH,dimH),Hstar(dimH,dimH))

! initialization of Hstar
info = mkl_sparse_z_create_coo(Hstar, SPARSE_INDEX_BASE_ONE, m**L, m**L, 2**L, ind(1,:), ind(2,:), Hele)

! initialization of empty matrix
ind = 0
info = mkl_sparse_z_create_coo(Hvert, SPARSE_INDEX_BASE_ONE, m**L, m**L, 0, ind(1,1), ind(2,1), H)

! add A and B to form the final matrix
info = mkl_sparse_z_add(SPARSE_OPERATION_NON_TRANSPOSE, Hstar, 1d0, Hvert, H)

当我用下面的命令编译它时

ifort -xHost -parallel full.f90 -o output -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_spblas -lmkl_core -liomp5 -lpthread -lm -qopenmp && ./output

它给了我以下错误,即使我已经找到了库

source /opt/intel/bin/ifortvars.sh -arch intel64 -platform linux
source /opt/intel/bin/compilervars.sh -arch intel64 -platform linux
full.f90(146): error #6404: This name does not have a type, and must have an explicit type.   [MKL_SPARSE_Z_CREATE_COO]
     info = mkl_sparse_z_create_coo(Hvert, SPARSE_INDEX_BASE_ONE, m**L, m**L, 2**L, ind(1,:), ind(2,:), Hele)
------------^
full.f90(226): error #6404: This name does not have a type, and must have an explicit type.   [MKL_SPARSE_Z_ADD]
     info = mkl_sparse_z_add(SPARSE_OPERATION_NON_TRANSPOSE, Hstar, 1d0, Hvert, H)
------------^
full.f90(240): error #6404: This name does not have a type, and must have an explicit type.   [MKL_SPARSE_Z_MV]
       info = mkl_sparse_z_mv(SPARSE_OPERATION_NON_TRANSPOSE, 1d0, H, SPARSE_MATRIX_TYPE_HERMITIAN, psi(a,:), 0d0, dummy)
--------------^
compilation aborted for full.f90 (code 1)

我认为这是由于我错误地链接到相关库以及将矩阵初始化为普通可分配数组造成的。

我应该如何使用这些功能?

另外,我不知道大写变量SPARSE_INDEX_BASE_ONE是什么意思。我应该那样使用它吗?

linking 路径是正确的。您不需要 link -mkl_spblas。请始终参考 MKL 链接器顾问 (https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor)。 我建议查看现有的 sparse_z_csrmv.f90 示例,该示例显示了如何调用类似的 Sparse BLAS 函数。此示例已调用 CSR 而不是 COO 格式,但在这种情况下无关紧要。