0

我需要对大型矩阵进行逆运算,并且我想修改我当前的 LAPACKE 版本例程,以利用 GPU NVIDIA 卡的强大功能。

事实上,我的 LAPACKE 例程适用于相对较小的矩阵,但不适用于大型矩阵。

下面这个 LAPACKE 例程的实现:

 #include <mkl.h>

// Passing Matrixes by Reference
void matrix_inverse_lapack(vector<vector<double>> const &F_matrix, vector<vector<double>> &F_output) {

  // Index for loop and arrays
  int i, j, ip, idx;

  // Size of F_matrix
  int N = F_matrix.size();

  int *IPIV = new int[N];

 // Output Diagonal block
  double *diag = new double[N];

  for (i = 0; i<N; i++){
    for (j = 0; j<N; j++){
      idx = i*N + j;
      arr[idx] = F_matrix[i][j];
    }
  }

  // LAPACKE routines
  int info1 = LAPACKE_dgetrf(LAPACK_ROW_MAJOR, N, N, arr, N, IPIV);
  int info2 = LAPACKE_dgetri(LAPACK_ROW_MAJOR, N, arr, N, IPIV);

 for (i = 0; i<N; i++){
    for (j = 0; j<N; j++){
      idx = i*N + j;
      F_output[i][j] = arr[idx];
    }
  }

  delete[] IPIV;
  delete[] arr;
}

with 被称为逆 CO_CL 矩阵:

matrix_inverse_lapack(CO_CL, CO_CL);

CO_CL 定义为:

vector<vector<double>> CO_CL(lsize*(2*Dim_x+Dim_y), vector<double>(lsize*(2*Dim_x+Dim_y), 0));

在我的情况下,如何使用 MAGMA for NVIDIA 来求逆矩阵,而不是使用 LAPACKE?

更新 1:我已经下载magma-2.6.1,首先,我必须修改原始 Makefile :

CXX = icpc -std=c++11 -O3 -xHost
CXXFLAGS = -Wall -c -I${MKLROOT}/include -I/opt/intel/oneapi/compiler/latest/linux/compiler/include -qopenmp -qmkl=parallel
LDFLAGS = -L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/../compiler/lib -qopenmp -qmkl
SOURCES = main_intel.cpp XSAF_C_intel.cpp
EXECUTABLE = main_intel.exe

我没有在:中看到mkl标题并且兼容?magma-2.6.1nvccMKL

4

1 回答 1

1

尝试 magma sgetri gpu在单精度、GPU 接口中使用 - 逆矩阵。此函数以单精度计算 m × m 矩阵 A 的逆 A^−1。

magma_ssetmatrix ( m, m, a,m, d_a ,m, queue ); // copy a -> d_a
magmablas_slacpy ( MagmaFull ,m,m,d_a ,m,d_r ,m, queue ); // d_a - >d_r
// find the inverse matrix : d_a *X=I using the LU factorization
// with partial pivoting and row interchanges computed by
// magma_sgetrf_gpu ; row i is interchanged with row piv (i);
// d_a -mxm matrix ; d_a is overwritten by the inverse
gpu_time = magma_sync_wtime ( NULL );
magma sgetrf gpu( m, m, d a, m, piv, &info);
magma sgetri gpu(m,d a,m,piv,dwork,ldwork,&info);

英伟达的官方文档里有很多例子,大家也可以看看:

于 2021-08-26T04:44:08.497 回答