xref: /petsc/src/mat/impls/aij/mpi/strumpack/strumpack.c (revision 1d27aa22b2f6148b2c4e3f06a75e0638d6493e09)
148f88336SPieter Ghysels #include <../src/mat/impls/aij/seq/aij.h> /*I "petscmat.h" I*/
27d6ea485SPieter Ghysels #include <../src/mat/impls/aij/mpi/mpiaij.h>
37d6ea485SPieter Ghysels #include <StrumpackSparseSolver.h>
47d6ea485SPieter Ghysels 
5d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatGetDiagonal_STRUMPACK(Mat A, Vec v)
6d71ae5a4SJacob Faibussowitsch {
77d6ea485SPieter Ghysels   PetscFunctionBegin;
87d6ea485SPieter Ghysels   SETERRQ(PetscObjectComm((PetscObject)A), PETSC_ERR_SUP, "Mat type: STRUMPACK factor");
93ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
107d6ea485SPieter Ghysels }
117d6ea485SPieter Ghysels 
12d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatDestroy_STRUMPACK(Mat A)
13d71ae5a4SJacob Faibussowitsch {
1435e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)A->data;
157d6ea485SPieter Ghysels 
167d6ea485SPieter Ghysels   PetscFunctionBegin;
177d6ea485SPieter Ghysels   /* Deallocate STRUMPACK storage */
18e77caa6dSBarry Smith   PetscStackCallExternalVoid("STRUMPACK_destroy", STRUMPACK_destroy(S));
1935e8bcc9SJunchao Zhang   PetscCall(PetscFree(A->data));
20575704cbSPieter Ghysels 
21575704cbSPieter Ghysels   /* clear composed functions */
229566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatFactorGetSolverType_C", NULL));
239566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetReordering_C", NULL));
2429e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetReordering_C", NULL));
259566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetColPerm_C", NULL));
2629e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetColPerm_C", NULL));
2729e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetGeometricNxyz_C", NULL));
2829e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetGeometricComponents_C", NULL));
2929e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetGeometricWidth_C", NULL));
3029e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetGPU_C", NULL));
3129e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetGPU_C", NULL));
3229e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompression_C", NULL));
3329e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompression_C", NULL));
3429e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompRelTol_C", NULL));
3529e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompRelTol_C", NULL));
3629e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompAbsTol_C", NULL));
3729e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompAbsTol_C", NULL));
3829e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompMaxRank_C", NULL));
3929e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompMaxRank_C", NULL));
4029e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompLeafSize_C", NULL));
4129e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompLeafSize_C", NULL));
4229e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompMinSepSize_C", NULL));
4329e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompMinSepSize_C", NULL));
4429e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompLossyPrecision_C", NULL));
4529e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompLossyPrecision_C", NULL));
4629e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKSetCompButterflyLevels_C", NULL));
4729e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatSTRUMPACKGetCompButterflyLevels_C", NULL));
48575704cbSPieter Ghysels 
493ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
50575704cbSPieter Ghysels }
51575704cbSPieter Ghysels 
52d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatSTRUMPACKSetReordering_STRUMPACK(Mat F, MatSTRUMPACKReordering reordering)
53d71ae5a4SJacob Faibussowitsch {
5435e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
55575704cbSPieter Ghysels 
56575704cbSPieter Ghysels   PetscFunctionBegin;
5729e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_reordering_method", STRUMPACK_set_reordering_method(*S, (STRUMPACK_REORDERING_STRATEGY)reordering));
5829e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
5929e0a805SPieter Ghysels }
6029e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetReordering_STRUMPACK(Mat F, MatSTRUMPACKReordering *reordering)
6129e0a805SPieter Ghysels {
6229e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
6329e0a805SPieter Ghysels 
6429e0a805SPieter Ghysels   PetscFunctionBegin;
6529e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_reordering_method", *reordering = (MatSTRUMPACKReordering)STRUMPACK_reordering_method(*S));
663ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
6734f43fa5SPieter Ghysels }
68e5a36eccSStefano Zampini 
69542aee0fSPieter Ghysels /*@
70*1d27aa22SBarry Smith   MatSTRUMPACKSetReordering - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> fill-reducing reordering
7134f43fa5SPieter Ghysels 
7229e0a805SPieter Ghysels   Logically Collective
7329e0a805SPieter Ghysels 
7434f43fa5SPieter Ghysels   Input Parameters:
7529e0a805SPieter Ghysels + F          - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
7629e0a805SPieter Ghysels - reordering - the code to be used to find the fill-reducing reordering
7734f43fa5SPieter Ghysels 
7811a5261eSBarry Smith   Options Database Key:
792ef1f0ffSBarry Smith . -mat_strumpack_reordering <METIS> - Sparsity reducing matrix reordering, see `MatSTRUMPACKReordering`
8034f43fa5SPieter Ghysels 
8129e0a805SPieter Ghysels   Level: intermediate
8234f43fa5SPieter Ghysels 
83*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatSTRUMPACKReordering`, `MatGetFactor()`, `MatSTRUMPACKSetColPerm()`, `MatSTRUMPACKGetReordering()`
84542aee0fSPieter Ghysels @*/
85d71ae5a4SJacob Faibussowitsch PetscErrorCode MatSTRUMPACKSetReordering(Mat F, MatSTRUMPACKReordering reordering)
86d71ae5a4SJacob Faibussowitsch {
8734f43fa5SPieter Ghysels   PetscFunctionBegin;
8834f43fa5SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
8934f43fa5SPieter Ghysels   PetscValidLogicalCollectiveEnum(F, reordering, 2);
90cac4c232SBarry Smith   PetscTryMethod(F, "MatSTRUMPACKSetReordering_C", (Mat, MatSTRUMPACKReordering), (F, reordering));
913ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
92575704cbSPieter Ghysels }
9329e0a805SPieter Ghysels /*@
94*1d27aa22SBarry Smith   MatSTRUMPACKGetReordering - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> fill-reducing reordering
9529e0a805SPieter Ghysels 
9629e0a805SPieter Ghysels   Logically Collective
9729e0a805SPieter Ghysels 
9829e0a805SPieter Ghysels   Input Parameters:
9929e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
10029e0a805SPieter Ghysels 
10129e0a805SPieter Ghysels   Output Parameter:
10229e0a805SPieter Ghysels . reordering - the code to be used to find the fill-reducing reordering
10329e0a805SPieter Ghysels 
10429e0a805SPieter Ghysels   Level: intermediate
10529e0a805SPieter Ghysels 
106*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatSTRUMPACKReordering`, `MatGetFactor()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKSetColPerm()`
10729e0a805SPieter Ghysels @*/
10829e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetReordering(Mat F, MatSTRUMPACKReordering *reordering)
10929e0a805SPieter Ghysels {
11029e0a805SPieter Ghysels   PetscFunctionBegin;
11129e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
11229e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetReordering_C", (Mat, MatSTRUMPACKReordering *), (F, reordering));
11329e0a805SPieter Ghysels   PetscValidLogicalCollectiveEnum(F, *reordering, 2);
11429e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
11529e0a805SPieter Ghysels }
116575704cbSPieter Ghysels 
117d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatSTRUMPACKSetColPerm_STRUMPACK(Mat F, PetscBool cperm)
118d71ae5a4SJacob Faibussowitsch {
11935e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
12034f43fa5SPieter Ghysels 
12134f43fa5SPieter Ghysels   PetscFunctionBegin;
12229e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_matching", STRUMPACK_set_matching(*S, cperm ? STRUMPACK_MATCHING_MAX_DIAGONAL_PRODUCT_SCALING : STRUMPACK_MATCHING_NONE));
12329e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
12429e0a805SPieter Ghysels }
12529e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetColPerm_STRUMPACK(Mat F, PetscBool *cperm)
12629e0a805SPieter Ghysels {
12729e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
12829e0a805SPieter Ghysels 
12929e0a805SPieter Ghysels   PetscFunctionBegin;
13029e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_matching", *cperm = (PetscBool)(STRUMPACK_matching(*S) != STRUMPACK_MATCHING_NONE));
1313ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
13234f43fa5SPieter Ghysels }
133e5a36eccSStefano Zampini 
134575704cbSPieter Ghysels /*@
135*1d27aa22SBarry Smith   MatSTRUMPACKSetColPerm - Set whether STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>
136*1d27aa22SBarry Smith   should try to permute the columns of the matrix in order to get a nonzero diagonal
137147403d9SBarry Smith 
138c3339decSBarry Smith   Logically Collective
139575704cbSPieter Ghysels 
140575704cbSPieter Ghysels   Input Parameters:
1412ef1f0ffSBarry Smith + F     - the factored matrix obtained by calling `MatGetFactor()`
14211a5261eSBarry Smith - cperm - `PETSC_TRUE` to permute (internally) the columns of the matrix
143575704cbSPieter Ghysels 
14411a5261eSBarry Smith   Options Database Key:
145147403d9SBarry Smith . -mat_strumpack_colperm <cperm> - true to use the permutation
146575704cbSPieter Ghysels 
14729e0a805SPieter Ghysels   Level: intermediate
148575704cbSPieter Ghysels 
149*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `MatSTRUMPACKSetReordering()`, `Mat`, `MatGetFactor()`, `MatSTRUMPACKGetColPerm()`
150575704cbSPieter Ghysels @*/
151d71ae5a4SJacob Faibussowitsch PetscErrorCode MatSTRUMPACKSetColPerm(Mat F, PetscBool cperm)
152d71ae5a4SJacob Faibussowitsch {
153575704cbSPieter Ghysels   PetscFunctionBegin;
154575704cbSPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
15534f43fa5SPieter Ghysels   PetscValidLogicalCollectiveBool(F, cperm, 2);
156cac4c232SBarry Smith   PetscTryMethod(F, "MatSTRUMPACKSetColPerm_C", (Mat, PetscBool), (F, cperm));
1573ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
158575704cbSPieter Ghysels }
15929e0a805SPieter Ghysels /*@
160*1d27aa22SBarry Smith   MatSTRUMPACKGetColPerm - Get whether STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>
161*1d27aa22SBarry Smith   will try to permute the columns of the matrix in order to get a nonzero diagonal
162575704cbSPieter Ghysels 
16329e0a805SPieter Ghysels   Logically Collective
16429e0a805SPieter Ghysels 
16529e0a805SPieter Ghysels   Input Parameters:
16629e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()`
16729e0a805SPieter Ghysels 
16829e0a805SPieter Ghysels   Output Parameter:
16929e0a805SPieter Ghysels . cperm - Indicates whether STRUMPACK will permute columns
17029e0a805SPieter Ghysels 
17129e0a805SPieter Ghysels   Level: intermediate
17229e0a805SPieter Ghysels 
173*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `MatSTRUMPACKSetReordering()`, `Mat`, `MatGetFactor()`, `MatSTRUMPACKSetColPerm()`
17429e0a805SPieter Ghysels @*/
17529e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetColPerm(Mat F, PetscBool *cperm)
17629e0a805SPieter Ghysels {
17729e0a805SPieter Ghysels   PetscFunctionBegin;
17829e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
17929e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetColPerm_C", (Mat, PetscBool *), (F, cperm));
18029e0a805SPieter Ghysels   PetscValidLogicalCollectiveBool(F, *cperm, 2);
18129e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
18229e0a805SPieter Ghysels }
18329e0a805SPieter Ghysels 
18429e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetGPU_STRUMPACK(Mat F, PetscBool gpu)
185d71ae5a4SJacob Faibussowitsch {
18635e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
18734f43fa5SPieter Ghysels 
18834f43fa5SPieter Ghysels   PetscFunctionBegin;
18929e0a805SPieter Ghysels   if (gpu) {
19029e0a805SPieter Ghysels #if !(defined(STRUMPACK_USE_CUDA) || defined(STRUMPACK_USE_HIP) || defined(STRUMPACK_USE_SYCL))
19129e0a805SPieter Ghysels     PetscCall(PetscPrintf(PETSC_COMM_SELF, "  Warning: strumpack was not configured with GPU support\n"));
19229e0a805SPieter Ghysels #endif
19329e0a805SPieter Ghysels     PetscStackCallExternalVoid("STRUMPACK_enable_gpu", STRUMPACK_enable_gpu(*S));
19429e0a805SPieter Ghysels   } else PetscStackCallExternalVoid("STRUMPACK_disable_gpu", STRUMPACK_disable_gpu(*S));
19529e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
19629e0a805SPieter Ghysels }
19729e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetGPU_STRUMPACK(Mat F, PetscBool *gpu)
19829e0a805SPieter Ghysels {
19929e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
20029e0a805SPieter Ghysels 
20129e0a805SPieter Ghysels   PetscFunctionBegin;
20229e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_use_gpu", *gpu = (PetscBool)STRUMPACK_use_gpu(*S));
2033ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
20434f43fa5SPieter Ghysels }
205e5a36eccSStefano Zampini 
20634f43fa5SPieter Ghysels /*@
207*1d27aa22SBarry Smith   MatSTRUMPACKSetGPU - Set whether STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>
208*1d27aa22SBarry Smith   should enable GPU acceleration (not supported for all compression types)
20929e0a805SPieter Ghysels 
21029e0a805SPieter Ghysels   Logically Collective
21129e0a805SPieter Ghysels 
21229e0a805SPieter Ghysels   Input Parameters:
21329e0a805SPieter Ghysels + F   - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
21429e0a805SPieter Ghysels - gpu - whether or not to use GPU acceleration
21529e0a805SPieter Ghysels 
21629e0a805SPieter Ghysels   Options Database Key:
21729e0a805SPieter Ghysels . -mat_strumpack_gpu <gpu> - true to use gpu offload
21829e0a805SPieter Ghysels 
21929e0a805SPieter Ghysels   Level: intermediate
22029e0a805SPieter Ghysels 
221*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKGetGPU()`
22229e0a805SPieter Ghysels @*/
22329e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetGPU(Mat F, PetscBool gpu)
22429e0a805SPieter Ghysels {
22529e0a805SPieter Ghysels   PetscFunctionBegin;
22629e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
22729e0a805SPieter Ghysels   PetscValidLogicalCollectiveBool(F, gpu, 2);
22829e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetGPU_C", (Mat, PetscBool), (F, gpu));
22929e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
23029e0a805SPieter Ghysels }
23129e0a805SPieter Ghysels /*@
232*1d27aa22SBarry Smith   MatSTRUMPACKGetGPU - Get whether STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>
233*1d27aa22SBarry Smith   will try to use GPU acceleration (not supported for all compression types)
23429e0a805SPieter Ghysels 
23529e0a805SPieter Ghysels   Logically Collective
23629e0a805SPieter Ghysels 
23729e0a805SPieter Ghysels   Input Parameters:
23829e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
23929e0a805SPieter Ghysels 
24029e0a805SPieter Ghysels   Output Parameter:
24129e0a805SPieter Ghysels . gpu - whether or not STRUMPACK will try to use GPU acceleration
24229e0a805SPieter Ghysels 
24329e0a805SPieter Ghysels   Level: intermediate
24429e0a805SPieter Ghysels 
245*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetGPU()`
24629e0a805SPieter Ghysels @*/
24729e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetGPU(Mat F, PetscBool *gpu)
24829e0a805SPieter Ghysels {
24929e0a805SPieter Ghysels   PetscFunctionBegin;
25029e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
25129e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetGPU_C", (Mat, PetscBool *), (F, gpu));
25229e0a805SPieter Ghysels   PetscValidLogicalCollectiveBool(F, *gpu, 2);
25329e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
25429e0a805SPieter Ghysels }
25529e0a805SPieter Ghysels 
25629e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetCompression_STRUMPACK(Mat F, MatSTRUMPACKCompressionType comp)
25729e0a805SPieter Ghysels {
25829e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
25929e0a805SPieter Ghysels 
26029e0a805SPieter Ghysels   PetscFunctionBegin;
261c2935fbeSBarry Smith #if !defined(STRUMPACK_USE_BPACK)
26229e0a805SPieter Ghysels   PetscCheck(comp != MAT_STRUMPACK_COMPRESSION_TYPE_HODLR && comp != MAT_STRUMPACK_COMPRESSION_TYPE_BLR_HODLR && comp != MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR, PetscObjectComm((PetscObject)F), PETSC_ERR_SUP, "Compression scheme requires ButterflyPACK, please reconfigure with --download-butterflypack");
26329e0a805SPieter Ghysels #endif
264c2935fbeSBarry Smith #if !defined(STRUMPACK_USE_ZFP)
26529e0a805SPieter Ghysels   PetscCheck(comp != MAT_STRUMPACK_COMPRESSION_TYPE_ZFP_BLR_HODLR && comp != MAT_STRUMPACK_COMPRESSION_TYPE_LOSSLESS && comp != MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY, PetscObjectComm((PetscObject)F), PETSC_ERR_SUP, "Compression scheme requires ZFP, please reconfigure with --download-zfp");
26629e0a805SPieter Ghysels #endif
26729e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_compression", STRUMPACK_set_compression(*S, (STRUMPACK_COMPRESSION_TYPE)comp));
26829e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
26929e0a805SPieter Ghysels }
27029e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetCompression_STRUMPACK(Mat F, MatSTRUMPACKCompressionType *comp)
27129e0a805SPieter Ghysels {
27229e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
27329e0a805SPieter Ghysels 
27429e0a805SPieter Ghysels   PetscFunctionBegin;
27529e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression", *comp = (MatSTRUMPACKCompressionType)STRUMPACK_compression(*S));
27629e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
27729e0a805SPieter Ghysels }
27829e0a805SPieter Ghysels 
27929e0a805SPieter Ghysels /*@
280*1d27aa22SBarry Smith   MatSTRUMPACKSetCompression - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> compression type
28129e0a805SPieter Ghysels 
28229e0a805SPieter Ghysels   Input Parameters:
28329e0a805SPieter Ghysels + F    - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
28429e0a805SPieter Ghysels - comp - Type of compression to be used in the approximate sparse factorization
28529e0a805SPieter Ghysels 
28629e0a805SPieter Ghysels   Options Database Key:
28729e0a805SPieter Ghysels . -mat_strumpack_compression <NONE> - Type of rank-structured compression in sparse LU factors (choose one of) NONE HSS BLR HODLR BLR_HODLR ZFP_BLR_HODLR LOSSLESS LOSSY
28829e0a805SPieter Ghysels 
28929e0a805SPieter Ghysels   Level: intermediate
29029e0a805SPieter Ghysels 
291*1d27aa22SBarry Smith   Note:
29229e0a805SPieter Ghysels   Default for `comp` is `MAT_STRUMPACK_COMPRESSION_TYPE_NONE` for `-pc_type lu` and `MAT_STRUMPACK_COMPRESSION_TYPE_BLR`
29329e0a805SPieter Ghysels   for `-pc_type ilu`
29429e0a805SPieter Ghysels 
295*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKCompressionType`, `MatSTRUMPACKGetCompression()`
29629e0a805SPieter Ghysels @*/
29729e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetCompression(Mat F, MatSTRUMPACKCompressionType comp)
29829e0a805SPieter Ghysels {
29929e0a805SPieter Ghysels   PetscFunctionBegin;
30029e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
30129e0a805SPieter Ghysels   PetscValidLogicalCollectiveEnum(F, comp, 2);
30229e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetCompression_C", (Mat, MatSTRUMPACKCompressionType), (F, comp));
30329e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
30429e0a805SPieter Ghysels }
30529e0a805SPieter Ghysels /*@
306*1d27aa22SBarry Smith   MatSTRUMPACKGetCompression - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> compression type
30729e0a805SPieter Ghysels 
30829e0a805SPieter Ghysels   Input Parameters:
30929e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
31029e0a805SPieter Ghysels 
31129e0a805SPieter Ghysels   Output Parameter:
31229e0a805SPieter Ghysels . comp - Type of compression to be used in the approximate sparse factorization
31329e0a805SPieter Ghysels 
31429e0a805SPieter Ghysels   Level: intermediate
31529e0a805SPieter Ghysels 
316*1d27aa22SBarry Smith   Note:
31729e0a805SPieter Ghysels   Default is `MAT_STRUMPACK_COMPRESSION_TYPE_NONE` for `-pc_type lu` and `MAT_STRUMPACK_COMPRESSION_TYPE_BLR` for `-pc_type ilu`
31829e0a805SPieter Ghysels 
319*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKCompressionType`, `MatSTRUMPACKSetCompression()`
32029e0a805SPieter Ghysels @*/
32129e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetCompression(Mat F, MatSTRUMPACKCompressionType *comp)
32229e0a805SPieter Ghysels {
32329e0a805SPieter Ghysels   PetscFunctionBegin;
32429e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
32529e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetCompression_C", (Mat, MatSTRUMPACKCompressionType *), (F, comp));
32629e0a805SPieter Ghysels   PetscValidLogicalCollectiveEnum(F, *comp, 2);
32729e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
32829e0a805SPieter Ghysels }
32929e0a805SPieter Ghysels 
33029e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetCompRelTol_STRUMPACK(Mat F, PetscReal rtol)
33129e0a805SPieter Ghysels {
33229e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
33329e0a805SPieter Ghysels 
33429e0a805SPieter Ghysels   PetscFunctionBegin;
33529e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_compression_rel_tol", STRUMPACK_set_compression_rel_tol(*S, rtol));
33629e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
33729e0a805SPieter Ghysels }
33829e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetCompRelTol_STRUMPACK(Mat F, PetscReal *rtol)
33929e0a805SPieter Ghysels {
34029e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
34129e0a805SPieter Ghysels 
34229e0a805SPieter Ghysels   PetscFunctionBegin;
34329e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_rel_tol", *rtol = (PetscReal)STRUMPACK_compression_rel_tol(*S));
34429e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
34529e0a805SPieter Ghysels }
34629e0a805SPieter Ghysels 
34729e0a805SPieter Ghysels /*@
348*1d27aa22SBarry Smith   MatSTRUMPACKSetCompRelTol - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> relative tolerance for compression
349147403d9SBarry Smith 
350c3339decSBarry Smith   Logically Collective
35134f43fa5SPieter Ghysels 
35234f43fa5SPieter Ghysels   Input Parameters:
3532ef1f0ffSBarry Smith + F    - the factored matrix obtained by calling `MatGetFactor()`
35434f43fa5SPieter Ghysels - rtol - relative compression tolerance
35534f43fa5SPieter Ghysels 
35611a5261eSBarry Smith   Options Database Key:
35729e0a805SPieter Ghysels . -mat_strumpack_compression_rel_tol <1e-4> - Relative compression tolerance, when using `-pctype ilu`
35834f43fa5SPieter Ghysels 
35929e0a805SPieter Ghysels   Level: intermediate
36034f43fa5SPieter Ghysels 
361*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatGetFactor()`, `MatSTRUMPACKGetCompRelTol()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKSetColPerm()`
36234f43fa5SPieter Ghysels @*/
36329e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetCompRelTol(Mat F, PetscReal rtol)
364d71ae5a4SJacob Faibussowitsch {
36534f43fa5SPieter Ghysels   PetscFunctionBegin;
36634f43fa5SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
36734f43fa5SPieter Ghysels   PetscValidLogicalCollectiveReal(F, rtol, 2);
36829e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetCompRelTol_C", (Mat, PetscReal), (F, rtol));
36929e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
37029e0a805SPieter Ghysels }
37129e0a805SPieter Ghysels /*@
372*1d27aa22SBarry Smith   MatSTRUMPACKGetCompRelTol - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> relative tolerance for compression
37329e0a805SPieter Ghysels 
37429e0a805SPieter Ghysels   Logically Collective
37529e0a805SPieter Ghysels 
37629e0a805SPieter Ghysels   Input Parameters:
37729e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()`
37829e0a805SPieter Ghysels 
37929e0a805SPieter Ghysels   Output Parameter:
38029e0a805SPieter Ghysels . rtol - relative compression tolerance
38129e0a805SPieter Ghysels 
38229e0a805SPieter Ghysels   Level: intermediate
38329e0a805SPieter Ghysels 
384*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatGetFactor()`, `MatSTRUMPACKSetCompRelTol()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKSetColPerm()`
38529e0a805SPieter Ghysels @*/
38629e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetCompRelTol(Mat F, PetscReal *rtol)
38729e0a805SPieter Ghysels {
38829e0a805SPieter Ghysels   PetscFunctionBegin;
38929e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
39029e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetCompRelTol_C", (Mat, PetscReal *), (F, rtol));
39129e0a805SPieter Ghysels   PetscValidLogicalCollectiveReal(F, *rtol, 2);
3923ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
39334f43fa5SPieter Ghysels }
39434f43fa5SPieter Ghysels 
39529e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetCompAbsTol_STRUMPACK(Mat F, PetscReal atol)
396d71ae5a4SJacob Faibussowitsch {
39735e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
39834f43fa5SPieter Ghysels 
39934f43fa5SPieter Ghysels   PetscFunctionBegin;
40029e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_compression_abs_tol", STRUMPACK_set_compression_abs_tol(*S, atol));
40129e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
40229e0a805SPieter Ghysels }
40329e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetCompAbsTol_STRUMPACK(Mat F, PetscReal *atol)
40429e0a805SPieter Ghysels {
40529e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
40629e0a805SPieter Ghysels 
40729e0a805SPieter Ghysels   PetscFunctionBegin;
40829e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_abs_tol", *atol = (PetscReal)STRUMPACK_compression_abs_tol(*S));
4093ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
41034f43fa5SPieter Ghysels }
411e5a36eccSStefano Zampini 
41234f43fa5SPieter Ghysels /*@
413*1d27aa22SBarry Smith   MatSTRUMPACKSetCompAbsTol - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> absolute tolerance for compression
414147403d9SBarry Smith 
415c3339decSBarry Smith   Logically Collective
41634f43fa5SPieter Ghysels 
41734f43fa5SPieter Ghysels   Input Parameters:
4182ef1f0ffSBarry Smith + F    - the factored matrix obtained by calling `MatGetFactor()`
41934f43fa5SPieter Ghysels - atol - absolute compression tolerance
42034f43fa5SPieter Ghysels 
42111a5261eSBarry Smith   Options Database Key:
42229e0a805SPieter Ghysels . -mat_strumpack_compression_abs_tol <1e-10> - Absolute compression tolerance, when using `-pctype ilu`
42334f43fa5SPieter Ghysels 
42429e0a805SPieter Ghysels   Level: intermediate
42534f43fa5SPieter Ghysels 
426*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatGetFactor()`, `MatSTRUMPACKGetCompAbsTol()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKSetColPerm()`
42734f43fa5SPieter Ghysels @*/
42829e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetCompAbsTol(Mat F, PetscReal atol)
429d71ae5a4SJacob Faibussowitsch {
43034f43fa5SPieter Ghysels   PetscFunctionBegin;
43134f43fa5SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
43234f43fa5SPieter Ghysels   PetscValidLogicalCollectiveReal(F, atol, 2);
43329e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetCompAbsTol_C", (Mat, PetscReal), (F, atol));
4343ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
43534f43fa5SPieter Ghysels }
43634f43fa5SPieter Ghysels /*@
437*1d27aa22SBarry Smith   MatSTRUMPACKGetCompAbsTol - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> absolute tolerance for compression
438147403d9SBarry Smith 
439c3339decSBarry Smith   Logically Collective
44034f43fa5SPieter Ghysels 
44134f43fa5SPieter Ghysels   Input Parameters:
44229e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()`
44334f43fa5SPieter Ghysels 
44429e0a805SPieter Ghysels   Output Parameter:
44529e0a805SPieter Ghysels . atol - absolute compression tolerance
44634f43fa5SPieter Ghysels 
44729e0a805SPieter Ghysels   Level: intermediate
44834f43fa5SPieter Ghysels 
449*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatGetFactor()`, `MatSTRUMPACKSetCompAbsTol()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKSetColPerm()`
45034f43fa5SPieter Ghysels @*/
45129e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetCompAbsTol(Mat F, PetscReal *atol)
452d71ae5a4SJacob Faibussowitsch {
45334f43fa5SPieter Ghysels   PetscFunctionBegin;
45434f43fa5SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
45529e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetCompAbsTol_C", (Mat, PetscReal *), (F, atol));
45629e0a805SPieter Ghysels   PetscValidLogicalCollectiveReal(F, *atol, 2);
4573ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
45834f43fa5SPieter Ghysels }
45934f43fa5SPieter Ghysels 
46029e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetCompLeafSize_STRUMPACK(Mat F, PetscInt leaf_size)
461d71ae5a4SJacob Faibussowitsch {
46235e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
463a36bf211SPieter Ghysels 
464a36bf211SPieter Ghysels   PetscFunctionBegin;
46529e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_compression_leaf_size", STRUMPACK_set_compression_leaf_size(*S, leaf_size));
46629e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
46729e0a805SPieter Ghysels }
46829e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetCompLeafSize_STRUMPACK(Mat F, PetscInt *leaf_size)
46929e0a805SPieter Ghysels {
47029e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
47129e0a805SPieter Ghysels 
47229e0a805SPieter Ghysels   PetscFunctionBegin;
47329e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_leaf_size", *leaf_size = (PetscInt)STRUMPACK_compression_leaf_size(*S));
4743ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
475a36bf211SPieter Ghysels }
476e5a36eccSStefano Zampini 
477a36bf211SPieter Ghysels /*@
478*1d27aa22SBarry Smith   MatSTRUMPACKSetCompLeafSize - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> leaf size for HSS, BLR, HODLR...
479147403d9SBarry Smith 
480c3339decSBarry Smith   Logically Collective
481a36bf211SPieter Ghysels 
482a36bf211SPieter Ghysels   Input Parameters:
48329e0a805SPieter Ghysels + F         - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
48429e0a805SPieter Ghysels - leaf_size - Size of diagonal blocks in rank-structured approximation
485a36bf211SPieter Ghysels 
48611a5261eSBarry Smith   Options Database Key:
48729e0a805SPieter Ghysels . -mat_strumpack_compression_leaf_size - Size of diagonal blocks in rank-structured approximation, when using `-pctype ilu`
488a36bf211SPieter Ghysels 
48929e0a805SPieter Ghysels   Level: intermediate
490a36bf211SPieter Ghysels 
491*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatGetFactor()`, `MatSTRUMPACKGetCompLeafSize()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKSetColPerm()`
492a36bf211SPieter Ghysels @*/
49329e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetCompLeafSize(Mat F, PetscInt leaf_size)
494d71ae5a4SJacob Faibussowitsch {
495a36bf211SPieter Ghysels   PetscFunctionBegin;
496a36bf211SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
497a36bf211SPieter Ghysels   PetscValidLogicalCollectiveInt(F, leaf_size, 2);
49829e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetCompLeafSize_C", (Mat, PetscInt), (F, leaf_size));
4993ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
500a36bf211SPieter Ghysels }
501291d0ed5SPieter Ghysels /*@
502*1d27aa22SBarry Smith   MatSTRUMPACKGetCompLeafSize - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> leaf size for HSS, BLR, HODLR...
503147403d9SBarry Smith 
504c3339decSBarry Smith   Logically Collective
505291d0ed5SPieter Ghysels 
506291d0ed5SPieter Ghysels   Input Parameters:
50729e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
508291d0ed5SPieter Ghysels 
50929e0a805SPieter Ghysels   Output Parameter:
51029e0a805SPieter Ghysels . leaf_size - Size of diagonal blocks in rank-structured approximation
511291d0ed5SPieter Ghysels 
51229e0a805SPieter Ghysels   Level: intermediate
513291d0ed5SPieter Ghysels 
514*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `MatGetFactor()`, `MatSTRUMPACKSetCompLeafSize()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKSetColPerm()`
515291d0ed5SPieter Ghysels @*/
51629e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetCompLeafSize(Mat F, PetscInt *leaf_size)
517d71ae5a4SJacob Faibussowitsch {
518291d0ed5SPieter Ghysels   PetscFunctionBegin;
519291d0ed5SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
52029e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetCompLeafSize_C", (Mat, PetscInt *), (F, leaf_size));
52129e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, *leaf_size, 2);
52229e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
52329e0a805SPieter Ghysels }
52429e0a805SPieter Ghysels 
52529e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetGeometricNxyz_STRUMPACK(Mat F, PetscInt nx, PetscInt ny, PetscInt nz)
52629e0a805SPieter Ghysels {
52729e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
52829e0a805SPieter Ghysels 
52929e0a805SPieter Ghysels   PetscFunctionBegin;
53029e0a805SPieter Ghysels   if (nx < 1) {
53129e0a805SPieter Ghysels     PetscCheck(nx == PETSC_DECIDE || nx == PETSC_DEFAULT, PetscObjectComm((PetscObject)F), PETSC_ERR_ARG_OUTOFRANGE, "nx < 1");
53229e0a805SPieter Ghysels     nx = 1;
53329e0a805SPieter Ghysels   }
53429e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_nx", STRUMPACK_set_nx(*S, nx));
53529e0a805SPieter Ghysels   if (ny < 1) {
53629e0a805SPieter Ghysels     PetscCheck(ny == PETSC_DECIDE || ny == PETSC_DEFAULT, PetscObjectComm((PetscObject)F), PETSC_ERR_ARG_OUTOFRANGE, "ny < 1");
53729e0a805SPieter Ghysels     ny = 1;
53829e0a805SPieter Ghysels   }
53929e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_ny", STRUMPACK_set_ny(*S, ny));
54029e0a805SPieter Ghysels   if (nz < 1) {
54129e0a805SPieter Ghysels     PetscCheck(nz == PETSC_DECIDE || nz == PETSC_DEFAULT, PetscObjectComm((PetscObject)F), PETSC_ERR_ARG_OUTOFRANGE, "nz < 1");
54229e0a805SPieter Ghysels     nz = 1;
54329e0a805SPieter Ghysels   }
54429e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_nz", STRUMPACK_set_nz(*S, nz));
54529e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
54629e0a805SPieter Ghysels }
54729e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetGeometricComponents_STRUMPACK(Mat F, PetscInt nc)
54829e0a805SPieter Ghysels {
54929e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
55029e0a805SPieter Ghysels 
55129e0a805SPieter Ghysels   PetscFunctionBegin;
55229e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_components", STRUMPACK_set_components(*S, nc));
55329e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
55429e0a805SPieter Ghysels }
55529e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetGeometricWidth_STRUMPACK(Mat F, PetscInt w)
55629e0a805SPieter Ghysels {
55729e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
55829e0a805SPieter Ghysels 
55929e0a805SPieter Ghysels   PetscFunctionBegin;
56029e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_separator_width", STRUMPACK_set_separator_width(*S, w));
56129e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
56229e0a805SPieter Ghysels }
56329e0a805SPieter Ghysels 
56429e0a805SPieter Ghysels /*@
565*1d27aa22SBarry Smith   MatSTRUMPACKSetGeometricNxyz - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> mesh x, y and z dimensions, for use with GEOMETRIC ordering.
56629e0a805SPieter Ghysels 
56729e0a805SPieter Ghysels   Logically Collective
56829e0a805SPieter Ghysels 
56929e0a805SPieter Ghysels   Input Parameters:
57029e0a805SPieter Ghysels + F  - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
57129e0a805SPieter Ghysels . nx - x dimension of the mesh
57229e0a805SPieter Ghysels . ny - y dimension of the mesh
57329e0a805SPieter Ghysels - nz - z dimension of the mesh
57429e0a805SPieter Ghysels 
57529e0a805SPieter Ghysels   Level: intermediate
57629e0a805SPieter Ghysels 
577*1d27aa22SBarry Smith   Note:
57829e0a805SPieter Ghysels   If the mesh is two (or one) dimensional one can use 1, `PETSC_DECIDE` or `PETSC_DEFAULT`
57929e0a805SPieter Ghysels   for the missing z (and y) dimensions.
58029e0a805SPieter Ghysels 
581*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`
58229e0a805SPieter Ghysels @*/
58329e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetGeometricNxyz(Mat F, PetscInt nx, PetscInt ny, PetscInt nz)
58429e0a805SPieter Ghysels {
58529e0a805SPieter Ghysels   PetscFunctionBegin;
58629e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
58729e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, nx, 2);
58829e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, ny, 3);
58929e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, nz, 4);
59029e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetGeometricNxyz_C", (Mat, PetscInt, PetscInt, PetscInt), (F, nx, ny, nz));
59129e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
59229e0a805SPieter Ghysels }
59329e0a805SPieter Ghysels /*@
594*1d27aa22SBarry Smith   MatSTRUMPACKSetGeometricComponents - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>
595*1d27aa22SBarry Smith   number of degrees of freedom per mesh point, for use with GEOMETRIC ordering.
59629e0a805SPieter Ghysels 
59729e0a805SPieter Ghysels   Logically Collective
59829e0a805SPieter Ghysels 
59929e0a805SPieter Ghysels   Input Parameters:
60029e0a805SPieter Ghysels + F  - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
60129e0a805SPieter Ghysels - nc - Number of components/dof's per grid point
60229e0a805SPieter Ghysels 
60329e0a805SPieter Ghysels   Options Database Key:
60429e0a805SPieter Ghysels . -mat_strumpack_geometric_components <1> - Number of components per mesh point, for geometric nested dissection ordering
60529e0a805SPieter Ghysels 
60629e0a805SPieter Ghysels   Level: intermediate
60729e0a805SPieter Ghysels 
608*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`
60929e0a805SPieter Ghysels @*/
61029e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetGeometricComponents(Mat F, PetscInt nc)
61129e0a805SPieter Ghysels {
61229e0a805SPieter Ghysels   PetscFunctionBegin;
61329e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
61429e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, nc, 2);
61529e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetGeometricComponents_C", (Mat, PetscInt), (F, nc));
61629e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
61729e0a805SPieter Ghysels }
61829e0a805SPieter Ghysels /*@
619*1d27aa22SBarry Smith   MatSTRUMPACKSetGeometricWidth - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> width of the separator, for use with GEOMETRIC ordering.
62029e0a805SPieter Ghysels 
62129e0a805SPieter Ghysels   Logically Collective
62229e0a805SPieter Ghysels 
62329e0a805SPieter Ghysels   Input Parameters:
62429e0a805SPieter Ghysels + F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
62529e0a805SPieter Ghysels - w - width of the separator
62629e0a805SPieter Ghysels 
62729e0a805SPieter Ghysels   Options Database Key:
62829e0a805SPieter Ghysels . -mat_strumpack_geometric_width <1> - Width of the separator of the mesh, for geometric nested dissection ordering
62929e0a805SPieter Ghysels 
63029e0a805SPieter Ghysels   Level: intermediate
63129e0a805SPieter Ghysels 
632*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`
63329e0a805SPieter Ghysels @*/
63429e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetGeometricWidth(Mat F, PetscInt w)
63529e0a805SPieter Ghysels {
63629e0a805SPieter Ghysels   PetscFunctionBegin;
63729e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
63829e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, w, 2);
63929e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetGeometricWidth_C", (Mat, PetscInt), (F, w));
64029e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
64129e0a805SPieter Ghysels }
64229e0a805SPieter Ghysels 
64329e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetCompMinSepSize_STRUMPACK(Mat F, PetscInt min_sep_size)
64429e0a805SPieter Ghysels {
64529e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
64629e0a805SPieter Ghysels 
64729e0a805SPieter Ghysels   PetscFunctionBegin;
64829e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_compression_min_sep_size", STRUMPACK_set_compression_min_sep_size(*S, min_sep_size));
64929e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
65029e0a805SPieter Ghysels }
65129e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetCompMinSepSize_STRUMPACK(Mat F, PetscInt *min_sep_size)
65229e0a805SPieter Ghysels {
65329e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
65429e0a805SPieter Ghysels 
65529e0a805SPieter Ghysels   PetscFunctionBegin;
65629e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_min_sep_size", *min_sep_size = (PetscInt)STRUMPACK_compression_min_sep_size(*S));
65729e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
65829e0a805SPieter Ghysels }
65929e0a805SPieter Ghysels 
66029e0a805SPieter Ghysels /*@
661*1d27aa22SBarry Smith   MatSTRUMPACKSetCompMinSepSize - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> minimum separator size for low-rank approximation
66229e0a805SPieter Ghysels 
66329e0a805SPieter Ghysels   Logically Collective
66429e0a805SPieter Ghysels 
66529e0a805SPieter Ghysels   Input Parameters:
66629e0a805SPieter Ghysels + F            - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
66729e0a805SPieter Ghysels - min_sep_size - minimum dense matrix size for low-rank approximation
66829e0a805SPieter Ghysels 
66929e0a805SPieter Ghysels   Options Database Key:
67029e0a805SPieter Ghysels . -mat_strumpack_compression_min_sep_size <min_sep_size> - Minimum size of dense sub-block for low-rank compression
67129e0a805SPieter Ghysels 
67229e0a805SPieter Ghysels   Level: intermediate
67329e0a805SPieter Ghysels 
674*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKGetCompMinSepSize()`
67529e0a805SPieter Ghysels @*/
67629e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetCompMinSepSize(Mat F, PetscInt min_sep_size)
67729e0a805SPieter Ghysels {
67829e0a805SPieter Ghysels   PetscFunctionBegin;
67929e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
68029e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, min_sep_size, 2);
68129e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetCompMinSepSize_C", (Mat, PetscInt), (F, min_sep_size));
68229e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
68329e0a805SPieter Ghysels }
68429e0a805SPieter Ghysels /*@
685*1d27aa22SBarry Smith   MatSTRUMPACKGetCompMinSepSize - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> minimum separator size for low-rank approximation
68629e0a805SPieter Ghysels 
68729e0a805SPieter Ghysels   Logically Collective
68829e0a805SPieter Ghysels 
68929e0a805SPieter Ghysels   Input Parameters:
69029e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
69129e0a805SPieter Ghysels 
69229e0a805SPieter Ghysels   Output Parameter:
69329e0a805SPieter Ghysels . min_sep_size - minimum dense matrix size for low-rank approximation
69429e0a805SPieter Ghysels 
69529e0a805SPieter Ghysels   Level: intermediate
69629e0a805SPieter Ghysels 
697*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetCompMinSepSize()`
69829e0a805SPieter Ghysels @*/
69929e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetCompMinSepSize(Mat F, PetscInt *min_sep_size)
70029e0a805SPieter Ghysels {
70129e0a805SPieter Ghysels   PetscFunctionBegin;
70229e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
70329e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetCompMinSepSize_C", (Mat, PetscInt *), (F, min_sep_size));
70429e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, *min_sep_size, 2);
70529e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
70629e0a805SPieter Ghysels }
70729e0a805SPieter Ghysels 
70829e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetCompLossyPrecision_STRUMPACK(Mat F, PetscInt lossy_prec)
70929e0a805SPieter Ghysels {
71029e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
71129e0a805SPieter Ghysels 
71229e0a805SPieter Ghysels   PetscFunctionBegin;
71329e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_compression_lossy_precision", STRUMPACK_set_compression_lossy_precision(*S, lossy_prec));
71429e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
71529e0a805SPieter Ghysels }
71629e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetCompLossyPrecision_STRUMPACK(Mat F, PetscInt *lossy_prec)
71729e0a805SPieter Ghysels {
71829e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
71929e0a805SPieter Ghysels 
72029e0a805SPieter Ghysels   PetscFunctionBegin;
72129e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_lossy_precision", *lossy_prec = (PetscInt)STRUMPACK_compression_lossy_precision(*S));
72229e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
72329e0a805SPieter Ghysels }
72429e0a805SPieter Ghysels 
72529e0a805SPieter Ghysels /*@
726*1d27aa22SBarry Smith   MatSTRUMPACKSetCompLossyPrecision - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> precision for lossy compression (requires ZFP support)
72729e0a805SPieter Ghysels 
72829e0a805SPieter Ghysels   Logically Collective
72929e0a805SPieter Ghysels 
73029e0a805SPieter Ghysels   Input Parameters:
73129e0a805SPieter Ghysels + F          - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
73229e0a805SPieter Ghysels - lossy_prec - Number of bitplanes to use in lossy compression
73329e0a805SPieter Ghysels 
73429e0a805SPieter Ghysels   Options Database Key:
73529e0a805SPieter Ghysels . -mat_strumpack_compression_lossy_precision <lossy_prec> - Precision when using lossy compression [1-64], when using `-pctype ilu -mat_strumpack_compression MAT_STRUMPACK_COMPRESSION_TYPE_LOSSY`
73629e0a805SPieter Ghysels 
73729e0a805SPieter Ghysels   Level: intermediate
73829e0a805SPieter Ghysels 
739*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKGetCompLossyPrecision()`
74029e0a805SPieter Ghysels @*/
74129e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetCompLossyPrecision(Mat F, PetscInt lossy_prec)
74229e0a805SPieter Ghysels {
74329e0a805SPieter Ghysels   PetscFunctionBegin;
74429e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
74529e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, lossy_prec, 2);
74629e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetCompLossyPrecision_C", (Mat, PetscInt), (F, lossy_prec));
74729e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
74829e0a805SPieter Ghysels }
74929e0a805SPieter Ghysels /*@
750*1d27aa22SBarry Smith   MatSTRUMPACKGetCompLossyPrecision - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master> precision for lossy compression (requires ZFP support)
75129e0a805SPieter Ghysels 
75229e0a805SPieter Ghysels   Logically Collective
75329e0a805SPieter Ghysels 
75429e0a805SPieter Ghysels   Input Parameters:
75529e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
75629e0a805SPieter Ghysels 
75729e0a805SPieter Ghysels   Output Parameter:
75829e0a805SPieter Ghysels . lossy_prec - Number of bitplanes to use in lossy compression
75929e0a805SPieter Ghysels 
76029e0a805SPieter Ghysels   Level: intermediate
76129e0a805SPieter Ghysels 
762*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetCompLossyPrecision()`
76329e0a805SPieter Ghysels @*/
76429e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetCompLossyPrecision(Mat F, PetscInt *lossy_prec)
76529e0a805SPieter Ghysels {
76629e0a805SPieter Ghysels   PetscFunctionBegin;
76729e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
76829e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetCompLossyPrecision_C", (Mat, PetscInt *), (F, lossy_prec));
76929e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, *lossy_prec, 2);
77029e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
77129e0a805SPieter Ghysels }
77229e0a805SPieter Ghysels 
77329e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKSetCompButterflyLevels_STRUMPACK(Mat F, PetscInt bfly_lvls)
77429e0a805SPieter Ghysels {
77529e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
77629e0a805SPieter Ghysels 
77729e0a805SPieter Ghysels   PetscFunctionBegin;
77829e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_compression_butterfly_levels", STRUMPACK_set_compression_butterfly_levels(*S, bfly_lvls));
77929e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
78029e0a805SPieter Ghysels }
78129e0a805SPieter Ghysels static PetscErrorCode MatSTRUMPACKGetCompButterflyLevels_STRUMPACK(Mat F, PetscInt *bfly_lvls)
78229e0a805SPieter Ghysels {
78329e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
78429e0a805SPieter Ghysels 
78529e0a805SPieter Ghysels   PetscFunctionBegin;
78629e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_butterfly_levels", *bfly_lvls = (PetscInt)STRUMPACK_compression_butterfly_levels(*S));
78729e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
78829e0a805SPieter Ghysels }
78929e0a805SPieter Ghysels 
79029e0a805SPieter Ghysels /*@
791*1d27aa22SBarry Smith   MatSTRUMPACKSetCompButterflyLevels - Set STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>
792*1d27aa22SBarry Smith   number of butterfly levels in HODLR compression (requires ButterflyPACK support)
79329e0a805SPieter Ghysels 
79429e0a805SPieter Ghysels   Logically Collective
79529e0a805SPieter Ghysels 
79629e0a805SPieter Ghysels   Input Parameters:
79729e0a805SPieter Ghysels + F         - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
79829e0a805SPieter Ghysels - bfly_lvls - Number of levels of butterfly compression in HODLR compression
79929e0a805SPieter Ghysels 
80029e0a805SPieter Ghysels   Options Database Key:
801*1d27aa22SBarry Smith . -mat_strumpack_compression_butterfly_levels <bfly_lvls> - Number of levels in the hierarchically off-diagonal matrix for which to use butterfly,
802*1d27aa22SBarry Smith                                                             when using `-pctype ilu`, (BLR_)HODLR compression
80329e0a805SPieter Ghysels 
80429e0a805SPieter Ghysels   Level: intermediate
80529e0a805SPieter Ghysels 
806*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKGetCompButterflyLevels()`
80729e0a805SPieter Ghysels @*/
80829e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKSetCompButterflyLevels(Mat F, PetscInt bfly_lvls)
80929e0a805SPieter Ghysels {
81029e0a805SPieter Ghysels   PetscFunctionBegin;
81129e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
81229e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, bfly_lvls, 2);
81329e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKSetButterflyLevels_C", (Mat, PetscInt), (F, bfly_lvls));
81429e0a805SPieter Ghysels   PetscFunctionReturn(PETSC_SUCCESS);
81529e0a805SPieter Ghysels }
81629e0a805SPieter Ghysels /*@
817*1d27aa22SBarry Smith   MatSTRUMPACKGetCompButterflyLevels - Get STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>
818*1d27aa22SBarry Smith   number of butterfly levels in HODLR compression (requires ButterflyPACK support)
81929e0a805SPieter Ghysels 
82029e0a805SPieter Ghysels   Logically Collective
82129e0a805SPieter Ghysels 
82229e0a805SPieter Ghysels   Input Parameters:
82329e0a805SPieter Ghysels . F - the factored matrix obtained by calling `MatGetFactor()` from PETSc-STRUMPACK interface
82429e0a805SPieter Ghysels 
82529e0a805SPieter Ghysels   Output Parameter:
82629e0a805SPieter Ghysels . bfly_lvls - Number of levels of butterfly compression in HODLR compression
82729e0a805SPieter Ghysels 
82829e0a805SPieter Ghysels   Level: intermediate
82929e0a805SPieter Ghysels 
830*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, `MatGetFactor()`, `MatSTRUMPACKSetCompButterflyLevels()`
83129e0a805SPieter Ghysels @*/
83229e0a805SPieter Ghysels PetscErrorCode MatSTRUMPACKGetCompButterflyLevels(Mat F, PetscInt *bfly_lvls)
83329e0a805SPieter Ghysels {
83429e0a805SPieter Ghysels   PetscFunctionBegin;
83529e0a805SPieter Ghysels   PetscValidHeaderSpecific(F, MAT_CLASSID, 1);
83629e0a805SPieter Ghysels   PetscTryMethod(F, "MatSTRUMPACKGetButterflyLevels_C", (Mat, PetscInt *), (F, bfly_lvls));
83729e0a805SPieter Ghysels   PetscValidLogicalCollectiveInt(F, *bfly_lvls, 2);
8383ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
839291d0ed5SPieter Ghysels }
840291d0ed5SPieter Ghysels 
841d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatSolve_STRUMPACK(Mat A, Vec b_mpi, Vec x)
842d71ae5a4SJacob Faibussowitsch {
84335e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)A->data;
8447d6ea485SPieter Ghysels   STRUMPACK_RETURN_CODE   sp_err;
8457d6ea485SPieter Ghysels   const PetscScalar      *bptr;
8467d6ea485SPieter Ghysels   PetscScalar            *xptr;
8477d6ea485SPieter Ghysels 
8487d6ea485SPieter Ghysels   PetscFunctionBegin;
8499566063dSJacob Faibussowitsch   PetscCall(VecGetArray(x, &xptr));
8509566063dSJacob Faibussowitsch   PetscCall(VecGetArrayRead(b_mpi, &bptr));
8510d08a34dSPieter Ghysels 
852e77caa6dSBarry Smith   PetscStackCallExternalVoid("STRUMPACK_solve", sp_err = STRUMPACK_solve(*S, (PetscScalar *)bptr, xptr, 0));
8530d08a34dSPieter Ghysels   switch (sp_err) {
854d71ae5a4SJacob Faibussowitsch   case STRUMPACK_SUCCESS:
855d71ae5a4SJacob Faibussowitsch     break;
8569371c9d4SSatish Balay   case STRUMPACK_MATRIX_NOT_SET: {
8579371c9d4SSatish Balay     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: matrix was not set");
8589371c9d4SSatish Balay     break;
8599371c9d4SSatish Balay   }
8609371c9d4SSatish Balay   case STRUMPACK_REORDERING_ERROR: {
8619371c9d4SSatish Balay     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: matrix reordering failed");
8629371c9d4SSatish Balay     break;
8639371c9d4SSatish Balay   }
864d71ae5a4SJacob Faibussowitsch   default:
865d71ae5a4SJacob Faibussowitsch     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: solve failed");
8667d6ea485SPieter Ghysels   }
8679566063dSJacob Faibussowitsch   PetscCall(VecRestoreArray(x, &xptr));
8689566063dSJacob Faibussowitsch   PetscCall(VecRestoreArrayRead(b_mpi, &bptr));
8693ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
8707d6ea485SPieter Ghysels }
8717d6ea485SPieter Ghysels 
872d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatMatSolve_STRUMPACK(Mat A, Mat B_mpi, Mat X)
873d71ae5a4SJacob Faibussowitsch {
87429e0a805SPieter Ghysels   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)A->data;
87529e0a805SPieter Ghysels   STRUMPACK_RETURN_CODE   sp_err;
8767d6ea485SPieter Ghysels   PetscBool               flg;
87729e0a805SPieter Ghysels   PetscInt                m = A->rmap->n, nrhs;
87829e0a805SPieter Ghysels   const PetscScalar      *bptr;
87929e0a805SPieter Ghysels   PetscScalar            *xptr;
8807d6ea485SPieter Ghysels 
8817d6ea485SPieter Ghysels   PetscFunctionBegin;
8829566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompareAny((PetscObject)B_mpi, &flg, MATSEQDENSE, MATMPIDENSE, NULL));
8835f80ce2aSJacob Faibussowitsch   PetscCheck(flg, PetscObjectComm((PetscObject)A), PETSC_ERR_ARG_WRONG, "Matrix B must be MATDENSE matrix");
8849566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompareAny((PetscObject)X, &flg, MATSEQDENSE, MATMPIDENSE, NULL));
8855f80ce2aSJacob Faibussowitsch   PetscCheck(flg, PetscObjectComm((PetscObject)A), PETSC_ERR_ARG_WRONG, "Matrix X must be MATDENSE matrix");
88629e0a805SPieter Ghysels 
88729e0a805SPieter Ghysels   PetscCall(MatGetSize(B_mpi, NULL, &nrhs));
88829e0a805SPieter Ghysels   PetscCall(MatDenseGetArray(X, &xptr));
88929e0a805SPieter Ghysels   PetscCall(MatDenseGetArrayRead(B_mpi, &bptr));
89029e0a805SPieter Ghysels 
89129e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_matsolve", sp_err = STRUMPACK_matsolve(*S, nrhs, bptr, m, xptr, m, 0));
89229e0a805SPieter Ghysels   switch (sp_err) {
89329e0a805SPieter Ghysels   case STRUMPACK_SUCCESS:
89429e0a805SPieter Ghysels     break;
89529e0a805SPieter Ghysels   case STRUMPACK_MATRIX_NOT_SET: {
89629e0a805SPieter Ghysels     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: matrix was not set");
89729e0a805SPieter Ghysels     break;
89829e0a805SPieter Ghysels   }
89929e0a805SPieter Ghysels   case STRUMPACK_REORDERING_ERROR: {
90029e0a805SPieter Ghysels     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: matrix reordering failed");
90129e0a805SPieter Ghysels     break;
90229e0a805SPieter Ghysels   }
90329e0a805SPieter Ghysels   default:
90429e0a805SPieter Ghysels     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: solve failed");
90529e0a805SPieter Ghysels   }
90629e0a805SPieter Ghysels   PetscCall(MatDenseRestoreArrayRead(B_mpi, &bptr));
90729e0a805SPieter Ghysels   PetscCall(MatDenseRestoreArray(X, &xptr));
90829e0a805SPieter Ghysels 
9093ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9107d6ea485SPieter Ghysels }
9117d6ea485SPieter Ghysels 
912d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatView_Info_STRUMPACK(Mat A, PetscViewer viewer)
913d71ae5a4SJacob Faibussowitsch {
914ad0c5e61SPieter Ghysels   PetscFunctionBegin;
915ad0c5e61SPieter Ghysels   /* check if matrix is strumpack type */
9163ba16761SJacob Faibussowitsch   if (A->ops->solve != MatSolve_STRUMPACK) PetscFunctionReturn(PETSC_SUCCESS);
9179566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIIPrintf(viewer, "STRUMPACK sparse solver!\n"));
9183ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
919ad0c5e61SPieter Ghysels }
920ad0c5e61SPieter Ghysels 
921d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatView_STRUMPACK(Mat A, PetscViewer viewer)
922d71ae5a4SJacob Faibussowitsch {
923ad0c5e61SPieter Ghysels   PetscBool         iascii;
924ad0c5e61SPieter Ghysels   PetscViewerFormat format;
925ad0c5e61SPieter Ghysels 
926ad0c5e61SPieter Ghysels   PetscFunctionBegin;
9279566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &iascii));
928ad0c5e61SPieter Ghysels   if (iascii) {
9299566063dSJacob Faibussowitsch     PetscCall(PetscViewerGetFormat(viewer, &format));
9309566063dSJacob Faibussowitsch     if (format == PETSC_VIEWER_ASCII_INFO) PetscCall(MatView_Info_STRUMPACK(A, viewer));
931ad0c5e61SPieter Ghysels   }
9323ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
933ad0c5e61SPieter Ghysels }
9347d6ea485SPieter Ghysels 
935d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatLUFactorNumeric_STRUMPACK(Mat F, Mat A, const MatFactorInfo *info)
936d71ae5a4SJacob Faibussowitsch {
93735e8bcc9SJunchao Zhang   STRUMPACK_SparseSolver *S = (STRUMPACK_SparseSolver *)F->data;
9387d6ea485SPieter Ghysels   STRUMPACK_RETURN_CODE   sp_err;
93929e0a805SPieter Ghysels   Mat                     Aloc;
94029e0a805SPieter Ghysels   const PetscScalar      *av;
94129e0a805SPieter Ghysels   const PetscInt         *ai = NULL, *aj = NULL;
94229e0a805SPieter Ghysels   PetscInt                M = A->rmap->N, m = A->rmap->n, dummy;
94329e0a805SPieter Ghysels   PetscBool               ismpiaij, isseqaij, flg;
9447d6ea485SPieter Ghysels 
9457d6ea485SPieter Ghysels   PetscFunctionBegin;
94629e0a805SPieter Ghysels   PetscCall(PetscObjectBaseTypeCompare((PetscObject)A, MATSEQAIJ, &isseqaij));
94729e0a805SPieter Ghysels   PetscCall(PetscObjectBaseTypeCompare((PetscObject)A, MATMPIAIJ, &ismpiaij));
94829e0a805SPieter Ghysels   if (ismpiaij) {
94929e0a805SPieter Ghysels     PetscCall(MatMPIAIJGetLocalMat(A, MAT_INITIAL_MATRIX, &Aloc));
95029e0a805SPieter Ghysels   } else if (isseqaij) {
95129e0a805SPieter Ghysels     PetscCall(PetscObjectReference((PetscObject)A));
95229e0a805SPieter Ghysels     Aloc = A;
95329e0a805SPieter Ghysels   } else SETERRQ(PetscObjectComm((PetscObject)A), PETSC_ERR_SUP, "Not for type %s", ((PetscObject)A)->type_name);
95429e0a805SPieter Ghysels 
95529e0a805SPieter Ghysels   PetscCall(MatGetRowIJ(Aloc, 0, PETSC_FALSE, PETSC_FALSE, &dummy, &ai, &aj, &flg));
95629e0a805SPieter Ghysels   PetscCheck(flg, PETSC_COMM_SELF, PETSC_ERR_SUP, "GetRowIJ failed");
95729e0a805SPieter Ghysels   PetscCall(MatSeqAIJGetArrayRead(Aloc, &av));
95829e0a805SPieter Ghysels 
95929e0a805SPieter Ghysels   if (ismpiaij) {
96029e0a805SPieter Ghysels     const PetscInt *dist = NULL;
96129e0a805SPieter Ghysels     PetscCall(MatGetOwnershipRanges(A, &dist));
96229e0a805SPieter Ghysels     PetscStackCallExternalVoid("STRUMPACK_set_distributed_csr_matrix", STRUMPACK_set_distributed_csr_matrix(*S, &m, ai, aj, av, dist, 0));
96329e0a805SPieter Ghysels   } else if (isseqaij) {
96429e0a805SPieter Ghysels     PetscStackCallExternalVoid("STRUMPACK_set_csr_matrix", STRUMPACK_set_csr_matrix(*S, &M, ai, aj, av, 0));
9657d6ea485SPieter Ghysels   }
9667d6ea485SPieter Ghysels 
96729e0a805SPieter Ghysels   PetscCall(MatRestoreRowIJ(Aloc, 0, PETSC_FALSE, PETSC_FALSE, &dummy, &ai, &aj, &flg));
96829e0a805SPieter Ghysels   PetscCheck(flg, PETSC_COMM_SELF, PETSC_ERR_SUP, "RestoreRowIJ failed");
96929e0a805SPieter Ghysels   PetscCall(MatSeqAIJRestoreArrayRead(Aloc, &av));
97029e0a805SPieter Ghysels   PetscCall(MatDestroy(&Aloc));
97129e0a805SPieter Ghysels 
9727d6ea485SPieter Ghysels   /* Reorder and Factor the matrix. */
9737d6ea485SPieter Ghysels   /* TODO figure out how to avoid reorder if the matrix values changed, but the pattern remains the same. */
974e77caa6dSBarry Smith   PetscStackCallExternalVoid("STRUMPACK_reorder", sp_err = STRUMPACK_reorder(*S));
975e77caa6dSBarry Smith   PetscStackCallExternalVoid("STRUMPACK_factor", sp_err = STRUMPACK_factor(*S));
9760d08a34dSPieter Ghysels   switch (sp_err) {
977d71ae5a4SJacob Faibussowitsch   case STRUMPACK_SUCCESS:
978d71ae5a4SJacob Faibussowitsch     break;
9799371c9d4SSatish Balay   case STRUMPACK_MATRIX_NOT_SET: {
9809371c9d4SSatish Balay     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: matrix was not set");
9819371c9d4SSatish Balay     break;
9829371c9d4SSatish Balay   }
9839371c9d4SSatish Balay   case STRUMPACK_REORDERING_ERROR: {
9849371c9d4SSatish Balay     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: matrix reordering failed");
9859371c9d4SSatish Balay     break;
9869371c9d4SSatish Balay   }
987d71ae5a4SJacob Faibussowitsch   default:
988d71ae5a4SJacob Faibussowitsch     SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "STRUMPACK error: factorization failed");
9897d6ea485SPieter Ghysels   }
990cb250fa3SPieter Ghysels   F->assembled    = PETSC_TRUE;
991cb250fa3SPieter Ghysels   F->preallocated = PETSC_TRUE;
9923ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
9937d6ea485SPieter Ghysels }
9947d6ea485SPieter Ghysels 
995d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatLUFactorSymbolic_STRUMPACK(Mat F, Mat A, IS r, IS c, const MatFactorInfo *info)
996d71ae5a4SJacob Faibussowitsch {
9977d6ea485SPieter Ghysels   PetscFunctionBegin;
9987d6ea485SPieter Ghysels   F->ops->lufactornumeric = MatLUFactorNumeric_STRUMPACK;
9997d6ea485SPieter Ghysels   F->ops->solve           = MatSolve_STRUMPACK;
10007d6ea485SPieter Ghysels   F->ops->matsolve        = MatMatSolve_STRUMPACK;
10013ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10027d6ea485SPieter Ghysels }
10037d6ea485SPieter Ghysels 
1004d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatFactorGetSolverType_aij_strumpack(Mat A, MatSolverType *type)
1005d71ae5a4SJacob Faibussowitsch {
10067d6ea485SPieter Ghysels   PetscFunctionBegin;
10077d6ea485SPieter Ghysels   *type = MATSOLVERSTRUMPACK;
10083ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
10097d6ea485SPieter Ghysels }
10107d6ea485SPieter Ghysels 
1011575704cbSPieter Ghysels /*MC
101229e0a805SPieter Ghysels   MATSOLVERSTRUMPACK = "strumpack" - A solver package providing a direct sparse solver (PCLU)
1013*1d27aa22SBarry Smith   and a preconditioner (PCILU) using low-rank compression via the external package STRUMPACK <https://portal.nersc.gov/project/sparse/strumpack/master>.
1014575704cbSPieter Ghysels 
101529e0a805SPieter Ghysels   Use `./configure --download-strumpack --download-metis` to have PETSc installed with STRUMPACK.
101629e0a805SPieter Ghysels 
101729e0a805SPieter Ghysels   For full functionality, add `--download-slate --download-magma --download-parmetis --download-ptscotch --download-zfp --download-butterflypack`.
101829e0a805SPieter Ghysels   SLATE provides GPU support in the multi-GPU setting, providing ScaLAPACK functionality but with GPU acceleration.
101929e0a805SPieter Ghysels   MAGMA can optionally be used for on node GPU support instead cuBLAS/cuSOLVER, and performs slightly better.
102029e0a805SPieter Ghysels   ParMETIS and PTScotch can be used for parallel fill-reducing ordering.
102129e0a805SPieter Ghysels   ZFP is used for floating point compression of the sparse factors (LOSSY or LOSSLESS compression).
102229e0a805SPieter Ghysels   ButterflyPACK is used for HODLR (Hierarchically Off-Diagonal Low Rank) and HODBF (Hierarchically Off-Diagonal Butterfly) compression of the sparse factors.
102329e0a805SPieter Ghysels 
1024575704cbSPieter Ghysels   Options Database Keys:
102529e0a805SPieter Ghysels + -mat_strumpack_verbose                      - Enable verbose output
102629e0a805SPieter Ghysels . -mat_strumpack_compression                  - Type of rank-structured compression in sparse LU factors (choose one of) NONE HSS BLR HODLR BLR_HODLR ZFP_BLR_HODLR LOSSLESS LOSSY
102729e0a805SPieter Ghysels . -mat_strumpack_compression_rel_tol          - Relative compression tolerance, when using `-pctype ilu`
102829e0a805SPieter Ghysels . -mat_strumpack_compression_abs_tol          - Absolute compression tolerance, when using `-pctype ilu`
102929e0a805SPieter Ghysels . -mat_strumpack_compression_min_sep_size     - Minimum size of separator for rank-structured compression, when using `-pctype ilu`
103029e0a805SPieter Ghysels . -mat_strumpack_compression_leaf_size        - Size of diagonal blocks in rank-structured approximation, when using `-pctype ilu`
103129e0a805SPieter Ghysels . -mat_strumpack_compression_lossy_precision  - Precision when using lossy compression [1-64], when using `-pctype ilu`, compression LOSSY (requires ZFP support)
103229e0a805SPieter Ghysels . -mat_strumpack_compression_butterfly_levels - Number of levels in the hierarchically off-diagonal matrix for which to use butterfly, when using `-pctype ilu`, (BLR_)HODLR compression (requires ButterflyPACK support)
103329e0a805SPieter Ghysels . -mat_strumpack_gpu                          - Enable GPU acceleration in numerical factorization (not supported for all compression types)
103429e0a805SPieter Ghysels . -mat_strumpack_colperm <TRUE>               - Permute matrix to make diagonal nonzeros
103529e0a805SPieter Ghysels . -mat_strumpack_reordering <METIS>           - Sparsity reducing matrix reordering (choose one of) NATURAL METIS PARMETIS SCOTCH PTSCOTCH RCM GEOMETRIC AMD MMD AND MLF SPECTRAL
103629e0a805SPieter Ghysels . -mat_strumpack_geometric_xyz <1,1,1>        - Mesh x,y,z dimensions, for use with GEOMETRIC ordering
103729e0a805SPieter Ghysels . -mat_strumpack_geometric_components <1>     - Number of components per mesh point, for geometric nested dissection ordering
103829e0a805SPieter Ghysels . -mat_strumpack_geometric_width <1>          - Width of the separator of the mesh, for geometric nested dissection ordering
103929e0a805SPieter Ghysels - -mat_strumpack_metis_nodeNDP                - Use METIS_NodeNDP instead of METIS_NodeND, for a more balanced tree
1040575704cbSPieter Ghysels 
1041575704cbSPieter Ghysels  Level: beginner
1042575704cbSPieter Ghysels 
1043*1d27aa22SBarry Smith  Notes:
1044*1d27aa22SBarry Smith  Recommended use is 1 MPI process per GPU.
1045*1d27aa22SBarry Smith 
1046*1d27aa22SBarry Smith  Use `-pc_type lu` `-pc_factor_mat_solver_type strumpack` to use this as an exact (direct) solver.
1047*1d27aa22SBarry Smith 
1048*1d27aa22SBarry Smith  Use `-pc_type ilu` `-pc_factor_mat_solver_type strumpack` to enable low-rank compression (i.e, use as a preconditioner), by default using block low rank (BLR).
1049*1d27aa22SBarry Smith 
1050*1d27aa22SBarry Smith  Works with `MATAIJ` matrices
1051*1d27aa22SBarry Smith 
105229e0a805SPieter Ghysels  HODLR, BLR_HODBF and ZFP_BLR_HODLR compression require STRUMPACK to be configured with ButterflyPACK support (`--download-butterflypack`).
105329e0a805SPieter Ghysels 
105429e0a805SPieter Ghysels  LOSSY, LOSSLESS and ZFP_BLR_HODLR compression require STRUMPACK to be configured with ZFP support (`--download-zfp`).
105529e0a805SPieter Ghysels 
1056*1d27aa22SBarry Smith .seealso: `MATSOLVERSTRUMPACK`, [](ch_matrices), `Mat`, `PCLU`, `PCILU`, `MATSOLVERSUPERLU_DIST`, `MATSOLVERMUMPS`, `PCFactorSetMatSolverType()`, `MatSolverType`,
105729e0a805SPieter Ghysels           `MatGetFactor()`, `MatSTRUMPACKSetReordering()`, `MatSTRUMPACKReordering`, `MatSTRUMPACKCompressionType`, `MatSTRUMPACKSetColPerm()`.
1058575704cbSPieter Ghysels M*/
1059d71ae5a4SJacob Faibussowitsch static PetscErrorCode MatGetFactor_aij_strumpack(Mat A, MatFactorType ftype, Mat *F)
1060d71ae5a4SJacob Faibussowitsch {
10617d6ea485SPieter Ghysels   Mat       B;
10627d6ea485SPieter Ghysels   PetscInt  M = A->rmap->N, N = A->cmap->N;
106329e0a805SPieter Ghysels   PetscBool verb, flg, set;
106429e0a805SPieter Ghysels   PetscReal ctol;
106529e0a805SPieter Ghysels   PetscInt  min_sep_size, leaf_size, nxyz[3], nrdims, nc, w;
106629e0a805SPieter Ghysels #if defined(STRUMPACK_USE_ZFP)
106729e0a805SPieter Ghysels   PetscInt lossy_prec;
106829e0a805SPieter Ghysels #endif
106929e0a805SPieter Ghysels #if defined(STRUMPACK_USE_BPACK)
107029e0a805SPieter Ghysels   PetscInt bfly_lvls;
107129e0a805SPieter Ghysels #endif
107229e0a805SPieter Ghysels #if defined(STRUMPACK_USE_SLATE_SCALAPACK)
107329e0a805SPieter Ghysels   PetscMPIInt mpithreads;
107429e0a805SPieter Ghysels #endif
107534f43fa5SPieter Ghysels   STRUMPACK_SparseSolver       *S;
107634f43fa5SPieter Ghysels   STRUMPACK_INTERFACE           iface;
107729e0a805SPieter Ghysels   STRUMPACK_REORDERING_STRATEGY ndcurrent, ndvalue;
107829e0a805SPieter Ghysels   STRUMPACK_COMPRESSION_TYPE    compcurrent, compvalue;
10799371c9d4SSatish Balay   const STRUMPACK_PRECISION     table[2][2][2] = {
10809371c9d4SSatish Balay     {{STRUMPACK_FLOATCOMPLEX_64, STRUMPACK_DOUBLECOMPLEX_64}, {STRUMPACK_FLOAT_64, STRUMPACK_DOUBLE_64}},
10819371c9d4SSatish Balay     {{STRUMPACK_FLOATCOMPLEX, STRUMPACK_DOUBLECOMPLEX},       {STRUMPACK_FLOAT, STRUMPACK_DOUBLE}      }
10829371c9d4SSatish Balay   };
10834ac6704cSBarry Smith   const STRUMPACK_PRECISION prec               = table[(sizeof(PetscInt) == 8) ? 0 : 1][(PETSC_SCALAR == PETSC_COMPLEX) ? 0 : 1][(PETSC_REAL == PETSC_FLOAT) ? 0 : 1];
108429e0a805SPieter Ghysels   const char *const         STRUMPACKNDTypes[] = {"NATURAL", "METIS", "PARMETIS", "SCOTCH", "PTSCOTCH", "RCM", "GEOMETRIC", "AMD", "MMD", "AND", "MLF", "SPECTRAL", "STRUMPACKNDTypes", "", 0};
108529e0a805SPieter Ghysels   const char *const         CompTypes[]        = {"NONE", "HSS", "BLR", "HODLR", "BLR_HODLR", "ZFP_BLR_HODLR", "LOSSLESS", "LOSSY", "CompTypes", "", 0};
10867d6ea485SPieter Ghysels 
10877d6ea485SPieter Ghysels   PetscFunctionBegin;
108829e0a805SPieter Ghysels #if defined(STRUMPACK_USE_SLATE_SCALAPACK)
108929e0a805SPieter Ghysels   PetscCallMPI(MPI_Query_thread(&mpithreads));
109029e0a805SPieter Ghysels   PetscCheck(mpithreads == MPI_THREAD_MULTIPLE, PetscObjectComm((PetscObject)A), PETSC_ERR_SUP_SYS, "SLATE requires MPI_THREAD_MULTIPLE");
109129e0a805SPieter Ghysels #endif
10927d6ea485SPieter Ghysels   /* Create the factorization matrix */
10939566063dSJacob Faibussowitsch   PetscCall(MatCreate(PetscObjectComm((PetscObject)A), &B));
10949566063dSJacob Faibussowitsch   PetscCall(MatSetSizes(B, A->rmap->n, A->cmap->n, M, N));
109535e8bcc9SJunchao Zhang   PetscCall(PetscStrallocpy("strumpack", &((PetscObject)B)->type_name));
109635e8bcc9SJunchao Zhang   PetscCall(MatSetUp(B));
109729e0a805SPieter Ghysels   PetscCall(MatSeqAIJSetPreallocation(B, 0, NULL));
109829e0a805SPieter Ghysels   PetscCall(MatMPIAIJSetPreallocation(B, 0, NULL, 0, NULL));
109966e17bc3SBarry Smith   B->trivialsymbolic = PETSC_TRUE;
1100575704cbSPieter Ghysels   if (ftype == MAT_FACTOR_LU || ftype == MAT_FACTOR_ILU) {
11017d6ea485SPieter Ghysels     B->ops->lufactorsymbolic  = MatLUFactorSymbolic_STRUMPACK;
1102575704cbSPieter Ghysels     B->ops->ilufactorsymbolic = MatLUFactorSymbolic_STRUMPACK;
1103575704cbSPieter Ghysels   } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "Factor type not supported");
110435e8bcc9SJunchao Zhang   B->ops->getinfo     = MatGetInfo_External;
11057d6ea485SPieter Ghysels   B->ops->view        = MatView_STRUMPACK;
11067d6ea485SPieter Ghysels   B->ops->destroy     = MatDestroy_STRUMPACK;
11077d6ea485SPieter Ghysels   B->ops->getdiagonal = MatGetDiagonal_STRUMPACK;
11089566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatFactorGetSolverType_C", MatFactorGetSolverType_aij_strumpack));
11099566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetReordering_C", MatSTRUMPACKSetReordering_STRUMPACK));
111029e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetReordering_C", MatSTRUMPACKGetReordering_STRUMPACK));
11119566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetColPerm_C", MatSTRUMPACKSetColPerm_STRUMPACK));
111229e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetColPerm_C", MatSTRUMPACKGetColPerm_STRUMPACK));
111329e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetGeometricNxyz_C", MatSTRUMPACKSetGeometricNxyz_STRUMPACK));
111429e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetGeometricComponents_C", MatSTRUMPACKSetGeometricComponents_STRUMPACK));
111529e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetGeometricWidth_C", MatSTRUMPACKSetGeometricWidth_STRUMPACK));
111629e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetGPU_C", MatSTRUMPACKSetGPU_STRUMPACK));
111729e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetGPU_C", MatSTRUMPACKGetGPU_STRUMPACK));
111829e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetCompression_C", MatSTRUMPACKSetCompression_STRUMPACK));
111929e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetCompression_C", MatSTRUMPACKGetCompression_STRUMPACK));
112029e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetCompRelTol_C", MatSTRUMPACKSetCompRelTol_STRUMPACK));
112129e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetCompRelTol_C", MatSTRUMPACKGetCompRelTol_STRUMPACK));
112229e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetCompAbsTol_C", MatSTRUMPACKSetCompAbsTol_STRUMPACK));
112329e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetCompAbsTol_C", MatSTRUMPACKGetCompAbsTol_STRUMPACK));
112429e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetCompLeafSize_C", MatSTRUMPACKSetCompLeafSize_STRUMPACK));
112529e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetCompLeafSize_C", MatSTRUMPACKGetCompLeafSize_STRUMPACK));
112629e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetCompMinSepSize_C", MatSTRUMPACKSetCompMinSepSize_STRUMPACK));
112729e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetCompMinSepSize_C", MatSTRUMPACKGetCompMinSepSize_STRUMPACK));
112829e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetCompLossyPrecision_C", MatSTRUMPACKSetCompLossyPrecision_STRUMPACK));
112929e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetCompLossyPrecision_C", MatSTRUMPACKGetCompLossyPrecision_STRUMPACK));
113029e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKSetCompButterflyLevels_C", MatSTRUMPACKSetCompButterflyLevels_STRUMPACK));
113129e0a805SPieter Ghysels   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatSTRUMPACKGetCompButterflyLevels_C", MatSTRUMPACKGetCompButterflyLevels_STRUMPACK));
1132575704cbSPieter Ghysels   B->factortype = ftype;
113329e0a805SPieter Ghysels 
113429e0a805SPieter Ghysels   /* set solvertype */
113529e0a805SPieter Ghysels   PetscCall(PetscFree(B->solvertype));
113629e0a805SPieter Ghysels   PetscCall(PetscStrallocpy(MATSOLVERSTRUMPACK, &B->solvertype));
113729e0a805SPieter Ghysels 
11384dfa11a4SJacob Faibussowitsch   PetscCall(PetscNew(&S));
113935e8bcc9SJunchao Zhang   B->data = S;
11400d08a34dSPieter Ghysels 
114135e8bcc9SJunchao Zhang   PetscCall(PetscObjectBaseTypeCompare((PetscObject)A, MATSEQAIJ, &flg)); /* A might be MATSEQAIJCUSPARSE */
11420d08a34dSPieter Ghysels   iface = flg ? STRUMPACK_MT : STRUMPACK_MPI_DIST;
11437d6ea485SPieter Ghysels 
114426cc229bSBarry Smith   PetscOptionsBegin(PetscObjectComm((PetscObject)B), ((PetscObject)B)->prefix, "STRUMPACK Options", "Mat");
1145575704cbSPieter Ghysels   verb = PetscLogPrintInfo ? PETSC_TRUE : PETSC_FALSE;
11469566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBool("-mat_strumpack_verbose", "Print STRUMPACK information", "None", verb, &verb, NULL));
11477d6ea485SPieter Ghysels 
1148e77caa6dSBarry Smith   PetscStackCallExternalVoid("STRUMPACK_init", STRUMPACK_init(S, PetscObjectComm((PetscObject)A), prec, iface, 0, NULL, verb));
114955c022e5SPieter Ghysels 
115029e0a805SPieter Ghysels   /* By default, no compression is done. Compression is enabled when the user enables it with        */
115129e0a805SPieter Ghysels   /*  -mat_strumpack_compression with anything else than NONE, or when selecting ilu                 */
115229e0a805SPieter Ghysels   /* preconditioning, in which case we default to STRUMPACK_BLR compression.                         */
115329e0a805SPieter Ghysels   /* When compression is enabled, the STRUMPACK solver becomes an incomplete                         */
115488382b05SPieter Ghysels   /* (or approximate) LU factorization.                                                              */
115529e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression", compcurrent = STRUMPACK_compression(*S));
115629e0a805SPieter Ghysels   PetscCall(PetscOptionsEnum("-mat_strumpack_compression", "Rank-structured compression type", "None", CompTypes, (PetscEnum)compcurrent, (PetscEnum *)&compvalue, &set));
115729e0a805SPieter Ghysels   if (set) {
115829e0a805SPieter Ghysels     PetscCall(MatSTRUMPACKSetCompression(B, (MatSTRUMPACKCompressionType)compvalue));
115929e0a805SPieter Ghysels   } else {
116029e0a805SPieter Ghysels     if (ftype == MAT_FACTOR_ILU) { PetscStackCallExternalVoid("STRUMPACK_set_compression", STRUMPACK_set_compression(*S, STRUMPACK_BLR)); }
116188382b05SPieter Ghysels   }
116255c022e5SPieter Ghysels 
116329e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_rel_tol", ctol = (PetscReal)STRUMPACK_compression_rel_tol(*S));
116429e0a805SPieter Ghysels   PetscCall(PetscOptionsReal("-mat_strumpack_compression_rel_tol", "Relative compression tolerance", "None", ctol, &ctol, &set));
116529e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_compression_rel_tol", STRUMPACK_set_compression_rel_tol(*S, (double)ctol));
116629e0a805SPieter Ghysels 
116729e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_abs_tol", ctol = (PetscReal)STRUMPACK_compression_abs_tol(*S));
116829e0a805SPieter Ghysels   PetscCall(PetscOptionsReal("-mat_strumpack_compression_abs_tol", "Absolute compression tolerance", "None", ctol, &ctol, &set));
116929e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_compression_abs_tol", STRUMPACK_set_compression_abs_tol(*S, (double)ctol));
117029e0a805SPieter Ghysels 
117129e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_min_sep_size", min_sep_size = (PetscInt)STRUMPACK_compression_min_sep_size(*S));
117229e0a805SPieter Ghysels   PetscCall(PetscOptionsInt("-mat_strumpack_compression_min_sep_size", "Minimum size of separator for compression", "None", min_sep_size, &min_sep_size, &set));
117329e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_compression_min_sep_size", STRUMPACK_set_compression_min_sep_size(*S, (int)min_sep_size));
117429e0a805SPieter Ghysels 
117529e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_leaf_size", leaf_size = (PetscInt)STRUMPACK_compression_leaf_size(*S));
117629e0a805SPieter Ghysels   PetscCall(PetscOptionsInt("-mat_strumpack_compression_leaf_size", "Size of diagonal blocks in rank-structured approximation", "None", leaf_size, &leaf_size, &set));
117729e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_compression_leaf_size", STRUMPACK_set_compression_leaf_size(*S, (int)leaf_size));
117829e0a805SPieter Ghysels 
117929e0a805SPieter Ghysels #if defined(STRUMPACK_USE_ZFP)
118029e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_lossy_precision", lossy_prec = (PetscInt)STRUMPACK_compression_lossy_precision(*S));
118129e0a805SPieter Ghysels   PetscCall(PetscOptionsInt("-mat_strumpack_compression_lossy_precision", "Number of bitplanes to use in lossy compression", "None", lossy_prec, &lossy_prec, &set));
118229e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_compression_lossy_precision", STRUMPACK_set_compression_lossy_precision(*S, (int)lossy_prec));
118329e0a805SPieter Ghysels #endif
118429e0a805SPieter Ghysels 
118529e0a805SPieter Ghysels #if defined(STRUMPACK_USE_BPACK)
118629e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_compression_butterfly_levels", bfly_lvls = (PetscInt)STRUMPACK_compression_butterfly_levels(*S));
118729e0a805SPieter Ghysels   PetscCall(PetscOptionsInt("-mat_strumpack_compression_butterfly_levels", "Number of levels in the HODLR matrix for which to use butterfly compression", "None", bfly_lvls, &bfly_lvls, &set));
118829e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_compression_butterfly_levels", STRUMPACK_set_compression_butterfly_levels(*S, (int)bfly_lvls));
118929e0a805SPieter Ghysels #endif
119029e0a805SPieter Ghysels 
119129e0a805SPieter Ghysels #if defined(STRUMPACK_USE_CUDA) || defined(STRUMPACK_USE_HIP) || defined(STRUMPACK_USE_SYCL)
119229e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_use_gpu", flg = (STRUMPACK_use_gpu(*S) == 0) ? PETSC_FALSE : PETSC_TRUE);
119329e0a805SPieter Ghysels   PetscCall(PetscOptionsBool("-mat_strumpack_gpu", "Enable GPU acceleration (not supported for all compression types)", "None", flg, &flg, &set));
119429e0a805SPieter Ghysels   if (set) MatSTRUMPACKSetGPU(B, flg);
119529e0a805SPieter Ghysels #endif
119629e0a805SPieter Ghysels 
119729e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_matching", flg = (STRUMPACK_matching(*S) == STRUMPACK_MATCHING_NONE) ? PETSC_FALSE : PETSC_TRUE);
119829e0a805SPieter Ghysels   PetscCall(PetscOptionsBool("-mat_strumpack_colperm", "Find a col perm to get nonzero diagonal", "None", flg, &flg, &set));
119929e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_matching", STRUMPACK_set_matching(*S, flg ? STRUMPACK_MATCHING_MAX_DIAGONAL_PRODUCT_SCALING : STRUMPACK_MATCHING_NONE));
120029e0a805SPieter Ghysels 
120129e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_reordering_method", ndcurrent = STRUMPACK_reordering_method(*S));
120229e0a805SPieter Ghysels   PetscCall(PetscOptionsEnum("-mat_strumpack_reordering", "Sparsity reducing matrix reordering", "None", STRUMPACKNDTypes, (PetscEnum)ndcurrent, (PetscEnum *)&ndvalue, &set));
120329e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_reordering_method", STRUMPACK_set_reordering_method(*S, ndvalue));
120429e0a805SPieter Ghysels 
120529e0a805SPieter Ghysels   /* geometric ordering, for a regular 1D/2D/3D mesh in the natural ordering, */
120629e0a805SPieter Ghysels   /* with nc DOF's per gridpoint, and possibly a wider stencil                */
120729e0a805SPieter Ghysels   nrdims  = 3;
120829e0a805SPieter Ghysels   nxyz[0] = nxyz[1] = nxyz[2] = 1;
120929e0a805SPieter Ghysels   PetscCall(PetscOptionsIntArray("-mat_strumpack_geometric_xyz", "Mesh sizes nx,ny,nz (Use 1 for default)", "", nxyz, &nrdims, &set));
121029e0a805SPieter Ghysels   if (set) {
121129e0a805SPieter Ghysels     PetscCheck(nrdims == 1 || nrdims == 2 || nrdims == 3, PetscObjectComm((PetscObject)F), PETSC_ERR_ARG_OUTOFRANGE, "'-mat_strumpack_geometric_xyz' requires 1, 2, or 3 values.");
121229e0a805SPieter Ghysels     PetscCall(MatSTRUMPACKSetGeometricNxyz(B, (int)nxyz[0], (int)nxyz[1], (int)nxyz[2]));
121329e0a805SPieter Ghysels   }
121429e0a805SPieter Ghysels   PetscCall(PetscOptionsInt("-mat_strumpack_geometric_components", "Number of components per mesh point, for geometric nested dissection ordering", "None", 1, &nc, &set));
121529e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_components", STRUMPACK_set_components(*S, (int)nc));
121629e0a805SPieter Ghysels   PetscCall(PetscOptionsInt("-mat_strumpack_geometric_width", "Width of the separator (for instance a 1D 3-point wide stencil needs a 1 point wide separator, a 1D 5-point stencil needs a 2 point wide separator), for geometric nested dissection ordering", "None", 1, &w, &set));
121729e0a805SPieter Ghysels   if (set) PetscStackCallExternalVoid("STRUMPACK_set_separator_width", STRUMPACK_set_separator_width(*S, (int)w));
121829e0a805SPieter Ghysels 
121929e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_use_METIS_NodeNDP", flg = (STRUMPACK_use_METIS_NodeNDP(*S) == 0) ? PETSC_FALSE : PETSC_TRUE);
122029e0a805SPieter Ghysels   PetscCall(PetscOptionsBool("-mat_strumpack_metis_nodeNDP", "Use METIS_NodeNDP instead of METIS_NodeND, for a more balanced tree", "None", flg, &flg, &set));
122129e0a805SPieter Ghysels   if (set) {
122229e0a805SPieter Ghysels     if (flg) {
122329e0a805SPieter Ghysels       PetscStackCallExternalVoid("STRUMPACK_enable_METIS_NodeNDP", STRUMPACK_enable_METIS_NodeNDP(*S));
122429e0a805SPieter Ghysels     } else {
122529e0a805SPieter Ghysels       PetscStackCallExternalVoid("STRUMPACK_disable_METIS_NodeNDP", STRUMPACK_disable_METIS_NodeNDP(*S));
122629e0a805SPieter Ghysels     }
122729e0a805SPieter Ghysels   }
122829e0a805SPieter Ghysels 
122929e0a805SPieter Ghysels   /* Disable the outer iterative solver from STRUMPACK.                                       */
123029e0a805SPieter Ghysels   /* When STRUMPACK is used as a direct solver, it will by default do iterative refinement.   */
123129e0a805SPieter Ghysels   /* When STRUMPACK is used as an approximate factorization preconditioner (by enabling       */
123229e0a805SPieter Ghysels   /* low-rank compression), it will use it's own preconditioned GMRES. Here we can disable    */
123329e0a805SPieter Ghysels   /* the outer iterative solver, as PETSc uses STRUMPACK from within a KSP.                   */
123429e0a805SPieter Ghysels   PetscStackCallExternalVoid("STRUMPACK_set_Krylov_solver", STRUMPACK_set_Krylov_solver(*S, STRUMPACK_DIRECT));
123529e0a805SPieter Ghysels 
123629e0a805SPieter Ghysels   PetscOptionsEnd();
123726cc229bSBarry Smith 
12387d6ea485SPieter Ghysels   *F = B;
12393ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
12407d6ea485SPieter Ghysels }
12417d6ea485SPieter Ghysels 
1242d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MatSolverTypeRegister_STRUMPACK(void)
1243d71ae5a4SJacob Faibussowitsch {
12447d6ea485SPieter Ghysels   PetscFunctionBegin;
12459566063dSJacob Faibussowitsch   PetscCall(MatSolverTypeRegister(MATSOLVERSTRUMPACK, MATMPIAIJ, MAT_FACTOR_LU, MatGetFactor_aij_strumpack));
12469566063dSJacob Faibussowitsch   PetscCall(MatSolverTypeRegister(MATSOLVERSTRUMPACK, MATSEQAIJ, MAT_FACTOR_LU, MatGetFactor_aij_strumpack));
12479566063dSJacob Faibussowitsch   PetscCall(MatSolverTypeRegister(MATSOLVERSTRUMPACK, MATMPIAIJ, MAT_FACTOR_ILU, MatGetFactor_aij_strumpack));
12489566063dSJacob Faibussowitsch   PetscCall(MatSolverTypeRegister(MATSOLVERSTRUMPACK, MATSEQAIJ, MAT_FACTOR_ILU, MatGetFactor_aij_strumpack));
12493ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
12507d6ea485SPieter Ghysels }
1251