Hello,
In C++, I need a function which enables the inversion on large matrixes (at the maximum, I need to inverse 120,000 x 120,000
size matrix).
I am trying with the workstation at work to perform this with LAPACKE
dgetri
and dgetrf
routines with Intel OneAPI
framework.
The workstation has 1TB of RAM and 2 GPU cards RTX A6000 of 48GB for each one.
Currently, the maximum that I can invert is roughly a matrix of 50,000 x 50,000
. Over this size, the 1TB RAM if full
and I get the following error :
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Command terminated by signal 6
Here the implemented function which inverses a matrix :
// Inversion Matrix : 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();
cout << "m = " << N << endl;
int *IPIV = new int[N];
// Statement of main array to inverse
double *arr = new double[N*N];
// Statement of returned matrix of size N
//vector<vector<double> > F_final(N, vector<double>(N));
// Output Diagonal block
double *diag = new double[N];
//#pragma omp parallel for num_threads(n_threads)
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);
//#pragma omp parallel for num_threads(n_threads)
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;
}
Is there a workaround with LAPACKE to be able to invert a 120,000 x 120,000
matrix without having a bad alloc
error, even if the RAM of workstation has 1TB?
PS: I have also tried to use MAGMA for GPU cards but I am also limited to 40,000 x 40,000
matrix size for one GPU. I couldn't have for the moment found a way to combine the powerful in the same time of both GPU.
EDIT :
Is there a way to pass by reference the F_matrix input variable as arguments for LAPACKE dgetrf
and degetri
? I remind that F_matrix has a type vector<vector<double>>
.
Thanks in advance for your help.
Best regards