1

I am a beginner in using PETSc and I am trying to develop a function to reverse a PETSc matrix. However, as I am using a mpiaij matrix, PETSc shows no support for this type.

[0]PETSC ERROR: No support for this operation for this object type
[0]PETSC ERROR: Mat type mpiaij

I've found a similar question in this answer but after downloading and configuring the SuperLU package, nothing works. I think we need to change the original MatLUFactor but no documentation in SuperLU is founded. I have tried by configuring PCFactorSetMatSolverType to SuperLU in PETSc but it doesn't work.

Thanks a lot for your help!

Here is my code:

void inv_PETSC_matrix(Mat& matrix,  Mat &inv_matrix)
{

  Mat             Ones;
  PetscInt        petsc_m=0, petsc_n=0,i,j;
  PetscErrorCode  ierr=0;
  PetscScalar     v = 1.0;
  ierr = MatGetSize(matrix, &petsc_m, &petsc_n);

    //Create a Ones matrix
  MatCreateSeqDense(PETSC_COMM_SELF,petsc_m,petsc_n,NULL,&Ones);
    //Create a Solution matrix
  MatCreateSeqDense(PETSC_COMM_SELF,petsc_m,petsc_n,NULL,&inv_matrix);

    //Factorisation LU
  MatLUFactor(matrix,NULL,NULL,NULL);

    //Affect value to the matrix Ones
  for(i = 0; i<petsc_m; i++)
    for(j=0; j<petsc_n; j++)
      MatSetValues(Ones,1,&i,1,&j,&v,INSERT_VALUES);

      //Inversion
  MatMatSolve(matrix, Ones, inv_matrix);
}
lcs_27
  • 11
  • 3
  • It's easiest to do this through commandline options:```yourprog -ksp_type preonly -pc_type lu -pc_factor_mat_solver_type superlu``` Btw, your statement "nothing works" is uninformative. Please give exact error messages or behavior. Does your program start at all? Then it hangs? Aborts with error? What? – Victor Eijkhout Oct 13 '21 at 16:08
  • Sorry for this late response. I've tried the method that you mentioned but the error remains the same(`No support for this operation for this object type Mat type mpiaij`). btw, this is the meaning of "nothing works" in my description——The bug reported is exactly the same(sorry for this unclear description). I am wondering if we need to change to another function of LUFactor in superlu ( is there a corresponding one?) as if we still use `MatLUFactor` it's still the function of mpiaij that will be used. Thanks a lot. – lcs_27 Oct 27 '21 at 19:37
  • Is there a separate solver type `superlu_dist`? – Victor Eijkhout Oct 27 '21 at 20:08
  • Yes, I've just found that our system didn't recognise the superlu that we have installed and we are trying to figure it out. Besides, I think we shouldn't use `MatLUFactor ` but we should use `PCFactorGetMatrix` instead. Thanks for the help anyway. – lcs_27 Oct 29 '21 at 07:50

0 Answers0