xref: /petsc/src/mat/impls/aij/mpi/superlu_dist/superlu_dist.c (revision 00a402e09c6d62f19dbf72eef0e53394ab690d5c)
1 
2 /*
3         Provides an interface to the SuperLU_DIST sparse solver
4 */
5 
6 #include <../src/mat/impls/aij/seq/aij.h>
7 #include <../src/mat/impls/aij/mpi/mpiaij.h>
8 #if defined(PETSC_HAVE_STDLIB_H) /* This is to get around weird problem with SuperLU on cray */
9 #include <stdlib.h>
10 #endif
11 
12 EXTERN_C_BEGIN
13 #if defined(PETSC_USE_COMPLEX)
14 #include <superlu_zdefs.h>
15 #else
16 #include <superlu_ddefs.h>
17 #endif
18 EXTERN_C_END
19 
20 /*
21     GLOBAL - The sparse matrix and right hand side are all stored initially on process 0. Should be called centralized
22     DISTRIBUTED - The sparse matrix and right hand size are initially stored across the entire MPI communicator.
23 */
24 typedef enum {GLOBAL,DISTRIBUTED} SuperLU_MatInputMode;
25 const char *SuperLU_MatInputModes[] = {"GLOBAL","DISTRIBUTED","SuperLU_MatInputMode","PETSC_",0};
26 
27 typedef struct {
28   int_t                  nprow,npcol,*row,*col;
29   gridinfo_t             grid;
30   superlu_dist_options_t options;
31   SuperMatrix            A_sup;
32   ScalePermstruct_t      ScalePermstruct;
33   LUstruct_t             LUstruct;
34   int                    StatPrint;
35   SuperLU_MatInputMode   MatInputMode;
36   SOLVEstruct_t          SOLVEstruct;
37   fact_t                 FactPattern;
38   MPI_Comm               comm_superlu;
39 #if defined(PETSC_USE_COMPLEX)
40   doublecomplex          *val;
41 #else
42   double                 *val;
43 #endif
44   PetscBool              matsolve_iscalled,matmatsolve_iscalled;
45   PetscBool              CleanUpSuperLU_Dist;  /* Flag to clean up (non-global) SuperLU objects during Destroy */
46 } Mat_SuperLU_DIST;
47 
48 
49 PetscErrorCode MatSuperluDistGetDiagU_SuperLU_DIST(Mat F,PetscScalar *diagU)
50 {
51   Mat_SuperLU_DIST  *lu= (Mat_SuperLU_DIST*)F->data;
52 
53   PetscFunctionBegin;
54 #if defined(PETSC_USE_COMPLEX)
55   PetscStackCall("SuperLU_DIST:pzGetDiagU",pzGetDiagU(F->rmap->N,&lu->LUstruct,&lu->grid,(doublecomplex*)diagU));
56 #else
57   PetscStackCall("SuperLU_DIST:pdGetDiagU",pdGetDiagU(F->rmap->N,&lu->LUstruct,&lu->grid,diagU));
58 #endif
59   PetscFunctionReturn(0);
60 }
61 
62 PetscErrorCode MatSuperluDistGetDiagU(Mat F,PetscScalar *diagU)
63 {
64   PetscErrorCode    ierr;
65 
66   PetscFunctionBegin;
67   PetscValidHeaderSpecific(F,MAT_CLASSID,1);
68   ierr = PetscTryMethod(F,"MatSuperluDistGetDiagU_C",(Mat,PetscScalar*),(F,diagU));CHKERRQ(ierr);
69   PetscFunctionReturn(0);
70 }
71 
72 static PetscErrorCode MatDestroy_SuperLU_DIST(Mat A)
73 {
74   PetscErrorCode   ierr;
75   Mat_SuperLU_DIST *lu = (Mat_SuperLU_DIST*)A->data;
76 
77   PetscFunctionBegin;
78   if (lu->CleanUpSuperLU_Dist) {
79     /* Deallocate SuperLU_DIST storage */
80     if (lu->MatInputMode == GLOBAL) {
81       PetscStackCall("SuperLU_DIST:Destroy_CompCol_Matrix_dist",Destroy_CompCol_Matrix_dist(&lu->A_sup));
82     } else {
83       PetscStackCall("SuperLU_DIST:Destroy_CompRowLoc_Matrix_dist",Destroy_CompRowLoc_Matrix_dist(&lu->A_sup));
84       if (lu->options.SolveInitialized) {
85 #if defined(PETSC_USE_COMPLEX)
86         PetscStackCall("SuperLU_DIST:zSolveFinalize",zSolveFinalize(&lu->options, &lu->SOLVEstruct));
87 #else
88         PetscStackCall("SuperLU_DIST:dSolveFinalize",dSolveFinalize(&lu->options, &lu->SOLVEstruct));
89 #endif
90       }
91     }
92     PetscStackCall("SuperLU_DIST:Destroy_LU",Destroy_LU(A->cmap->N, &lu->grid, &lu->LUstruct));
93     PetscStackCall("SuperLU_DIST:ScalePermstructFree",ScalePermstructFree(&lu->ScalePermstruct));
94     PetscStackCall("SuperLU_DIST:LUstructFree",LUstructFree(&lu->LUstruct));
95 
96     /* Release the SuperLU_DIST process grid. */
97     PetscStackCall("SuperLU_DIST:superlu_gridexit",superlu_gridexit(&lu->grid));
98     ierr = MPI_Comm_free(&(lu->comm_superlu));CHKERRQ(ierr);
99   }
100   ierr = PetscFree(A->data);CHKERRQ(ierr);
101   /* clear composed functions */
102   ierr = PetscObjectComposeFunction((PetscObject)A,"MatFactorGetSolverType_C",NULL);CHKERRQ(ierr);
103   ierr = PetscObjectComposeFunction((PetscObject)A,"MatSuperluDistGetDiagU_C",NULL);CHKERRQ(ierr);
104 
105   PetscFunctionReturn(0);
106 }
107 
108 static PetscErrorCode MatSolve_SuperLU_DIST(Mat A,Vec b_mpi,Vec x)
109 {
110   Mat_SuperLU_DIST *lu = (Mat_SuperLU_DIST*)A->data;
111   PetscErrorCode   ierr;
112   PetscMPIInt      size;
113   PetscInt         m=A->rmap->n,M=A->rmap->N,N=A->cmap->N;
114   SuperLUStat_t    stat;
115   double           berr[1];
116   PetscScalar      *bptr=NULL;
117   PetscInt         nrhs=1;
118   Vec              x_seq;
119   IS               iden;
120   VecScatter       scat;
121   int              info; /* SuperLU_Dist info code is ALWAYS an int, even with long long indices */
122   static PetscBool cite = PETSC_FALSE;
123 
124   PetscFunctionBegin;
125   if (lu->options.Fact != FACTORED) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"SuperLU_DIST options.Fact mush equal FACTORED");
126   ierr = PetscCitationsRegister("@article{lidemmel03,\n  author = {Xiaoye S. Li and James W. Demmel},\n  title = {{SuperLU_DIST}: A Scalable Distributed-Memory Sparse Direct\n           Solver for Unsymmetric Linear Systems},\n  journal = {ACM Trans. Mathematical Software},\n  volume = {29},\n  number = {2},\n  pages = {110-140},\n  year = 2003\n}\n",&cite);CHKERRQ(ierr);
127 
128   ierr = MPI_Comm_size(PetscObjectComm((PetscObject)A),&size);CHKERRQ(ierr);
129   if (size > 1 && lu->MatInputMode == GLOBAL) {
130     /* global mat input, convert b to x_seq */
131     ierr = VecCreateSeq(PETSC_COMM_SELF,N,&x_seq);CHKERRQ(ierr);
132     ierr = ISCreateStride(PETSC_COMM_SELF,N,0,1,&iden);CHKERRQ(ierr);
133     ierr = VecScatterCreate(b_mpi,iden,x_seq,iden,&scat);CHKERRQ(ierr);
134     ierr = ISDestroy(&iden);CHKERRQ(ierr);
135 
136     ierr = VecScatterBegin(scat,b_mpi,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
137     ierr = VecScatterEnd(scat,b_mpi,x_seq,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr);
138     ierr = VecGetArray(x_seq,&bptr);CHKERRQ(ierr);
139   } else { /* size==1 || distributed mat input */
140     if (lu->options.SolveInitialized && !lu->matsolve_iscalled) {
141       /* see comments in MatMatSolve() */
142 #if defined(PETSC_USE_COMPLEX)
143       PetscStackCall("SuperLU_DIST:zSolveFinalize",zSolveFinalize(&lu->options, &lu->SOLVEstruct));
144 #else
145       PetscStackCall("SuperLU_DIST:dSolveFinalize",dSolveFinalize(&lu->options, &lu->SOLVEstruct));
146 #endif
147       lu->options.SolveInitialized = NO;
148     }
149     ierr = VecCopy(b_mpi,x);CHKERRQ(ierr);
150     ierr = VecGetArray(x,&bptr);CHKERRQ(ierr);
151   }
152 
153   PetscStackCall("SuperLU_DIST:PStatInit",PStatInit(&stat));        /* Initialize the statistics variables. */
154   if (lu->MatInputMode == GLOBAL) {
155 #if defined(PETSC_USE_COMPLEX)
156     PetscStackCall("SuperLU_DIST:pzgssvx_ABglobal",pzgssvx_ABglobal(&lu->options,&lu->A_sup,&lu->ScalePermstruct,(doublecomplex*)bptr,M,nrhs,&lu->grid,&lu->LUstruct,berr,&stat,&info));
157 #else
158     PetscStackCall("SuperLU_DIST:pdgssvx_ABglobal",pdgssvx_ABglobal(&lu->options, &lu->A_sup, &lu->ScalePermstruct,bptr,M,nrhs,&lu->grid,&lu->LUstruct,berr,&stat,&info));
159 #endif
160   } else { /* distributed mat input */
161 #if defined(PETSC_USE_COMPLEX)
162     PetscStackCall("SuperLU_DIST:pzgssvx",pzgssvx(&lu->options,&lu->A_sup,&lu->ScalePermstruct,(doublecomplex*)bptr,m,nrhs,&lu->grid,&lu->LUstruct,&lu->SOLVEstruct,berr,&stat,&info));
163 #else
164     PetscStackCall("SuperLU_DIST:pdgssvx",pdgssvx(&lu->options,&lu->A_sup,&lu->ScalePermstruct,bptr,m,nrhs,&lu->grid,&lu->LUstruct,&lu->SOLVEstruct,berr,&stat,&info));
165 #endif
166   }
167   if (info) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"pdgssvx fails, info: %d\n",info);
168 
169   if (lu->options.PrintStat) PStatPrint(&lu->options, &stat, &lu->grid);      /* Print the statistics. */
170   PetscStackCall("SuperLU_DIST:PStatFree",PStatFree(&stat));
171 
172   if (size > 1 && lu->MatInputMode == GLOBAL) {
173     /* convert seq x to mpi x */
174     ierr = VecRestoreArray(x_seq,&bptr);CHKERRQ(ierr);
175     ierr = VecScatterBegin(scat,x_seq,x,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr);
176     ierr = VecScatterEnd(scat,x_seq,x,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr);
177     ierr = VecScatterDestroy(&scat);CHKERRQ(ierr);
178     ierr = VecDestroy(&x_seq);CHKERRQ(ierr);
179   } else {
180     ierr = VecRestoreArray(x,&bptr);CHKERRQ(ierr);
181 
182     lu->matsolve_iscalled    = PETSC_TRUE;
183     lu->matmatsolve_iscalled = PETSC_FALSE;
184   }
185   PetscFunctionReturn(0);
186 }
187 
188 static PetscErrorCode MatMatSolve_SuperLU_DIST(Mat A,Mat B_mpi,Mat X)
189 {
190   Mat_SuperLU_DIST *lu = (Mat_SuperLU_DIST*)A->data;
191   PetscErrorCode   ierr;
192   PetscMPIInt      size;
193   PetscInt         M=A->rmap->N,m=A->rmap->n,nrhs;
194   SuperLUStat_t    stat;
195   double           berr[1];
196   PetscScalar      *bptr;
197   int              info; /* SuperLU_Dist info code is ALWAYS an int, even with long long indices */
198   PetscBool        flg;
199 
200   PetscFunctionBegin;
201   if (lu->options.Fact != FACTORED) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"SuperLU_DIST options.Fact mush equal FACTORED");
202   ierr = PetscObjectTypeCompareAny((PetscObject)B_mpi,&flg,MATSEQDENSE,MATMPIDENSE,NULL);CHKERRQ(ierr);
203   if (!flg) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_ARG_WRONG,"Matrix B must be MATDENSE matrix");
204   ierr = PetscObjectTypeCompareAny((PetscObject)X,&flg,MATSEQDENSE,MATMPIDENSE,NULL);CHKERRQ(ierr);
205   if (!flg) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_ARG_WRONG,"Matrix X must be MATDENSE matrix");
206 
207   ierr = MPI_Comm_size(PetscObjectComm((PetscObject)A),&size);CHKERRQ(ierr);
208   if (size > 1 && lu->MatInputMode == GLOBAL) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"MatInputMode=GLOBAL for nproc %d>1 is not supported",size);
209   /* size==1 or distributed mat input */
210   if (lu->options.SolveInitialized && !lu->matmatsolve_iscalled) {
211     /* communication pattern of SOLVEstruct is unlikely created for matmatsolve,
212        thus destroy it and create a new SOLVEstruct.
213        Otherwise it may result in memory corruption or incorrect solution
214        See src/mat/examples/tests/ex125.c */
215 #if defined(PETSC_USE_COMPLEX)
216     PetscStackCall("SuperLU_DIST:zSolveFinalize",zSolveFinalize(&lu->options, &lu->SOLVEstruct));
217 #else
218     PetscStackCall("SuperLU_DIST:dSolveFinalize",dSolveFinalize(&lu->options, &lu->SOLVEstruct));
219 #endif
220     lu->options.SolveInitialized = NO;
221   }
222   ierr = MatCopy(B_mpi,X,SAME_NONZERO_PATTERN);CHKERRQ(ierr);
223 
224   ierr = MatGetSize(B_mpi,NULL,&nrhs);CHKERRQ(ierr);
225 
226   PetscStackCall("SuperLU_DIST:PStatInit",PStatInit(&stat));        /* Initialize the statistics variables. */
227   ierr = MatDenseGetArray(X,&bptr);CHKERRQ(ierr);
228   if (lu->MatInputMode == GLOBAL) { /* size == 1 */
229 #if defined(PETSC_USE_COMPLEX)
230     PetscStackCall("SuperLU_DIST:pzgssvx_ABglobal",pzgssvx_ABglobal(&lu->options, &lu->A_sup, &lu->ScalePermstruct,(doublecomplex*)bptr, M, nrhs,&lu->grid, &lu->LUstruct, berr, &stat, &info));
231 #else
232     PetscStackCall("SuperLU_DIST:pdgssvx_ABglobal",pdgssvx_ABglobal(&lu->options, &lu->A_sup, &lu->ScalePermstruct,bptr, M, nrhs, &lu->grid, &lu->LUstruct, berr, &stat, &info));
233 #endif
234   } else { /* distributed mat input */
235 #if defined(PETSC_USE_COMPLEX)
236     PetscStackCall("SuperLU_DIST:pzgssvx",pzgssvx(&lu->options,&lu->A_sup,&lu->ScalePermstruct,(doublecomplex*)bptr,m,nrhs,&lu->grid, &lu->LUstruct,&lu->SOLVEstruct,berr,&stat,&info));
237 #else
238     PetscStackCall("SuperLU_DIST:pdgssvx",pdgssvx(&lu->options,&lu->A_sup,&lu->ScalePermstruct,bptr,m,nrhs,&lu->grid,&lu->LUstruct,&lu->SOLVEstruct,berr,&stat,&info));
239 #endif
240   }
241   if (info) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"pdgssvx fails, info: %d\n",info);
242   ierr = MatDenseRestoreArray(X,&bptr);CHKERRQ(ierr);
243 
244   if (lu->options.PrintStat) PStatPrint(&lu->options, &stat, &lu->grid); /* Print the statistics. */
245   PetscStackCall("SuperLU_DIST:PStatFree",PStatFree(&stat));
246   lu->matsolve_iscalled    = PETSC_FALSE;
247   lu->matmatsolve_iscalled = PETSC_TRUE;
248   PetscFunctionReturn(0);
249 }
250 
251 /*
252   input:
253    F:        numeric Cholesky factor
254   output:
255    nneg:     total number of negative pivots
256    nzero:    total number of zero pivots
257    npos:     (global dimension of F) - nneg - nzero
258 */
259 static PetscErrorCode MatGetInertia_SuperLU_DIST(Mat F,PetscInt *nneg,PetscInt *nzero,PetscInt *npos)
260 {
261   PetscErrorCode   ierr;
262   Mat_SuperLU_DIST *lu = (Mat_SuperLU_DIST*)F->data;
263   PetscScalar      *diagU=NULL;
264   PetscInt         M,i,neg=0,zero=0,pos=0;
265   PetscReal        r;
266 
267   PetscFunctionBegin;
268   if (!F->assembled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Matrix factor F is not assembled");
269   if (lu->options.RowPerm != NOROWPERM) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must set NOROWPERM");
270   ierr = MatGetSize(F,&M,NULL);CHKERRQ(ierr);
271   ierr = PetscMalloc1(M,&diagU);CHKERRQ(ierr);
272   ierr = MatSuperluDistGetDiagU(F,diagU);CHKERRQ(ierr);
273   for (i=0; i<M; i++) {
274 #if defined(PETSC_USE_COMPLEX)
275     r = PetscImaginaryPart(diagU[i])/10.0;
276     if (r< -PETSC_MACHINE_EPSILON || r>PETSC_MACHINE_EPSILON) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"diagU[%d]=%g + i %g is non-real",i,PetscRealPart(diagU[i]),r*10.0);
277     r = PetscRealPart(diagU[i]);
278 #else
279     r = diagU[i];
280 #endif
281     if (r > 0) {
282       pos++;
283     } else if (r < 0) {
284       neg++;
285     } else zero++;
286   }
287 
288   ierr = PetscFree(diagU);CHKERRQ(ierr);
289   if (nneg)  *nneg  = neg;
290   if (nzero) *nzero = zero;
291   if (npos)  *npos  = pos;
292   PetscFunctionReturn(0);
293 }
294 
295 static PetscErrorCode MatLUFactorNumeric_SuperLU_DIST(Mat F,Mat A,const MatFactorInfo *info)
296 {
297   Mat              *tseq,A_seq = NULL;
298   Mat_SeqAIJ       *aa,*bb;
299   Mat_SuperLU_DIST *lu = (Mat_SuperLU_DIST*)F->data;
300   PetscErrorCode   ierr;
301   PetscInt         M=A->rmap->N,N=A->cmap->N,i,*ai,*aj,*bi,*bj,nz,rstart,*garray,
302                    m=A->rmap->n, colA_start,j,jcol,jB,countA,countB,*bjj,*ajj=NULL;
303   int              sinfo;   /* SuperLU_Dist info flag is always an int even with long long indices */
304   PetscMPIInt      size;
305   SuperLUStat_t    stat;
306   double           *berr=0;
307   IS               isrow;
308 #if defined(PETSC_USE_COMPLEX)
309   doublecomplex    *av, *bv;
310 #else
311   double           *av, *bv;
312 #endif
313 
314   PetscFunctionBegin;
315   ierr = MPI_Comm_size(PetscObjectComm((PetscObject)A),&size);CHKERRQ(ierr);
316 
317   if (lu->MatInputMode == GLOBAL) { /* global mat input */
318     if (size > 1) { /* convert mpi A to seq mat A */
319       ierr = ISCreateStride(PETSC_COMM_SELF,M,0,1,&isrow);CHKERRQ(ierr);
320       ierr = MatCreateSubMatrices(A,1,&isrow,&isrow,MAT_INITIAL_MATRIX,&tseq);CHKERRQ(ierr);
321       ierr = ISDestroy(&isrow);CHKERRQ(ierr);
322 
323       A_seq = *tseq;
324       ierr  = PetscFree(tseq);CHKERRQ(ierr);
325       aa    = (Mat_SeqAIJ*)A_seq->data;
326     } else {
327       PetscBool flg;
328       ierr = PetscObjectTypeCompare((PetscObject)A,MATMPIAIJ,&flg);CHKERRQ(ierr);
329       if (flg) {
330         Mat_MPIAIJ *At = (Mat_MPIAIJ*)A->data;
331         A = At->A;
332       }
333       aa =  (Mat_SeqAIJ*)A->data;
334     }
335 
336     /* Convert Petsc NR matrix to SuperLU_DIST NC.
337        Note: memories of lu->val, col and row are allocated by CompRow_to_CompCol_dist()! */
338     if (lu->options.Fact != DOFACT) {/* successive numeric factorization, sparsity pattern is reused. */
339       PetscStackCall("SuperLU_DIST:Destroy_CompCol_Matrix_dist",Destroy_CompCol_Matrix_dist(&lu->A_sup));
340       if (lu->FactPattern == SamePattern_SameRowPerm) {
341         lu->options.Fact = SamePattern_SameRowPerm; /* matrix has similar numerical values */
342       } else { /* lu->FactPattern == SamePattern */
343         PetscStackCall("SuperLU_DIST:Destroy_LU",Destroy_LU(N, &lu->grid, &lu->LUstruct));
344         lu->options.Fact = SamePattern;
345       }
346     }
347 #if defined(PETSC_USE_COMPLEX)
348     PetscStackCall("SuperLU_DIST:zCompRow_to_CompCol_dist",zCompRow_to_CompCol_dist(M,N,aa->nz,(doublecomplex*)aa->a,(int_t*)aa->j,(int_t*)aa->i,&lu->val,&lu->col, &lu->row));
349 #else
350     PetscStackCall("SuperLU_DIST:dCompRow_to_CompCol_dist",dCompRow_to_CompCol_dist(M,N,aa->nz,aa->a,(int_t*)aa->j,(int_t*)aa->i,&lu->val, &lu->col, &lu->row));
351 #endif
352 
353     /* Create compressed column matrix A_sup. */
354 #if defined(PETSC_USE_COMPLEX)
355     PetscStackCall("SuperLU_DIST:zCreate_CompCol_Matrix_dist",zCreate_CompCol_Matrix_dist(&lu->A_sup, M, N, aa->nz, lu->val, lu->col, lu->row, SLU_NC, SLU_Z, SLU_GE));
356 #else
357     PetscStackCall("SuperLU_DIST:dCreate_CompCol_Matrix_dist",dCreate_CompCol_Matrix_dist(&lu->A_sup, M, N, aa->nz, lu->val, lu->col, lu->row, SLU_NC, SLU_D, SLU_GE));
358 #endif
359   } else { /* distributed mat input */
360     Mat_MPIAIJ *mat = (Mat_MPIAIJ*)A->data;
361     aa=(Mat_SeqAIJ*)(mat->A)->data;
362     bb=(Mat_SeqAIJ*)(mat->B)->data;
363     ai=aa->i; aj=aa->j;
364     bi=bb->i; bj=bb->j;
365 #if defined(PETSC_USE_COMPLEX)
366     av=(doublecomplex*)aa->a;
367     bv=(doublecomplex*)bb->a;
368 #else
369     av=aa->a;
370     bv=bb->a;
371 #endif
372     rstart = A->rmap->rstart;
373     nz     = aa->nz + bb->nz;
374     garray = mat->garray;
375 
376     if (lu->options.Fact == DOFACT) { /* first numeric factorization */
377 #if defined(PETSC_USE_COMPLEX)
378       PetscStackCall("SuperLU_DIST:zallocateA_dist",zallocateA_dist(m, nz, &lu->val, &lu->col, &lu->row));
379 #else
380       PetscStackCall("SuperLU_DIST:dallocateA_dist",dallocateA_dist(m, nz, &lu->val, &lu->col, &lu->row));
381 #endif
382     } else { /* successive numeric factorization, sparsity pattern and perm_c are reused. */
383       if (lu->FactPattern == SamePattern_SameRowPerm) {
384         lu->options.Fact = SamePattern_SameRowPerm; /* matrix has similar numerical values */
385       } else if (lu->FactPattern == SamePattern) {
386         PetscStackCall("SuperLU_DIST:Destroy_LU",Destroy_LU(N, &lu->grid, &lu->LUstruct)); /* Deallocate L and U matrices. */
387         lu->options.Fact = SamePattern;
388       } else if (lu->FactPattern == DOFACT) {
389         PetscStackCall("SuperLU_DIST:Destroy_CompRowLoc_Matrix_dist",Destroy_CompRowLoc_Matrix_dist(&lu->A_sup));
390         PetscStackCall("SuperLU_DIST:Destroy_LU",Destroy_LU(N, &lu->grid, &lu->LUstruct));
391         lu->options.Fact = DOFACT;
392 
393 #if defined(PETSC_USE_COMPLEX)
394       PetscStackCall("SuperLU_DIST:zallocateA_dist",zallocateA_dist(m, nz, &lu->val, &lu->col, &lu->row));
395 #else
396       PetscStackCall("SuperLU_DIST:dallocateA_dist",dallocateA_dist(m, nz, &lu->val, &lu->col, &lu->row));
397 #endif
398       } else {
399         SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"options.Fact must be one of SamePattern SamePattern_SameRowPerm DOFACT");
400       }
401     }
402     nz = 0;
403     for (i=0; i<m; i++) {
404       lu->row[i] = nz;
405       countA     = ai[i+1] - ai[i];
406       countB     = bi[i+1] - bi[i];
407       if (aj) {
408         ajj = aj + ai[i]; /* ptr to the beginning of this row */
409       } else {
410         ajj = NULL;
411       }
412       bjj = bj + bi[i];
413 
414       /* B part, smaller col index */
415       if (aj) {
416         colA_start = rstart + ajj[0]; /* the smallest global col index of A */
417       } else { /* superlu_dist does not require matrix has diagonal entries, thus aj=NULL would work */
418         colA_start = rstart;
419       }
420       jB         = 0;
421       for (j=0; j<countB; j++) {
422         jcol = garray[bjj[j]];
423         if (jcol > colA_start) {
424           jB = j;
425           break;
426         }
427         lu->col[nz]   = jcol;
428         lu->val[nz++] = *bv++;
429         if (j==countB-1) jB = countB;
430       }
431 
432       /* A part */
433       for (j=0; j<countA; j++) {
434         lu->col[nz]   = rstart + ajj[j];
435         lu->val[nz++] = *av++;
436       }
437 
438       /* B part, larger col index */
439       for (j=jB; j<countB; j++) {
440         lu->col[nz]   = garray[bjj[j]];
441         lu->val[nz++] = *bv++;
442       }
443     }
444     lu->row[m] = nz;
445 
446     if (lu->options.Fact == DOFACT) {
447 #if defined(PETSC_USE_COMPLEX)
448       PetscStackCall("SuperLU_DIST:zCreate_CompRowLoc_Matrix_dist",zCreate_CompRowLoc_Matrix_dist(&lu->A_sup, M, N, nz, m, rstart,lu->val, lu->col, lu->row, SLU_NR_loc, SLU_Z, SLU_GE));
449 #else
450       PetscStackCall("SuperLU_DIST:dCreate_CompRowLoc_Matrix_dist",dCreate_CompRowLoc_Matrix_dist(&lu->A_sup, M, N, nz, m, rstart,lu->val, lu->col, lu->row, SLU_NR_loc, SLU_D, SLU_GE));
451 #endif
452     }
453   }
454 
455   /* Factor the matrix. */
456   PetscStackCall("SuperLU_DIST:PStatInit",PStatInit(&stat));   /* Initialize the statistics variables. */
457   if (lu->MatInputMode == GLOBAL) { /* global mat input */
458 #if defined(PETSC_USE_COMPLEX)
459     PetscStackCall("SuperLU_DIST:pzgssvx_ABglobal",pzgssvx_ABglobal(&lu->options, &lu->A_sup, &lu->ScalePermstruct, 0, M, 0,&lu->grid, &lu->LUstruct, berr, &stat, &sinfo));
460 #else
461     PetscStackCall("SuperLU_DIST:pdgssvx_ABglobal",pdgssvx_ABglobal(&lu->options, &lu->A_sup, &lu->ScalePermstruct, 0, M, 0,&lu->grid, &lu->LUstruct, berr, &stat, &sinfo));
462 #endif
463   } else { /* distributed mat input */
464 #if defined(PETSC_USE_COMPLEX)
465     PetscStackCall("SuperLU_DIST:pzgssvx",pzgssvx(&lu->options, &lu->A_sup, &lu->ScalePermstruct, 0, m, 0, &lu->grid,&lu->LUstruct, &lu->SOLVEstruct, berr, &stat, &sinfo));
466 #else
467     PetscStackCall("SuperLU_DIST:pdgssvx",pdgssvx(&lu->options, &lu->A_sup, &lu->ScalePermstruct, 0, m, 0, &lu->grid,&lu->LUstruct, &lu->SOLVEstruct, berr, &stat, &sinfo));
468 #endif
469   }
470 
471   if (sinfo > 0) {
472     if (A->erroriffailure) {
473       SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_MAT_LU_ZRPVT,"Zero pivot in row %D",sinfo);
474     } else {
475       if (sinfo <= lu->A_sup.ncol) {
476         F->factorerrortype = MAT_FACTOR_NUMERIC_ZEROPIVOT;
477         ierr = PetscInfo1(F,"U(i,i) is exactly zero, i= %D\n",sinfo);CHKERRQ(ierr);
478       } else if (sinfo > lu->A_sup.ncol) {
479         /*
480          number of bytes allocated when memory allocation
481          failure occurred, plus A->ncol.
482          */
483         F->factorerrortype = MAT_FACTOR_OUTMEMORY;
484         ierr = PetscInfo1(F,"Number of bytes allocated when memory allocation fails %D\n",sinfo);CHKERRQ(ierr);
485       }
486     }
487   } else if (sinfo < 0) {
488     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB, "info = %D, argument in p*gssvx() had an illegal value", sinfo);
489   }
490 
491   if (lu->MatInputMode == GLOBAL && size > 1) {
492     ierr = MatDestroy(&A_seq);CHKERRQ(ierr);
493   }
494 
495   if (lu->options.PrintStat) {
496     PStatPrint(&lu->options, &stat, &lu->grid);  /* Print the statistics. */
497   }
498   PetscStackCall("SuperLU_DIST:PStatFree",PStatFree(&stat));
499   F->assembled    = PETSC_TRUE;
500   F->preallocated = PETSC_TRUE;
501   lu->options.Fact  = FACTORED; /* The factored form of A is supplied. Local option used by this func. only */
502   PetscFunctionReturn(0);
503 }
504 
505 /* Note the Petsc r and c permutations are ignored */
506 static PetscErrorCode MatLUFactorSymbolic_SuperLU_DIST(Mat F,Mat A,IS r,IS c,const MatFactorInfo *info)
507 {
508   Mat_SuperLU_DIST *lu = (Mat_SuperLU_DIST*)F->data;
509   PetscInt         M   = A->rmap->N,N=A->cmap->N;
510 
511   PetscFunctionBegin;
512   /* Initialize the SuperLU process grid. */
513   PetscStackCall("SuperLU_DIST:superlu_gridinit",superlu_gridinit(lu->comm_superlu, lu->nprow, lu->npcol, &lu->grid));
514 
515   /* Initialize ScalePermstruct and LUstruct. */
516   PetscStackCall("SuperLU_DIST:ScalePermstructInit",ScalePermstructInit(M, N, &lu->ScalePermstruct));
517   PetscStackCall("SuperLU_DIST:LUstructInit",LUstructInit(N, &lu->LUstruct));
518   F->ops->lufactornumeric = MatLUFactorNumeric_SuperLU_DIST;
519   F->ops->solve           = MatSolve_SuperLU_DIST;
520   F->ops->matsolve        = MatMatSolve_SuperLU_DIST;
521   F->ops->getinertia      = NULL;
522 
523   if (A->symmetric || A->hermitian) {
524     F->ops->getinertia = MatGetInertia_SuperLU_DIST;
525   }
526   lu->CleanUpSuperLU_Dist = PETSC_TRUE;
527   PetscFunctionReturn(0);
528 }
529 
530 static PetscErrorCode MatCholeskyFactorSymbolic_SuperLU_DIST(Mat F,Mat A,IS r,const MatFactorInfo *info)
531 {
532   PetscErrorCode ierr;
533 
534   PetscFunctionBegin;
535   if (!A->symmetric) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_ARG_WRONG,"Input matrix must be symmetric\n");
536   ierr = MatLUFactorSymbolic_SuperLU_DIST(F,A,r,r,info);CHKERRQ(ierr);
537   F->ops->choleskyfactornumeric = MatLUFactorNumeric_SuperLU_DIST;
538   PetscFunctionReturn(0);
539 }
540 
541 static PetscErrorCode MatFactorGetSolverType_aij_superlu_dist(Mat A,MatSolverType *type)
542 {
543   PetscFunctionBegin;
544   *type = MATSOLVERSUPERLU_DIST;
545   PetscFunctionReturn(0);
546 }
547 
548 static PetscErrorCode MatView_Info_SuperLU_DIST(Mat A,PetscViewer viewer)
549 {
550   Mat_SuperLU_DIST       *lu=(Mat_SuperLU_DIST*)A->data;
551   superlu_dist_options_t options;
552   PetscErrorCode         ierr;
553 
554   PetscFunctionBegin;
555   /* check if matrix is superlu_dist type */
556   if (A->ops->solve != MatSolve_SuperLU_DIST) PetscFunctionReturn(0);
557 
558   options = lu->options;
559   ierr    = PetscViewerASCIIPrintf(viewer,"SuperLU_DIST run parameters:\n");CHKERRQ(ierr);
560   ierr    = PetscViewerASCIIPrintf(viewer,"  Process grid nprow %D x npcol %D \n",lu->nprow,lu->npcol);CHKERRQ(ierr);
561   ierr    = PetscViewerASCIIPrintf(viewer,"  Equilibrate matrix %s \n",PetscBools[options.Equil != NO]);CHKERRQ(ierr);
562   ierr    = PetscViewerASCIIPrintf(viewer,"  Matrix input mode %d \n",lu->MatInputMode);CHKERRQ(ierr);
563   ierr    = PetscViewerASCIIPrintf(viewer,"  Replace tiny pivots %s \n",PetscBools[options.ReplaceTinyPivot != NO]);CHKERRQ(ierr);
564   ierr    = PetscViewerASCIIPrintf(viewer,"  Use iterative refinement %s \n",PetscBools[options.IterRefine == SLU_DOUBLE]);CHKERRQ(ierr);
565   ierr    = PetscViewerASCIIPrintf(viewer,"  Processors in row %d col partition %d \n",lu->nprow,lu->npcol);CHKERRQ(ierr);
566   ierr    = PetscViewerASCIIPrintf(viewer,"  Row permutation %s \n",(options.RowPerm == NOROWPERM) ? "NATURAL" : "LargeDiag");CHKERRQ(ierr);
567 
568   switch (options.ColPerm) {
569   case NATURAL:
570     ierr = PetscViewerASCIIPrintf(viewer,"  Column permutation NATURAL\n");CHKERRQ(ierr);
571     break;
572   case MMD_AT_PLUS_A:
573     ierr = PetscViewerASCIIPrintf(viewer,"  Column permutation MMD_AT_PLUS_A\n");CHKERRQ(ierr);
574     break;
575   case MMD_ATA:
576     ierr = PetscViewerASCIIPrintf(viewer,"  Column permutation MMD_ATA\n");CHKERRQ(ierr);
577     break;
578   case METIS_AT_PLUS_A:
579     ierr = PetscViewerASCIIPrintf(viewer,"  Column permutation METIS_AT_PLUS_A\n");CHKERRQ(ierr);
580     break;
581   case PARMETIS:
582     ierr = PetscViewerASCIIPrintf(viewer,"  Column permutation PARMETIS\n");CHKERRQ(ierr);
583     break;
584   default:
585     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Unknown column permutation");
586   }
587 
588   ierr = PetscViewerASCIIPrintf(viewer,"  Parallel symbolic factorization %s \n",PetscBools[options.ParSymbFact != NO]);CHKERRQ(ierr);
589 
590   if (lu->FactPattern == SamePattern) {
591     ierr = PetscViewerASCIIPrintf(viewer,"  Repeated factorization SamePattern\n");CHKERRQ(ierr);
592   } else if (lu->FactPattern == SamePattern_SameRowPerm) {
593     ierr = PetscViewerASCIIPrintf(viewer,"  Repeated factorization SamePattern_SameRowPerm\n");CHKERRQ(ierr);
594   } else if (lu->FactPattern == DOFACT) {
595     ierr = PetscViewerASCIIPrintf(viewer,"  Repeated factorization DOFACT\n");CHKERRQ(ierr);
596   } else {
597     SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Unknown factorization pattern");
598   }
599   PetscFunctionReturn(0);
600 }
601 
602 static PetscErrorCode MatView_SuperLU_DIST(Mat A,PetscViewer viewer)
603 {
604   PetscErrorCode    ierr;
605   PetscBool         iascii;
606   PetscViewerFormat format;
607 
608   PetscFunctionBegin;
609   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
610   if (iascii) {
611     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
612     if (format == PETSC_VIEWER_ASCII_INFO) {
613       ierr = MatView_Info_SuperLU_DIST(A,viewer);CHKERRQ(ierr);
614     }
615   }
616   PetscFunctionReturn(0);
617 }
618 
619 static PetscErrorCode MatGetFactor_aij_superlu_dist(Mat A,MatFactorType ftype,Mat *F)
620 {
621   Mat                    B;
622   Mat_SuperLU_DIST       *lu;
623   PetscErrorCode         ierr;
624   PetscInt               M=A->rmap->N,N=A->cmap->N,indx;
625   PetscMPIInt            size;
626   superlu_dist_options_t options;
627   PetscBool              flg;
628   const char             *colperm[]     = {"NATURAL","MMD_AT_PLUS_A","MMD_ATA","METIS_AT_PLUS_A","PARMETIS"};
629   const char             *rowperm[]     = {"LargeDiag","NATURAL"};
630   const char             *factPattern[] = {"SamePattern","SamePattern_SameRowPerm","DOFACT"};
631   PetscBool              set;
632 
633   PetscFunctionBegin;
634   /* Create the factorization matrix */
635   ierr = MatCreate(PetscObjectComm((PetscObject)A),&B);CHKERRQ(ierr);
636   ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,M,N);CHKERRQ(ierr);
637   ierr = PetscStrallocpy("superlu_dist",&((PetscObject)B)->type_name);CHKERRQ(ierr);
638   ierr = MatSetUp(B);CHKERRQ(ierr);
639   B->ops->getinfo = MatGetInfo_External;
640   B->ops->view    = MatView_SuperLU_DIST;
641   B->ops->destroy = MatDestroy_SuperLU_DIST;
642 
643   if (ftype == MAT_FACTOR_LU) {
644     B->factortype = MAT_FACTOR_LU;
645     B->ops->lufactorsymbolic       = MatLUFactorSymbolic_SuperLU_DIST;
646   } else {
647     B->factortype = MAT_FACTOR_CHOLESKY;
648     B->ops->choleskyfactorsymbolic = MatCholeskyFactorSymbolic_SuperLU_DIST;
649   }
650 
651   /* set solvertype */
652   ierr = PetscFree(B->solvertype);CHKERRQ(ierr);
653   ierr = PetscStrallocpy(MATSOLVERSUPERLU_DIST,&B->solvertype);CHKERRQ(ierr);
654 
655   ierr    = PetscNewLog(B,&lu);CHKERRQ(ierr);
656   B->data = lu;
657 
658   /* Set the default input options:
659      options.Fact              = DOFACT;
660      options.Equil             = YES;
661      options.ParSymbFact       = NO;
662      options.ColPerm           = METIS_AT_PLUS_A;
663      options.RowPerm           = LargeDiag;
664      options.ReplaceTinyPivot  = YES;
665      options.IterRefine        = DOUBLE;
666      options.Trans             = NOTRANS;
667      options.SolveInitialized  = NO; -hold the communication pattern used MatSolve() and MatMatSolve()
668      options.RefineInitialized = NO;
669      options.PrintStat         = YES;
670   */
671   set_default_options_dist(&options);
672 
673   ierr = MPI_Comm_dup(PetscObjectComm((PetscObject)A),&(lu->comm_superlu));CHKERRQ(ierr);
674   ierr = MPI_Comm_size(PetscObjectComm((PetscObject)A),&size);CHKERRQ(ierr);
675   /* Default num of process columns and rows */
676   lu->nprow = (int_t) (0.5 + PetscSqrtReal((PetscReal)size));
677   if (!lu->nprow) lu->nprow = 1;
678   while (lu->nprow > 0) {
679     lu->npcol = (int_t) (size/lu->nprow);
680     if (size == lu->nprow * lu->npcol) break;
681     lu->nprow--;
682   }
683 
684   ierr = PetscOptionsBegin(PetscObjectComm((PetscObject)A),((PetscObject)A)->prefix,"SuperLU_Dist Options","Mat");CHKERRQ(ierr);
685   ierr = PetscOptionsInt("-mat_superlu_dist_r","Number rows in processor partition","None",lu->nprow,(PetscInt*)&lu->nprow,NULL);CHKERRQ(ierr);
686   ierr = PetscOptionsInt("-mat_superlu_dist_c","Number columns in processor partition","None",lu->npcol,(PetscInt*)&lu->npcol,NULL);CHKERRQ(ierr);
687   if (size != lu->nprow * lu->npcol) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_SIZ,"Number of processes %d must equal to nprow %d * npcol %d",size,lu->nprow,lu->npcol);
688 
689   lu->MatInputMode = DISTRIBUTED;
690 
691   ierr = PetscOptionsEnum("-mat_superlu_dist_matinput","Matrix input mode (global or distributed)","None",SuperLU_MatInputModes,(PetscEnum)lu->MatInputMode,(PetscEnum*)&lu->MatInputMode,NULL);CHKERRQ(ierr);
692   if (lu->MatInputMode == DISTRIBUTED && size == 1) lu->MatInputMode = GLOBAL;
693 
694   ierr = PetscOptionsBool("-mat_superlu_dist_equil","Equilibrate matrix","None",options.Equil ? PETSC_TRUE : PETSC_FALSE,&flg,&set);CHKERRQ(ierr);
695   if (set && !flg) options.Equil = NO;
696 
697   ierr = PetscOptionsEList("-mat_superlu_dist_rowperm","Row permutation","None",rowperm,2,rowperm[0],&indx,&flg);CHKERRQ(ierr);
698   if (flg) {
699     switch (indx) {
700     case 0:
701       options.RowPerm = LargeDiag;
702       break;
703     case 1:
704       options.RowPerm = NOROWPERM;
705       break;
706     }
707   }
708 
709   ierr = PetscOptionsEList("-mat_superlu_dist_colperm","Column permutation","None",colperm,5,colperm[3],&indx,&flg);CHKERRQ(ierr);
710   if (flg) {
711     switch (indx) {
712     case 0:
713       options.ColPerm = NATURAL;
714       break;
715     case 1:
716       options.ColPerm = MMD_AT_PLUS_A;
717       break;
718     case 2:
719       options.ColPerm = MMD_ATA;
720       break;
721     case 3:
722       options.ColPerm = METIS_AT_PLUS_A;
723       break;
724     case 4:
725       options.ColPerm = PARMETIS;   /* only works for np>1 */
726       break;
727     default:
728       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Unknown column permutation");
729     }
730   }
731 
732   options.ReplaceTinyPivot = NO;
733   ierr = PetscOptionsBool("-mat_superlu_dist_replacetinypivot","Replace tiny pivots","None",options.ReplaceTinyPivot ? PETSC_TRUE : PETSC_FALSE,&flg,&set);CHKERRQ(ierr);
734   if (set && flg) options.ReplaceTinyPivot = YES;
735 
736   options.ParSymbFact = NO;
737   ierr = PetscOptionsBool("-mat_superlu_dist_parsymbfact","Parallel symbolic factorization","None",PETSC_FALSE,&flg,&set);CHKERRQ(ierr);
738   if (set && flg && size>1) {
739     if (lu->MatInputMode == GLOBAL) {
740 #if defined(PETSC_USE_INFO)
741       ierr = PetscInfo(A,"Warning: '-mat_superlu_dist_parsymbfact' is ignored because MatInputMode=GLOBAL\n");CHKERRQ(ierr);
742 #endif
743     } else {
744 #if defined(PETSC_HAVE_PARMETIS)
745       options.ParSymbFact = YES;
746       options.ColPerm     = PARMETIS;   /* in v2.2, PARMETIS is forced for ParSymbFact regardless of user ordering setting */
747 #else
748       SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"parsymbfact needs PARMETIS");
749 #endif
750     }
751   }
752 
753   lu->FactPattern = SamePattern;
754   ierr = PetscOptionsEList("-mat_superlu_dist_fact","Sparsity pattern for repeated matrix factorization","None",factPattern,3,factPattern[0],&indx,&flg);CHKERRQ(ierr);
755   if (flg) {
756     switch (indx) {
757     case 0:
758       lu->FactPattern = SamePattern;
759       break;
760     case 1:
761       lu->FactPattern = SamePattern_SameRowPerm;
762       break;
763     case 2:
764       lu->FactPattern = DOFACT;
765       break;
766     }
767   }
768 
769   options.IterRefine = NOREFINE;
770   ierr               = PetscOptionsBool("-mat_superlu_dist_iterrefine","Use iterative refinement","None",options.IterRefine == NOREFINE ? PETSC_FALSE : PETSC_TRUE ,&flg,&set);CHKERRQ(ierr);
771   if (set) {
772     if (flg) options.IterRefine = SLU_DOUBLE;
773     else options.IterRefine = NOREFINE;
774   }
775 
776   if (PetscLogPrintInfo) options.PrintStat = YES;
777   else options.PrintStat = NO;
778   ierr = PetscOptionsBool("-mat_superlu_dist_statprint","Print factorization information","None",(PetscBool)options.PrintStat,(PetscBool*)&options.PrintStat,NULL);CHKERRQ(ierr);
779   ierr = PetscOptionsEnd();CHKERRQ(ierr);
780 
781   lu->options              = options;
782   lu->options.Fact         = DOFACT;
783   lu->matsolve_iscalled    = PETSC_FALSE;
784   lu->matmatsolve_iscalled = PETSC_FALSE;
785 
786   ierr = PetscObjectComposeFunction((PetscObject)B,"MatFactorGetSolverType_C",MatFactorGetSolverType_aij_superlu_dist);CHKERRQ(ierr);
787   ierr = PetscObjectComposeFunction((PetscObject)B,"MatSuperluDistGetDiagU_C",MatSuperluDistGetDiagU_SuperLU_DIST);CHKERRQ(ierr);
788 
789   *F = B;
790   PetscFunctionReturn(0);
791 }
792 
793 PETSC_EXTERN PetscErrorCode MatSolverTypeRegister_SuperLU_DIST(void)
794 {
795   PetscErrorCode ierr;
796   PetscFunctionBegin;
797   ierr = MatSolverTypeRegister(MATSOLVERSUPERLU_DIST,MATMPIAIJ,  MAT_FACTOR_LU,MatGetFactor_aij_superlu_dist);CHKERRQ(ierr);
798   ierr = MatSolverTypeRegister(MATSOLVERSUPERLU_DIST,MATSEQAIJ,  MAT_FACTOR_LU,MatGetFactor_aij_superlu_dist);CHKERRQ(ierr);
799   ierr = MatSolverTypeRegister(MATSOLVERSUPERLU_DIST,MATMPIAIJ,  MAT_FACTOR_CHOLESKY,MatGetFactor_aij_superlu_dist);CHKERRQ(ierr);
800   ierr = MatSolverTypeRegister(MATSOLVERSUPERLU_DIST,MATSEQAIJ,  MAT_FACTOR_CHOLESKY,MatGetFactor_aij_superlu_dist);CHKERRQ(ierr);
801   PetscFunctionReturn(0);
802 }
803 
804 /*MC
805   MATSOLVERSUPERLU_DIST - Parallel direct solver package for LU factorization
806 
807   Use ./configure --download-superlu_dist --download-parmetis --download-metis --download-ptscotch  to have PETSc installed with SuperLU_DIST
808 
809   Use -pc_type lu -pc_factor_mat_solver_type superlu_dist to use this direct solver
810 
811    Works with AIJ matrices
812 
813   Options Database Keys:
814 + -mat_superlu_dist_r <n> - number of rows in processor partition
815 . -mat_superlu_dist_c <n> - number of columns in processor partition
816 . -mat_superlu_dist_matinput <0,1> - matrix input mode; 0=global, 1=distributed
817 . -mat_superlu_dist_equil - equilibrate the matrix
818 . -mat_superlu_dist_rowperm <LargeDiag,NATURAL> - row permutation
819 . -mat_superlu_dist_colperm <MMD_AT_PLUS_A,MMD_ATA,NATURAL> - column permutation
820 . -mat_superlu_dist_replacetinypivot - replace tiny pivots
821 . -mat_superlu_dist_fact <SamePattern> - (choose one of) SamePattern SamePattern_SameRowPerm DOFACT
822 . -mat_superlu_dist_iterrefine - use iterative refinement
823 - -mat_superlu_dist_statprint - print factorization information
824 
825    Level: beginner
826 
827 .seealso: PCLU
828 
829 .seealso: PCFactorSetMatSolverType(), MatSolverType
830 
831 M*/
832