Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory allocation failed in SuperLU_MT? #9

Open
SalmanMaths opened this issue Mar 2, 2023 · 8 comments
Open

Memory allocation failed in SuperLU_MT? #9

SalmanMaths opened this issue Mar 2, 2023 · 8 comments

Comments

@SalmanMaths
Copy link

I am using the SuperLU_MT and the code from pdrepeat.c (https://github.com/xiaoyeli/superlu_mt/blob/master/EXAMPLE/pdrepeat.c). In this code the function dreadhb(&m, &n, &nnz, &a, &asub, &xa); is used. My matrix format is CRS and transform it into CCS by dCompRow_to_CompCol(m, n, nnz,
const_cast<double*>(_sk.data()), const_cast<int_t*>(_ik.data()), const_cast<int_t*>(_id.data()),
&a, &asub, &xa);
And then use the dCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_D, SLU_GE); to create the Supermatrix A.

When I run the code, it gives me the following error:

** On entry to sp_ienv, parameter number 1 had an illegal value Storage for L subscripts exceeded; Current column 0; Need at least 72; You may set it by the 8-th parameter in routine sp_ienv(). Memory allocation failed at line 222 in file pmemory.c

Any suggestions about this to handle the error?

@xiaoyeli
Copy link
Owner

xiaoyeli commented Mar 3, 2023

It's difficult to tell what went wrong. You will need to do some debugging, for example, by printing out some info at various places of the source code.

@SalmanMaths
Copy link
Author

SalmanMaths commented Mar 4, 2023

The problem occurred to me at the position/function ( LU factorization of A):
/* ------------------------------------------------------------
Compute the LU factorization of A.
The following routine will create nprocs threads.
------------------------------------------------------------*/
pdgstrf(&superlumt_options, &AC, perm_r, &L, &U, &Gstat, &info);

@SalmanMaths
Copy link
Author

SalmanMaths commented Mar 4, 2023

It is must, to use the dreadhb(&m, &n, &nnz, &a, &asub, &xa)? instead of it, I use the following (it works in SuperLU):

// Initialize matrix A.
m = n = f.size();//f.size is the number of rows of the matrix
nnz = _sk.size();
if ( !(a = doubleMalloc(nnz)) ) SUPERLU_ABORT("Malloc fails for a[].");
if ( !(asub = intMalloc(nnz)) ) SUPERLU_ABORT("Malloc fails for asub[].");
if ( !(xa = intMalloc(n+1)) ) SUPERLU_ABORT("Malloc fails for xa[].");
dCompRow_to_CompCol(m, n, nnz,
const_cast<double*>(_sk.data()), const_cast<int_t*>(_ik.data()), const_cast<int_t*>(_id.data()),
&a, &asub, &xa);
/* Set up the sparse matrix data structure for A. */
dCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_D, SLU_GE);

@xiaoyeli
Copy link
Owner

xiaoyeli commented Mar 4, 2023

I don't see anything wrong in your matrix setup routine. I suggest you go into the SuperLU source code, do some printing at various places, see whether your input matrix is correct.
In SRC/pdutil.c, therre are a number of printing functions, such as: dPrint_CompCol_Matrix(), etc.

@SalmanMaths
Copy link
Author

SalmanMaths commented Mar 5, 2023

fp.txt
I did this and printed the CCS matrix in the attached file.

@SalmanMaths
Copy link
Author

SalmanMaths commented Mar 6, 2023

Dear Sherry Li,
Thank you so much for your support. I think my problem is from the not correct reading of matrix structure. Now I am going to save my matrix in a .hb file then I will call from dreadhb() function. So I hope it will work.

But I need your help to define the .hb file correctly. I defined it below but it is not working. Please help me in this (Particularly in the first two lines:
fprintf(fp,"CompCol matrix %s\n", what);
//fprintf(fp,"Stype %d, Dtype %d, Mtype %d\n", A->Stype,A->Dtype,A->Mtype);
n = A->ncol;
Astore = (NCformat *) A->Store;
dp = (double *) Astore->nzval;
fprintf(fp,"RUA");
fprintf(fp," %d %d %d ", A->nrow,A->ncol,Astore->nnz);//nrow, ncol, a, asub, xa,
fprintf(fp,"0\n");):

`template
void FEM_Matrix_2::Save_Matrix(std::vector const &f) const
{
SuperMatrix A1;
SuperMatrix *A;
double *a;
int *asub, *xa;
int m, n1, nnz;
NCformat *Astore;
int i,n;
double dp;
char what;
FILE fp;
// // Initialize matrix A.
m = n1 = f.size(); // number of rows of square matrix.
nnz = _sk.size();
if ( !(a = doubleMalloc(nnz)) ) SUPERLU_ABORT("Malloc fails for a[].");
if ( !(asub = intMalloc(nnz)) ) SUPERLU_ABORT("Malloc fails for asub[].");
if ( !(xa = intMalloc(n1+1)) ) SUPERLU_ABORT("Malloc fails for xa[].");
dCompRow_to_CompCol(m, n1, nnz,
const_cast<double
>(_sk.data()), const_cast<int_t
>(_ik.data()), const_cast<int_t
>(_id.data()),
&a, &asub, &xa);

// Create matrix A in the format expected by SuperLU. 
dCreate_CompCol_Matrix(&A1, m, n1, nnz, a, asub, xa, SLU_NC, SLU_D, SLU_GE);
A = &A1;
fp = fopen("./SRC/fp.hb","w");
fprintf(fp,"CompCol matrix %s\n", what);
//fprintf(fp,"Stype %d, Dtype %d, Mtype %d\n", A->Stype,A->Dtype,A->Mtype);
n = A->ncol;
Astore = (NCformat *) A->Store;
dp = (double *) Astore->nzval;
fprintf(fp,"RUA");
fprintf(fp," %d %d  %d ", A->nrow,A->ncol,Astore->nnz);//nrow, ncol, a, asub, xa,
fprintf(fp,"0\n");
//fprintf(fp,"\nxa: ");//
for (i = 0; i <= n; ++i){
fprintf(fp,"%d  ", Astore->colptr[i]);
}
fprintf(fp,"\n");
//fprintf(fp,"\nasub: ");//
for (i = 0; i < Astore->colptr[n]; ++i){
fprintf(fp,"%d  ", Astore->rowind[i]);
}
fprintf(fp,"\n");
//fprintf(fp,"\na: ");//
for (i = 0; i < Astore->colptr[n]; ++i){ 
fprintf(fp,"%f  ", dp[i]);
}
fprintf(fp,"\n");
fclose(fp);
return;	

}`

@SalmanMaths
Copy link
Author

fp.hb.zip
Dear Sherry Li,

I am using the matrix in the attachment but give me the Segmentation fault (core dumped) at dreadhb().
What is wrong in the matrix or it is the code problem?

@SalmanMaths
Copy link
Author

fp.zip

Dear Sherry Li,

I also try in this way but still segmentation fault.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants