xref: /petsc/src/mat/impls/aij/mpi/mumps/mumps.c (revision ace87b0db0efe80e274e353a31cc25b05e0d31a0)
1397b6df1SKris Buschelman /*$Id: mumps.c,v 1.10 2001/08/15 15:56:50 bsmith Exp $*/
2397b6df1SKris Buschelman /*
3397b6df1SKris Buschelman     Provides an interface to the MUMPS_4.2_beta sparse solver
4397b6df1SKris Buschelman */
5397b6df1SKris Buschelman 
6397b6df1SKris Buschelman #include "src/mat/impls/aij/seq/aij.h"
7397b6df1SKris Buschelman #include "src/mat/impls/aij/mpi/mpiaij.h"
8397b6df1SKris Buschelman #include "src/mat/impls/sbaij/seq/sbaij.h"
9397b6df1SKris Buschelman #include "src/mat/impls/sbaij/mpi/mpisbaij.h"
10397b6df1SKris Buschelman 
11397b6df1SKris Buschelman EXTERN_C_BEGIN
12397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
13397b6df1SKris Buschelman #include "zmumps_c.h"
14397b6df1SKris Buschelman #else
15397b6df1SKris Buschelman #include "dmumps_c.h"
16397b6df1SKris Buschelman #endif
17397b6df1SKris Buschelman EXTERN_C_END
18397b6df1SKris Buschelman #define JOB_INIT -1
19397b6df1SKris Buschelman #define JOB_END -2
20397b6df1SKris Buschelman /* macros s.t. indices match MUMPS documentation */
21397b6df1SKris Buschelman #define ICNTL(I) icntl[(I)-1]
22397b6df1SKris Buschelman #define CNTL(I) cntl[(I)-1]
23397b6df1SKris Buschelman #define INFOG(I) infog[(I)-1]
24397b6df1SKris Buschelman #define RINFOG(I) rinfog[(I)-1]
25397b6df1SKris Buschelman 
26397b6df1SKris Buschelman typedef struct {
27397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
28397b6df1SKris Buschelman   ZMUMPS_STRUC_C id;
29397b6df1SKris Buschelman #else
30397b6df1SKris Buschelman   DMUMPS_STRUC_C id;
31397b6df1SKris Buschelman #endif
32397b6df1SKris Buschelman   MatStructure   matstruc;
33397b6df1SKris Buschelman   int            myid,size,*irn,*jcn,sym;
34397b6df1SKris Buschelman   PetscScalar    *val;
35397b6df1SKris Buschelman   MPI_Comm       comm_mumps;
36397b6df1SKris Buschelman 
37c338a77dSKris Buschelman   MatType        basetype;
38c338a77dSKris Buschelman   PetscTruth     isAIJ,CleanUpMUMPS;
39c338a77dSKris Buschelman   int (*MatView)(Mat,PetscViewer);
40c338a77dSKris Buschelman   int (*MatAssemblyEnd)(Mat,MatAssemblyType);
41c338a77dSKris Buschelman   int (*MatLUFactorSymbolic)(Mat,IS,IS,MatFactorInfo*,Mat*);
42c338a77dSKris Buschelman   int (*MatCholeskyFactorSymbolic)(Mat,IS,MatFactorInfo*,Mat*);
43c338a77dSKris Buschelman   int (*MatDestroy)(Mat);
44c338a77dSKris Buschelman } Mat_AIJ_MUMPS;
450e3434eeSKris Buschelman 
46397b6df1SKris Buschelman /* convert Petsc mpiaij matrix to triples: row[nz], col[nz], val[nz] */
47397b6df1SKris Buschelman /*
48397b6df1SKris Buschelman   input:
49397b6df1SKris Buschelman     A       - matrix in mpiaij format
50397b6df1SKris Buschelman     shift   - 0: C style output triple; 1: Fortran style output triple.
51397b6df1SKris Buschelman     valOnly - FALSE: spaces are allocated and values are set for the triple
52397b6df1SKris Buschelman               TRUE:  only the values in v array are updated
53397b6df1SKris Buschelman   output:
54397b6df1SKris Buschelman     nnz     - dim of r, c, and v (number of local nonzero entries of A)
55397b6df1SKris Buschelman     r, c, v - row and col index, matrix values (matrix triples)
56397b6df1SKris Buschelman  */
57397b6df1SKris Buschelman int MatConvertToTriples(Mat A,int shift,PetscTruth valOnly,int *nnz,int **r, int **c, PetscScalar **v)
58397b6df1SKris Buschelman {
59397b6df1SKris Buschelman   int              *ai, *aj, *bi, *bj, rstart,nz, *garray;
60397b6df1SKris Buschelman   int              ierr,i,j,jj,jB,irow,m=A->m,*ajj,*bjj,countA,countB,colA_start,jcol;
61d54de34fSKris Buschelman   int              *row,*col;
62397b6df1SKris Buschelman   PetscScalar      *av, *bv,*val;
63397b6df1SKris Buschelman   Mat_AIJ_MUMPS *mumps = (Mat_AIJ_MUMPS *)A->spptr;
64397b6df1SKris Buschelman 
65397b6df1SKris Buschelman   PetscFunctionBegin;
66397b6df1SKris Buschelman 
67397b6df1SKris Buschelman   if (mumps->isAIJ){
68397b6df1SKris Buschelman     Mat_MPIAIJ    *mat =  (Mat_MPIAIJ*)A->data;
69397b6df1SKris Buschelman     Mat_SeqAIJ    *aa=(Mat_SeqAIJ*)(mat->A)->data;
70397b6df1SKris Buschelman     Mat_SeqAIJ    *bb=(Mat_SeqAIJ*)(mat->B)->data;
71397b6df1SKris Buschelman     nz = aa->nz + bb->nz;
72397b6df1SKris Buschelman     ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= mat->rstart;
73397b6df1SKris Buschelman     garray = mat->garray;
74397b6df1SKris Buschelman     av=aa->a; bv=bb->a;
75397b6df1SKris Buschelman 
76397b6df1SKris Buschelman   } else {
77397b6df1SKris Buschelman     Mat_MPISBAIJ  *mat =  (Mat_MPISBAIJ*)A->data;
78397b6df1SKris Buschelman     Mat_SeqSBAIJ  *aa=(Mat_SeqSBAIJ*)(mat->A)->data;
79397b6df1SKris Buschelman     Mat_SeqBAIJ    *bb=(Mat_SeqBAIJ*)(mat->B)->data;
80847143adSKris Buschelman     if (mat->bs > 1) SETERRQ1(PETSC_ERR_SUP," bs=%d is not supported yet\n", mat->bs);
81397b6df1SKris Buschelman     nz = aa->s_nz + bb->nz;
82397b6df1SKris Buschelman     ai=aa->i; aj=aa->j; bi=bb->i; bj=bb->j; rstart= mat->rstart;
83397b6df1SKris Buschelman     garray = mat->garray;
84397b6df1SKris Buschelman     av=aa->a; bv=bb->a;
85397b6df1SKris Buschelman   }
86397b6df1SKris Buschelman 
87397b6df1SKris Buschelman   if (!valOnly){
88397b6df1SKris Buschelman     ierr = PetscMalloc(nz*sizeof(int),&row);CHKERRQ(ierr);
89397b6df1SKris Buschelman     ierr = PetscMalloc(nz*sizeof(int),&col);CHKERRQ(ierr);
90397b6df1SKris Buschelman     ierr = PetscMalloc(nz*sizeof(PetscScalar),&val);CHKERRQ(ierr);
91397b6df1SKris Buschelman     *r = row; *c = col; *v = val;
92397b6df1SKris Buschelman   } else {
93397b6df1SKris Buschelman     row = *r; col = *c; val = *v;
94397b6df1SKris Buschelman   }
95397b6df1SKris Buschelman   *nnz = nz;
96397b6df1SKris Buschelman 
97397b6df1SKris Buschelman   jj = 0; jB = 0; irow = rstart;
98397b6df1SKris Buschelman   for ( i=0; i<m; i++ ) {
99397b6df1SKris Buschelman     ajj = aj + ai[i];                 /* ptr to the beginning of this row */
100397b6df1SKris Buschelman     countA = ai[i+1] - ai[i];
101397b6df1SKris Buschelman     countB = bi[i+1] - bi[i];
102397b6df1SKris Buschelman     bjj = bj + bi[i];
103397b6df1SKris Buschelman 
104397b6df1SKris Buschelman     /* get jB, the starting local col index for the 2nd B-part */
105397b6df1SKris Buschelman     colA_start = rstart + ajj[0]; /* the smallest col index for A */
106397b6df1SKris Buschelman     for (j=0; j<countB; j++){
107397b6df1SKris Buschelman       jcol = garray[bjj[j]];
108397b6df1SKris Buschelman       if (jcol > colA_start) { jB = j; break; }
109397b6df1SKris Buschelman       if (j==countB-1) jB = countB;
110397b6df1SKris Buschelman     }
111397b6df1SKris Buschelman 
112397b6df1SKris Buschelman     /* B-part, smaller col index */
113397b6df1SKris Buschelman     colA_start = rstart + ajj[0]; /* the smallest col index for A */
114397b6df1SKris Buschelman     for (j=0; j<jB; j++){
115397b6df1SKris Buschelman       jcol = garray[bjj[j]];
116397b6df1SKris Buschelman       if (!valOnly){
117397b6df1SKris Buschelman         row[jj] = irow + shift; col[jj] = jcol + shift;
118397b6df1SKris Buschelman       }
119397b6df1SKris Buschelman       val[jj++] = *bv++;
120397b6df1SKris Buschelman     }
121397b6df1SKris Buschelman     /* A-part */
122397b6df1SKris Buschelman     for (j=0; j<countA; j++){
123397b6df1SKris Buschelman       if (!valOnly){
124397b6df1SKris Buschelman         row[jj] = irow + shift; col[jj] = rstart + ajj[j] + shift;
125397b6df1SKris Buschelman       }
126397b6df1SKris Buschelman       val[jj++] = *av++;
127397b6df1SKris Buschelman     }
128397b6df1SKris Buschelman     /* B-part, larger col index */
129397b6df1SKris Buschelman     for (j=jB; j<countB; j++){
130397b6df1SKris Buschelman       if (!valOnly){
131397b6df1SKris Buschelman         row[jj] = irow + shift; col[jj] = garray[bjj[j]] + shift;
132397b6df1SKris Buschelman       }
133397b6df1SKris Buschelman       val[jj++] = *bv++;
134397b6df1SKris Buschelman     }
135397b6df1SKris Buschelman     irow++;
136397b6df1SKris Buschelman   }
137397b6df1SKris Buschelman 
138397b6df1SKris Buschelman   PetscFunctionReturn(0);
139397b6df1SKris Buschelman }
140397b6df1SKris Buschelman 
141c338a77dSKris Buschelman EXTERN_C_BEGIN
142c338a77dSKris Buschelman #undef __FUNCT__
143c338a77dSKris Buschelman #define __FUNCT__ "MatConvert_MUMPS_Base"
144c338a77dSKris Buschelman int MatConvert_MUMPS_Base(Mat A,MatType type,Mat *newmat) {
145c338a77dSKris Buschelman   /* This routine is only called to convert an unfactored PETSc-MUMPS matrix */
146c338a77dSKris Buschelman   /* to its base PETSc type, so we will ignore 'MatType type'. */
147c338a77dSKris Buschelman   int           ierr;
148c338a77dSKris Buschelman   Mat           B=*newmat;
149c338a77dSKris Buschelman   Mat_AIJ_MUMPS *lu=(Mat_AIJ_MUMPS*)A->spptr;
150c338a77dSKris Buschelman 
151c338a77dSKris Buschelman   PetscFunctionBegin;
152c338a77dSKris Buschelman   if (B != A) {
153c338a77dSKris Buschelman     /* This routine was inherited from SeqAIJ. */
154c338a77dSKris Buschelman     ierr = MatDuplicate(A,MAT_COPY_VALUES,&B);CHKERRQ(ierr);
155c338a77dSKris Buschelman   } else {
156c338a77dSKris Buschelman 
157c338a77dSKris Buschelman   B->ops->view                   = lu->MatView;
158c338a77dSKris Buschelman   B->ops->assemblyend            = lu->MatAssemblyEnd;
159c338a77dSKris Buschelman   B->ops->lufactorsymbolic       = lu->MatLUFactorSymbolic;
160c338a77dSKris Buschelman   B->ops->choleskyfactorsymbolic = lu->MatCholeskyFactorSymbolic;
161c338a77dSKris Buschelman   B->ops->destroy                = lu->MatDestroy;
162c338a77dSKris Buschelman   ierr = PetscObjectChangeTypeName((PetscObject)B,lu->basetype);CHKERRQ(ierr);
163c338a77dSKris Buschelman   ierr = PetscFree(lu);CHKERRQ(ierr);
164c338a77dSKris Buschelman   }
165c338a77dSKris Buschelman   *newmat = B;
166c338a77dSKris Buschelman   PetscFunctionReturn(0);
167c338a77dSKris Buschelman }
168c338a77dSKris Buschelman EXTERN_C_END
169c338a77dSKris Buschelman 
170397b6df1SKris Buschelman #undef __FUNCT__
171397b6df1SKris Buschelman #define __FUNCT__ "MatDestroy_AIJ_MUMPS"
172397b6df1SKris Buschelman int MatDestroy_AIJ_MUMPS(Mat A)
173397b6df1SKris Buschelman {
174397b6df1SKris Buschelman   Mat_AIJ_MUMPS *lu = (Mat_AIJ_MUMPS*)A->spptr;
175c338a77dSKris Buschelman   int           ierr,size=lu->size;
176397b6df1SKris Buschelman 
177397b6df1SKris Buschelman   PetscFunctionBegin;
178397b6df1SKris Buschelman   if (lu->CleanUpMUMPS) {
179397b6df1SKris Buschelman     /* Terminate instance, deallocate memories */
180397b6df1SKris Buschelman     lu->id.job=JOB_END;
181397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
182397b6df1SKris Buschelman     zmumps_c(&lu->id);
183397b6df1SKris Buschelman #else
184397b6df1SKris Buschelman     dmumps_c(&lu->id);
185397b6df1SKris Buschelman #endif
186c338a77dSKris Buschelman     if (lu->irn) {
187c338a77dSKris Buschelman       ierr = PetscFree(lu->irn);CHKERRQ(ierr);
188c338a77dSKris Buschelman     }
189c338a77dSKris Buschelman     if (lu->jcn) {
190c338a77dSKris Buschelman       ierr = PetscFree(lu->jcn);CHKERRQ(ierr);
191c338a77dSKris Buschelman     }
192c338a77dSKris Buschelman     if (size>1 && lu->val) {
193c338a77dSKris Buschelman       ierr = PetscFree(lu->val);CHKERRQ(ierr);
194c338a77dSKris Buschelman     }
195397b6df1SKris Buschelman     ierr = MPI_Comm_free(&(lu->comm_mumps));CHKERRQ(ierr);
196397b6df1SKris Buschelman   }
197c338a77dSKris Buschelman   ierr = MatConvert_MUMPS_Base(A,lu->basetype,&A);CHKERRQ(ierr);
198c338a77dSKris Buschelman   ierr = (*A->ops->destroy)(A);CHKERRQ(ierr);
199397b6df1SKris Buschelman   PetscFunctionReturn(0);
200397b6df1SKris Buschelman }
201397b6df1SKris Buschelman 
202397b6df1SKris Buschelman #undef __FUNCT__
203c338a77dSKris Buschelman #define __FUNCT__ "MatFactorInfo_MUMPS"
204c338a77dSKris Buschelman int MatFactorInfo_MUMPS(Mat A,PetscViewer viewer)
205c338a77dSKris Buschelman {
206c338a77dSKris Buschelman   Mat_AIJ_MUMPS *lu= (Mat_AIJ_MUMPS*)A->spptr;
207397b6df1SKris Buschelman   int              ierr;
208397b6df1SKris Buschelman 
209397b6df1SKris Buschelman   PetscFunctionBegin;
210c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"MUMPS run parameters:\n");CHKERRQ(ierr);
211c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  SYM (matrix type):                  %d \n",lu->id.sym);CHKERRQ(ierr);
212c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  PAR (host participation):           %d \n",lu->id.par);CHKERRQ(ierr);
213c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(4) (level of printing):       %d \n",lu->id.ICNTL(4));CHKERRQ(ierr);
214c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(5) (input mat struct):        %d \n",lu->id.ICNTL(5));CHKERRQ(ierr);
215c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(6) (matrix prescaling):       %d \n",lu->id.ICNTL(6));CHKERRQ(ierr);
216c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(7) (matrix ordering):         %d \n",lu->id.ICNTL(7));CHKERRQ(ierr);
217c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(9) (A/A^T x=b is solved):     %d \n",lu->id.ICNTL(9));CHKERRQ(ierr);
218c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(10) (max num of refinements): %d \n",lu->id.ICNTL(10));CHKERRQ(ierr);
219c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(11) (error analysis):         %d \n",lu->id.ICNTL(11));CHKERRQ(ierr);
220c338a77dSKris Buschelman   if (lu->myid == 0 && lu->id.ICNTL(11)>0) {
221c338a77dSKris Buschelman     ierr = PetscPrintf(PETSC_COMM_SELF,"        RINFOG(4) (inf norm of input mat):        %g\n",lu->id.RINFOG(4));CHKERRQ(ierr);
222c338a77dSKris Buschelman     ierr = PetscPrintf(PETSC_COMM_SELF,"        RINFOG(5) (inf norm of solution):         %g\n",lu->id.RINFOG(5));CHKERRQ(ierr);
223c338a77dSKris Buschelman     ierr = PetscPrintf(PETSC_COMM_SELF,"        RINFOG(6) (inf norm of residual):         %g\n",lu->id.RINFOG(6));CHKERRQ(ierr);
224c338a77dSKris Buschelman     ierr = PetscPrintf(PETSC_COMM_SELF,"        RINFOG(7),RINFOG(8) (backward error est): %g, %g\n",lu->id.RINFOG(7),lu->id.RINFOG(8));CHKERRQ(ierr);
225c338a77dSKris Buschelman     ierr = PetscPrintf(PETSC_COMM_SELF,"        RINFOG(9) (error estimate):               %g \n",lu->id.RINFOG(9));CHKERRQ(ierr);
226c338a77dSKris Buschelman     ierr = PetscPrintf(PETSC_COMM_SELF,"        RINFOG(10),RINFOG(11)(condition numbers): %g, %g\n",lu->id.RINFOG(10),lu->id.RINFOG(11));CHKERRQ(ierr);
227c338a77dSKris Buschelman 
228c338a77dSKris Buschelman   }
229c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(12) (efficiency control):     %d \n",lu->id.ICNTL(12));CHKERRQ(ierr);
230c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(13) (efficiency control):     %d \n",lu->id.ICNTL(13));CHKERRQ(ierr);
231c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(14) (efficiency control):     %d \n",lu->id.ICNTL(14));CHKERRQ(ierr);
232c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(15) (efficiency control):     %d \n",lu->id.ICNTL(15));CHKERRQ(ierr);
233c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  ICNTL(18) (input mat struct):       %d \n",lu->id.ICNTL(18));CHKERRQ(ierr);
234c338a77dSKris Buschelman 
235c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  CNTL(1) (relative pivoting threshold):      %g \n",lu->id.CNTL(1));CHKERRQ(ierr);
236c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  CNTL(2) (stopping criterion of refinement): %g \n",lu->id.CNTL(2));CHKERRQ(ierr);
237c338a77dSKris Buschelman   ierr = PetscViewerASCIIPrintf(viewer,"  CNTL(3) (absolute pivoting threshold):      %g \n",lu->id.CNTL(3));CHKERRQ(ierr);
238397b6df1SKris Buschelman   PetscFunctionReturn(0);
239397b6df1SKris Buschelman }
240397b6df1SKris Buschelman 
241397b6df1SKris Buschelman #undef __FUNCT__
242397b6df1SKris Buschelman #define __FUNCT__ "MatView_AIJ_MUMPS"
243397b6df1SKris Buschelman int MatView_AIJ_MUMPS(Mat A,PetscViewer viewer) {
244397b6df1SKris Buschelman   int               ierr;
245397b6df1SKris Buschelman   PetscTruth        isascii;
246397b6df1SKris Buschelman   PetscViewerFormat format;
247397b6df1SKris Buschelman   Mat_AIJ_MUMPS     *mumps=(Mat_AIJ_MUMPS*)(A->spptr);
248397b6df1SKris Buschelman 
249397b6df1SKris Buschelman   PetscFunctionBegin;
250397b6df1SKris Buschelman   ierr = (*mumps->MatView)(A,viewer);CHKERRQ(ierr);
251397b6df1SKris Buschelman 
252397b6df1SKris Buschelman   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&isascii);CHKERRQ(ierr);
253397b6df1SKris Buschelman   if (isascii) {
254397b6df1SKris Buschelman     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
255397b6df1SKris Buschelman     if (format == PETSC_VIEWER_ASCII_FACTOR_INFO) {
256397b6df1SKris Buschelman       ierr = MatFactorInfo_MUMPS(A,viewer);CHKERRQ(ierr);
257397b6df1SKris Buschelman     }
258397b6df1SKris Buschelman   }
259397b6df1SKris Buschelman   PetscFunctionReturn(0);
260397b6df1SKris Buschelman }
261397b6df1SKris Buschelman 
262397b6df1SKris Buschelman #undef __FUNCT__
263397b6df1SKris Buschelman #define __FUNCT__ "MatSolve_AIJ_MUMPS"
264397b6df1SKris Buschelman int MatSolve_AIJ_MUMPS(Mat A,Vec b,Vec x)
265397b6df1SKris Buschelman {
266397b6df1SKris Buschelman   Mat_AIJ_MUMPS *lu = (Mat_AIJ_MUMPS*)A->spptr;
267d54de34fSKris Buschelman   PetscScalar      *array;
268397b6df1SKris Buschelman   Vec              x_seq;
269397b6df1SKris Buschelman   IS               iden;
270397b6df1SKris Buschelman   VecScatter       scat;
271397b6df1SKris Buschelman   int              ierr;
272397b6df1SKris Buschelman 
273397b6df1SKris Buschelman   PetscFunctionBegin;
274397b6df1SKris Buschelman   if (lu->size > 1){
275397b6df1SKris Buschelman     if (!lu->myid){
276397b6df1SKris Buschelman       ierr = VecCreateSeq(PETSC_COMM_SELF,A->N,&x_seq);CHKERRQ(ierr);
277397b6df1SKris Buschelman       ierr = ISCreateStride(PETSC_COMM_SELF,A->N,0,1,&iden);CHKERRQ(ierr);
278397b6df1SKris Buschelman     } else {
279397b6df1SKris Buschelman       ierr = VecCreateSeq(PETSC_COMM_SELF,0,&x_seq);CHKERRQ(ierr);
280397b6df1SKris Buschelman       ierr = ISCreateStride(PETSC_COMM_SELF,0,0,1,&iden);CHKERRQ(ierr);
281397b6df1SKris Buschelman     }
282397b6df1SKris Buschelman     ierr = VecScatterCreate(b,iden,x_seq,iden,&scat);CHKERRQ(ierr);
283397b6df1SKris Buschelman     ierr = ISDestroy(iden);CHKERRQ(ierr);
284397b6df1SKris Buschelman 
285397b6df1SKris Buschelman     ierr = VecScatterBegin(b,x_seq,INSERT_VALUES,SCATTER_FORWARD,scat);CHKERRQ(ierr);
286397b6df1SKris Buschelman     ierr = VecScatterEnd(b,x_seq,INSERT_VALUES,SCATTER_FORWARD,scat);CHKERRQ(ierr);
287397b6df1SKris Buschelman     if (!lu->myid) {ierr = VecGetArray(x_seq,&array);CHKERRQ(ierr);}
288397b6df1SKris Buschelman   } else {  /* size == 1 */
289397b6df1SKris Buschelman     ierr = VecCopy(b,x);CHKERRQ(ierr);
290397b6df1SKris Buschelman     ierr = VecGetArray(x,&array);CHKERRQ(ierr);
291397b6df1SKris Buschelman   }
292397b6df1SKris Buschelman   if (!lu->myid) { /* define rhs on the host */
293397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
294397b6df1SKris Buschelman     lu->id.rhs = (mumps_double_complex*)array;
295397b6df1SKris Buschelman #else
296397b6df1SKris Buschelman     lu->id.rhs = array;
297397b6df1SKris Buschelman #endif
298397b6df1SKris Buschelman   }
299397b6df1SKris Buschelman 
300397b6df1SKris Buschelman   /* solve phase */
301397b6df1SKris Buschelman   lu->id.job=3;
302397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
303397b6df1SKris Buschelman   zmumps_c(&lu->id);
304397b6df1SKris Buschelman #else
305397b6df1SKris Buschelman   dmumps_c(&lu->id);
306397b6df1SKris Buschelman #endif
307397b6df1SKris Buschelman   if (lu->id.INFOG(1) < 0) {
308397b6df1SKris Buschelman     SETERRQ1(1,"Error reported by MUMPS in solve phase: INFOG(1)=%d\n",lu->id.INFOG(1));
309397b6df1SKris Buschelman   }
310397b6df1SKris Buschelman 
311397b6df1SKris Buschelman   /* convert mumps solution x_seq to petsc mpi x */
312397b6df1SKris Buschelman   if (lu->size > 1) {
313397b6df1SKris Buschelman     if (!lu->myid){
314397b6df1SKris Buschelman       ierr = VecRestoreArray(x_seq,&array);CHKERRQ(ierr);
315397b6df1SKris Buschelman     }
316397b6df1SKris Buschelman     ierr = VecScatterBegin(x_seq,x,INSERT_VALUES,SCATTER_REVERSE,scat);CHKERRQ(ierr);
317397b6df1SKris Buschelman     ierr = VecScatterEnd(x_seq,x,INSERT_VALUES,SCATTER_REVERSE,scat);CHKERRQ(ierr);
318397b6df1SKris Buschelman     ierr = VecScatterDestroy(scat);CHKERRQ(ierr);
319397b6df1SKris Buschelman     ierr = VecDestroy(x_seq);CHKERRQ(ierr);
320397b6df1SKris Buschelman   } else {
321397b6df1SKris Buschelman     ierr = VecRestoreArray(x,&array);CHKERRQ(ierr);
322397b6df1SKris Buschelman   }
323397b6df1SKris Buschelman 
324397b6df1SKris Buschelman   PetscFunctionReturn(0);
325397b6df1SKris Buschelman }
326397b6df1SKris Buschelman 
327397b6df1SKris Buschelman #undef __FUNCT__
328397b6df1SKris Buschelman #define __FUNCT__ "MatFactorNumeric_MPIAIJ_MUMPS"
329397b6df1SKris Buschelman int MatFactorNumeric_AIJ_MUMPS(Mat A,Mat *F)
330397b6df1SKris Buschelman {
331397b6df1SKris Buschelman   Mat_AIJ_MUMPS *lu  = (Mat_AIJ_MUMPS*)(*F)->spptr;
332c36ead0aSKris Buschelman   Mat_AIJ_MUMPS *lua = (Mat_AIJ_MUMPS*)(A)->spptr;
333397b6df1SKris Buschelman   int              rnz,nnz,ierr,nz,i,M=A->M,*ai,*aj,icntl;
334397b6df1SKris Buschelman   PetscTruth       valOnly,flg;
335397b6df1SKris Buschelman 
336397b6df1SKris Buschelman   PetscFunctionBegin;
337397b6df1SKris Buschelman   if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
338397b6df1SKris Buschelman     (*F)->ops->solve    = MatSolve_AIJ_MUMPS;
339397b6df1SKris Buschelman 
340397b6df1SKris Buschelman     /* Initialize a MUMPS instance */
341397b6df1SKris Buschelman     ierr = MPI_Comm_rank(A->comm, &lu->myid);
342397b6df1SKris Buschelman     ierr = MPI_Comm_size(A->comm,&lu->size);CHKERRQ(ierr);
343397b6df1SKris Buschelman     lu->id.job = JOB_INIT;
344397b6df1SKris Buschelman     ierr = MPI_Comm_dup(A->comm,&(lu->comm_mumps));CHKERRQ(ierr);
345397b6df1SKris Buschelman     lu->id.comm_fortran = lu->comm_mumps;
346397b6df1SKris Buschelman 
347397b6df1SKris Buschelman     /* Set mumps options */
348397b6df1SKris Buschelman     ierr = PetscOptionsBegin(A->comm,A->prefix,"MUMPS Options","Mat");CHKERRQ(ierr);
349397b6df1SKris Buschelman     lu->id.par=1;  /* host participates factorizaton and solve */
350397b6df1SKris Buschelman     lu->id.sym=lu->sym;
351397b6df1SKris Buschelman     if (lu->sym == 2){
352397b6df1SKris Buschelman       ierr = PetscOptionsInt("-mat_mumps_sym","SYM: (1,2)","None",lu->id.sym,&icntl,&flg);CHKERRQ(ierr);
353397b6df1SKris Buschelman       if (flg && icntl == 1) lu->id.sym=icntl;  /* matrix is spd */
354397b6df1SKris Buschelman     }
355397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
356397b6df1SKris Buschelman   zmumps_c(&lu->id);
357397b6df1SKris Buschelman #else
358397b6df1SKris Buschelman   dmumps_c(&lu->id);
359397b6df1SKris Buschelman #endif
360397b6df1SKris Buschelman 
361397b6df1SKris Buschelman     if (lu->size == 1){
362397b6df1SKris Buschelman       lu->id.ICNTL(18) = 0;   /* centralized assembled matrix input */
363397b6df1SKris Buschelman     } else {
364397b6df1SKris Buschelman       lu->id.ICNTL(18) = 3;   /* distributed assembled matrix input */
365397b6df1SKris Buschelman     }
366397b6df1SKris Buschelman 
367397b6df1SKris Buschelman     icntl=-1;
368397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_4","ICNTL(4): level of printing (0 to 4)","None",lu->id.ICNTL(4),&icntl,&flg);CHKERRQ(ierr);
369397b6df1SKris Buschelman     if (flg && icntl > 0) {
370397b6df1SKris Buschelman       lu->id.ICNTL(4)=icntl; /* and use mumps default icntl(i), i=1,2,3 */
371397b6df1SKris Buschelman     } else { /* no output */
372397b6df1SKris Buschelman       lu->id.ICNTL(1) = 0;  /* error message, default= 6 */
373397b6df1SKris Buschelman       lu->id.ICNTL(2) = -1; /* output stream for diagnostic printing, statistics, and warning. default=0 */
374397b6df1SKris Buschelman       lu->id.ICNTL(3) = -1; /* output stream for global information, default=6 */
375397b6df1SKris Buschelman       lu->id.ICNTL(4) = 0;  /* level of printing, 0,1,2,3,4, default=2 */
376397b6df1SKris Buschelman     }
377397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_6","ICNTL(6): matrix prescaling (0 to 7)","None",lu->id.ICNTL(6),&lu->id.ICNTL(6),PETSC_NULL);CHKERRQ(ierr);
378397b6df1SKris Buschelman     icntl=-1;
379397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_7","ICNTL(7): matrix ordering (0 to 7)","None",lu->id.ICNTL(7),&icntl,&flg);CHKERRQ(ierr);
380397b6df1SKris Buschelman     if (flg) {
381397b6df1SKris Buschelman       if (icntl== 1){
382397b6df1SKris Buschelman         SETERRQ(PETSC_ERR_SUP,"pivot order be set by the user in PERM_IN -- not supported by the PETSc/MUMPS interface\n");
383397b6df1SKris Buschelman       } else {
384397b6df1SKris Buschelman         lu->id.ICNTL(7) = icntl;
385397b6df1SKris Buschelman       }
386397b6df1SKris Buschelman     }
387397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_9","ICNTL(9): A or A^T x=b to be solved. 1: A; otherwise: A^T","None",lu->id.ICNTL(9),&lu->id.ICNTL(9),PETSC_NULL);CHKERRQ(ierr);
388397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_10","ICNTL(10): max num of refinements","None",lu->id.ICNTL(10),&lu->id.ICNTL(10),PETSC_NULL);CHKERRQ(ierr);
389397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_11","ICNTL(11): error analysis, a positive value returns statistics (by -sles_view)","None",lu->id.ICNTL(11),&lu->id.ICNTL(11),PETSC_NULL);CHKERRQ(ierr);
390397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_12","ICNTL(12): efficiency control","None",lu->id.ICNTL(12),&lu->id.ICNTL(12),PETSC_NULL);CHKERRQ(ierr);
391397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_13","ICNTL(13): efficiency control","None",lu->id.ICNTL(13),&lu->id.ICNTL(13),PETSC_NULL);CHKERRQ(ierr);
392397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_14","ICNTL(14): efficiency control","None",lu->id.ICNTL(14),&lu->id.ICNTL(14),PETSC_NULL);CHKERRQ(ierr);
393397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_15","ICNTL(15): efficiency control","None",lu->id.ICNTL(15),&lu->id.ICNTL(15),PETSC_NULL);CHKERRQ(ierr);
394397b6df1SKris Buschelman 
395397b6df1SKris Buschelman     /*
396397b6df1SKris Buschelman     ierr = PetscOptionsInt("-mat_mumps_icntl_16","ICNTL(16): 1: rank detection; 2: rank detection and nullspace","None",lu->id.ICNTL(16),&icntl,&flg);CHKERRQ(ierr);
397397b6df1SKris Buschelman     if (flg){
398397b6df1SKris Buschelman       if (icntl >-1 && icntl <3 ){
399397b6df1SKris Buschelman         if (lu->myid==0) lu->id.ICNTL(16) = icntl;
400397b6df1SKris Buschelman       } else {
401397b6df1SKris Buschelman         SETERRQ1(PETSC_ERR_SUP,"ICNTL(16)=%d -- not supported\n",icntl);
402397b6df1SKris Buschelman       }
403397b6df1SKris Buschelman     }
404397b6df1SKris Buschelman     */
405397b6df1SKris Buschelman 
406397b6df1SKris Buschelman     ierr = PetscOptionsReal("-mat_mumps_cntl_1","CNTL(1): relative pivoting threshold","None",lu->id.CNTL(1),&lu->id.CNTL(1),PETSC_NULL);CHKERRQ(ierr);
407397b6df1SKris Buschelman     ierr = PetscOptionsReal("-mat_mumps_cntl_2","CNTL(2): stopping criterion of refinement","None",lu->id.CNTL(2),&lu->id.CNTL(2),PETSC_NULL);CHKERRQ(ierr);
408397b6df1SKris Buschelman     ierr = PetscOptionsReal("-mat_mumps_cntl_3","CNTL(3): absolute pivoting threshold","None",lu->id.CNTL(3),&lu->id.CNTL(3),PETSC_NULL);CHKERRQ(ierr);
409397b6df1SKris Buschelman     PetscOptionsEnd();
410397b6df1SKris Buschelman   }
411397b6df1SKris Buschelman 
412397b6df1SKris Buschelman   /* define matrix A */
413397b6df1SKris Buschelman   switch (lu->id.ICNTL(18)){
414397b6df1SKris Buschelman   case 0:  /* centralized assembled matrix input (size=1) */
415397b6df1SKris Buschelman     if (!lu->myid) {
416c36ead0aSKris Buschelman       if (lua->isAIJ){
417397b6df1SKris Buschelman         Mat_SeqAIJ   *aa = (Mat_SeqAIJ*)A->data;
418397b6df1SKris Buschelman         nz               = aa->nz;
419397b6df1SKris Buschelman         ai = aa->i; aj = aa->j; lu->val = aa->a;
420397b6df1SKris Buschelman       } else {
421397b6df1SKris Buschelman         Mat_SeqSBAIJ *aa = (Mat_SeqSBAIJ*)A->data;
422397b6df1SKris Buschelman         nz                  =  aa->s_nz;
423397b6df1SKris Buschelman         ai = aa->i; aj = aa->j; lu->val = aa->a;
424397b6df1SKris Buschelman       }
425397b6df1SKris Buschelman       if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){ /* first numeric factorization, get irn and jcn */
426397b6df1SKris Buschelman         ierr = PetscMalloc(nz*sizeof(int),&lu->irn);CHKERRQ(ierr);
427397b6df1SKris Buschelman         ierr = PetscMalloc(nz*sizeof(int),&lu->jcn);CHKERRQ(ierr);
428397b6df1SKris Buschelman         nz = 0;
429397b6df1SKris Buschelman         for (i=0; i<M; i++){
430397b6df1SKris Buschelman           rnz = ai[i+1] - ai[i];
431397b6df1SKris Buschelman           while (rnz--) {  /* Fortran row/col index! */
432397b6df1SKris Buschelman             lu->irn[nz] = i+1; lu->jcn[nz] = (*aj)+1; aj++; nz++;
433397b6df1SKris Buschelman           }
434397b6df1SKris Buschelman         }
435397b6df1SKris Buschelman       }
436397b6df1SKris Buschelman     }
437397b6df1SKris Buschelman     break;
438397b6df1SKris Buschelman   case 3:  /* distributed assembled matrix input (size>1) */
439397b6df1SKris Buschelman     if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
440397b6df1SKris Buschelman       valOnly = PETSC_FALSE;
441397b6df1SKris Buschelman     } else {
442397b6df1SKris Buschelman       valOnly = PETSC_TRUE; /* only update mat values, not row and col index */
443397b6df1SKris Buschelman     }
444397b6df1SKris Buschelman     ierr = MatConvertToTriples(A,1,valOnly, &nnz, &lu->irn, &lu->jcn, &lu->val);CHKERRQ(ierr);
445397b6df1SKris Buschelman     break;
446397b6df1SKris Buschelman   default: SETERRQ(PETSC_ERR_SUP,"Matrix input format is not supported by MUMPS.");
447397b6df1SKris Buschelman   }
448397b6df1SKris Buschelman 
449397b6df1SKris Buschelman   /* analysis phase */
450397b6df1SKris Buschelman   if (lu->matstruc == DIFFERENT_NONZERO_PATTERN){
451397b6df1SKris Buschelman      lu->id.n = M;
452397b6df1SKris Buschelman     switch (lu->id.ICNTL(18)){
453397b6df1SKris Buschelman     case 0:  /* centralized assembled matrix input */
454397b6df1SKris Buschelman       if (!lu->myid) {
455397b6df1SKris Buschelman         lu->id.nz =nz; lu->id.irn=lu->irn; lu->id.jcn=lu->jcn;
456397b6df1SKris Buschelman         if (lu->id.ICNTL(6)>1){
457397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
458397b6df1SKris Buschelman           lu->id.a = (mumps_double_complex*)lu->val;
459397b6df1SKris Buschelman #else
460397b6df1SKris Buschelman           lu->id.a = lu->val;
461397b6df1SKris Buschelman #endif
462397b6df1SKris Buschelman         }
463397b6df1SKris Buschelman       }
464397b6df1SKris Buschelman       break;
465397b6df1SKris Buschelman     case 3:  /* distributed assembled matrix input (size>1) */
466397b6df1SKris Buschelman       lu->id.nz_loc = nnz;
467397b6df1SKris Buschelman       lu->id.irn_loc=lu->irn; lu->id.jcn_loc=lu->jcn;
468397b6df1SKris Buschelman       if (lu->id.ICNTL(6)>1) {
469397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
470397b6df1SKris Buschelman         lu->id.a_loc = (mumps_double_complex*)lu->val;
471397b6df1SKris Buschelman #else
472397b6df1SKris Buschelman         lu->id.a_loc = lu->val;
473397b6df1SKris Buschelman #endif
474397b6df1SKris Buschelman       }
475397b6df1SKris Buschelman       break;
476397b6df1SKris Buschelman     }
477397b6df1SKris Buschelman     lu->id.job=1;
478397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
479397b6df1SKris Buschelman   zmumps_c(&lu->id);
480397b6df1SKris Buschelman #else
481397b6df1SKris Buschelman   dmumps_c(&lu->id);
482397b6df1SKris Buschelman #endif
483397b6df1SKris Buschelman     if (lu->id.INFOG(1) < 0) {
484397b6df1SKris Buschelman       SETERRQ1(1,"Error reported by MUMPS in analysis phase: INFOG(1)=%d\n",lu->id.INFOG(1));
485397b6df1SKris Buschelman     }
486397b6df1SKris Buschelman   }
487397b6df1SKris Buschelman 
488397b6df1SKris Buschelman   /* numerical factorization phase */
489397b6df1SKris Buschelman   if(lu->id.ICNTL(18) == 0) {
490397b6df1SKris Buschelman     if (lu->myid == 0) {
491397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
492397b6df1SKris Buschelman       lu->id.a = (mumps_double_complex*)lu->val;
493397b6df1SKris Buschelman #else
494397b6df1SKris Buschelman       lu->id.a = lu->val;
495397b6df1SKris Buschelman #endif
496397b6df1SKris Buschelman     }
497397b6df1SKris Buschelman   } else {
498397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
499397b6df1SKris Buschelman     lu->id.a_loc = (mumps_double_complex*)lu->val;
500397b6df1SKris Buschelman #else
501397b6df1SKris Buschelman     lu->id.a_loc = lu->val;
502397b6df1SKris Buschelman #endif
503397b6df1SKris Buschelman   }
504397b6df1SKris Buschelman   lu->id.job=2;
505397b6df1SKris Buschelman #if defined(PETSC_USE_COMPLEX)
506397b6df1SKris Buschelman   zmumps_c(&lu->id);
507397b6df1SKris Buschelman #else
508397b6df1SKris Buschelman   dmumps_c(&lu->id);
509397b6df1SKris Buschelman #endif
510397b6df1SKris Buschelman   if (lu->id.INFOG(1) < 0) {
511397b6df1SKris Buschelman     SETERRQ1(1,"1, Error reported by MUMPS in numerical factorization phase: INFOG(1)=%d\n",lu->id.INFOG(1));
512397b6df1SKris Buschelman   }
513397b6df1SKris Buschelman 
514397b6df1SKris Buschelman   if (lu->myid==0 && lu->id.ICNTL(16) > 0){
515397b6df1SKris Buschelman     SETERRQ1(1,"  lu->id.ICNTL(16):=%d\n",lu->id.INFOG(16));
516397b6df1SKris Buschelman   }
517397b6df1SKris Buschelman 
518397b6df1SKris Buschelman   (*F)->assembled  = PETSC_TRUE;
519397b6df1SKris Buschelman   lu->matstruc     = SAME_NONZERO_PATTERN;
520*ace87b0dSHong Zhang   lu->CleanUpMUMPS = PETSC_TRUE;
521397b6df1SKris Buschelman   PetscFunctionReturn(0);
522397b6df1SKris Buschelman }
523397b6df1SKris Buschelman 
524397b6df1SKris Buschelman /* Note the Petsc r and c permutations are ignored */
525397b6df1SKris Buschelman #undef __FUNCT__
526397b6df1SKris Buschelman #define __FUNCT__ "MatLUFactorSymbolic_AIJ_MUMPS"
527397b6df1SKris Buschelman int MatLUFactorSymbolic_AIJ_MUMPS(Mat A,IS r,IS c,MatFactorInfo *info,Mat *F)
528397b6df1SKris Buschelman {
529397b6df1SKris Buschelman   Mat              B;
530397b6df1SKris Buschelman   Mat_AIJ_MUMPS *lu;
531397b6df1SKris Buschelman   int              ierr;
532397b6df1SKris Buschelman 
533397b6df1SKris Buschelman   PetscFunctionBegin;
534397b6df1SKris Buschelman 
535397b6df1SKris Buschelman   /* Create the factorization matrix */
536397b6df1SKris Buschelman   ierr = MatCreate(A->comm,A->m,A->n,A->M,A->N,&B);CHKERRQ(ierr);
537397b6df1SKris Buschelman   ierr = MatSetType(B,MATAIJMUMPS);CHKERRQ(ierr);
538397b6df1SKris Buschelman   ierr = MatSeqAIJSetPreallocation(B,0,PETSC_NULL);CHKERRQ(ierr);
539397b6df1SKris Buschelman   ierr = MatMPIAIJSetPreallocation(B,0,PETSC_NULL,0,PETSC_NULL);CHKERRQ(ierr);
540397b6df1SKris Buschelman 
541397b6df1SKris Buschelman   B->ops->lufactornumeric = MatFactorNumeric_AIJ_MUMPS;
542397b6df1SKris Buschelman   B->factor               = FACTOR_LU;
5430e3434eeSKris Buschelman   lu                      = (Mat_AIJ_MUMPS*)B->spptr;
544397b6df1SKris Buschelman   lu->sym                 = 0;
545397b6df1SKris Buschelman   lu->matstruc            = DIFFERENT_NONZERO_PATTERN;
546397b6df1SKris Buschelman 
547397b6df1SKris Buschelman   *F = B;
548397b6df1SKris Buschelman   PetscFunctionReturn(0);
549397b6df1SKris Buschelman }
550397b6df1SKris Buschelman 
551397b6df1SKris Buschelman /* Note the Petsc r permutation is ignored */
552397b6df1SKris Buschelman #undef __FUNCT__
553397b6df1SKris Buschelman #define __FUNCT__ "MatCholeskyFactorSymbolic_AIJ_MUMPS"
554397b6df1SKris Buschelman int MatCholeskyFactorSymbolic_AIJ_MUMPS(Mat A,IS r,MatFactorInfo *info,Mat *F)
555397b6df1SKris Buschelman {
556397b6df1SKris Buschelman   Mat              B;
557397b6df1SKris Buschelman   Mat_AIJ_MUMPS *lu;
558397b6df1SKris Buschelman   int              ierr;
559397b6df1SKris Buschelman 
560397b6df1SKris Buschelman   PetscFunctionBegin;
561397b6df1SKris Buschelman 
562397b6df1SKris Buschelman   /* Create the factorization matrix */
563397b6df1SKris Buschelman   ierr = MatCreate(A->comm,A->m,A->n,A->M,A->N,&B);CHKERRQ(ierr);
564397b6df1SKris Buschelman   ierr = MatSetType(B,MATAIJMUMPS);CHKERRQ(ierr);
565397b6df1SKris Buschelman   ierr = MatSeqAIJSetPreallocation(B,0,PETSC_NULL);CHKERRQ(ierr);
566397b6df1SKris Buschelman   ierr = MatMPIAIJSetPreallocation(B,0,PETSC_NULL,0,PETSC_NULL);CHKERRQ(ierr);
567397b6df1SKris Buschelman 
568397b6df1SKris Buschelman   B->ops->choleskyfactornumeric = MatFactorNumeric_AIJ_MUMPS;
569397b6df1SKris Buschelman   B->factor                     = FACTOR_CHOLESKY;
570397b6df1SKris Buschelman   lu                            = (Mat_AIJ_MUMPS *)B->spptr;
571397b6df1SKris Buschelman   lu->sym                       = 2;
572397b6df1SKris Buschelman   lu->matstruc                  = DIFFERENT_NONZERO_PATTERN;
573397b6df1SKris Buschelman 
574397b6df1SKris Buschelman   *F = B;
575397b6df1SKris Buschelman   PetscFunctionReturn(0);
576397b6df1SKris Buschelman }
577397b6df1SKris Buschelman 
578397b6df1SKris Buschelman #undef __FUNCT__
579c338a77dSKris Buschelman #define __FUNCT__ "MatAssemblyEnd_AIJ_MUMPS"
580c338a77dSKris Buschelman int MatAssemblyEnd_AIJ_MUMPS(Mat A,MatAssemblyType mode) {
581c338a77dSKris Buschelman   int           ierr;
582c338a77dSKris Buschelman   Mat_AIJ_MUMPS *mumps=(Mat_AIJ_MUMPS*)A->spptr;
583c338a77dSKris Buschelman 
584397b6df1SKris Buschelman   PetscFunctionBegin;
585c338a77dSKris Buschelman   ierr = (*mumps->MatAssemblyEnd)(A,mode);CHKERRQ(ierr);
586c338a77dSKris Buschelman   mumps->MatLUFactorSymbolic       = A->ops->lufactorsymbolic;
587c338a77dSKris Buschelman   mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
588397b6df1SKris Buschelman   A->ops->lufactorsymbolic         = MatLUFactorSymbolic_AIJ_MUMPS;
589397b6df1SKris Buschelman   PetscFunctionReturn(0);
590397b6df1SKris Buschelman }
591397b6df1SKris Buschelman 
592c338a77dSKris Buschelman EXTERN_C_BEGIN
593c338a77dSKris Buschelman #undef __FUNCT__
594f579278aSKris Buschelman #define __FUNCT__ "MatConvert_AIJ_MUMPS"
595f579278aSKris Buschelman int MatConvert_AIJ_MUMPS(Mat A,MatType newtype,Mat *newmat) {
596c338a77dSKris Buschelman   int           ierr,size;
597c338a77dSKris Buschelman   MPI_Comm      comm;
598c338a77dSKris Buschelman   Mat           B=*newmat;
599c338a77dSKris Buschelman   Mat_AIJ_MUMPS *mumps;
600397b6df1SKris Buschelman 
601397b6df1SKris Buschelman   PetscFunctionBegin;
602c338a77dSKris Buschelman   if (B != A) {
603c338a77dSKris Buschelman     ierr = MatDuplicate(A,MAT_COPY_VALUES,&B);CHKERRQ(ierr);
604397b6df1SKris Buschelman   }
605397b6df1SKris Buschelman 
606c338a77dSKris Buschelman   ierr = PetscObjectGetComm((PetscObject)A,&comm);CHKERRQ(ierr);
607c338a77dSKris Buschelman   ierr = PetscNew(Mat_AIJ_MUMPS,&mumps);CHKERRQ(ierr);
608c338a77dSKris Buschelman 
609c338a77dSKris Buschelman   mumps->MatView                   = A->ops->view;
610c338a77dSKris Buschelman   mumps->MatAssemblyEnd            = A->ops->assemblyend;
611c338a77dSKris Buschelman   mumps->MatLUFactorSymbolic       = A->ops->lufactorsymbolic;
612c338a77dSKris Buschelman   mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
613c338a77dSKris Buschelman   mumps->MatDestroy                = A->ops->destroy;
614c338a77dSKris Buschelman   mumps->CleanUpMUMPS              = PETSC_FALSE;
615f579278aSKris Buschelman   mumps->isAIJ                     = PETSC_TRUE;
616c338a77dSKris Buschelman 
6174b68dd72SKris Buschelman   B->spptr                         = (void *)mumps;
6184b68dd72SKris Buschelman   B->ops->view                     = MatView_AIJ_MUMPS;
6194b68dd72SKris Buschelman   B->ops->assemblyend              = MatAssemblyEnd_AIJ_MUMPS;
6204b68dd72SKris Buschelman   B->ops->lufactorsymbolic         = MatLUFactorSymbolic_AIJ_MUMPS;
6214b68dd72SKris Buschelman   B->ops->destroy                  = MatDestroy_AIJ_MUMPS;
622c338a77dSKris Buschelman 
623c338a77dSKris Buschelman   ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);CHKERRQ(ierr);
624c338a77dSKris Buschelman   if (size == 1) {
625c338a77dSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqaij_aijmumps_C",
626f579278aSKris Buschelman                                              "MatConvert_AIJ_MUMPS",MatConvert_AIJ_MUMPS);CHKERRQ(ierr);
627c338a77dSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_aijmumps_seqaij_C",
628c338a77dSKris Buschelman                                              "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);CHKERRQ(ierr);
629c338a77dSKris Buschelman   } else {
630c338a77dSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mpiaij_aijmumps_C",
631f579278aSKris Buschelman                                              "MatConvert_AIJ_MUMPS",MatConvert_AIJ_MUMPS);CHKERRQ(ierr);
632c338a77dSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_aijmumps_mpiaij_C",
633c338a77dSKris Buschelman                                              "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);CHKERRQ(ierr);
634c338a77dSKris Buschelman   }
635c338a77dSKris Buschelman 
636f579278aSKris Buschelman   PetscLogInfo(0,"Using MUMPS for LU factorization and solves.");
637c338a77dSKris Buschelman   ierr = PetscObjectChangeTypeName((PetscObject)B,newtype);CHKERRQ(ierr);
638c338a77dSKris Buschelman   *newmat = B;
639397b6df1SKris Buschelman   PetscFunctionReturn(0);
640397b6df1SKris Buschelman }
641c338a77dSKris Buschelman EXTERN_C_END
642397b6df1SKris Buschelman 
64324b6179bSKris Buschelman /*MC
644f579278aSKris Buschelman   MATAIJMUMPS - a matrix type providing direct solvers (LU) for distributed
64524b6179bSKris Buschelman   and sequential matrices via the external package MUMPS.
64624b6179bSKris Buschelman 
64724b6179bSKris Buschelman   If MUMPS is installed (see the manual for instructions
64824b6179bSKris Buschelman   on how to declare the existence of external packages),
64924b6179bSKris Buschelman   a matrix type can be constructed which invokes MUMPS solvers.
65024b6179bSKris Buschelman   After calling MatCreate(...,A), simply call MatSetType(A,MATAIJMUMPS).
65124b6179bSKris Buschelman   This matrix type is only supported for double precision real.
65224b6179bSKris Buschelman 
65324b6179bSKris Buschelman   If created with a single process communicator, this matrix type inherits from MATSEQAIJ.
65424b6179bSKris Buschelman   Otherwise, this matrix type inherits from MATMPIAIJ.  Hence for single process communicators,
65524b6179bSKris Buschelman   MatSeqAIJSetPreallocation is supported, and similarly MatMPIAIJSetPreallocation is supported
65624b6179bSKris Buschelman   for communicators controlling multiple processes.  It is recommended that you call both of
65724b6179bSKris Buschelman   the above preallocation routines for simplicity.
65824b6179bSKris Buschelman 
65924b6179bSKris Buschelman   Options Database Keys:
66024b6179bSKris Buschelman + -mat_type aijmumps
66124b6179bSKris Buschelman . -mat_mumps_sym <0,1,2> - 0 the matrix is unsymmetric, 1 symmetric positive definite, 2 symmetric
66224b6179bSKris Buschelman . -mat_mumps_icntl_4 <0,1,2,3,4> - print level
66324b6179bSKris Buschelman . -mat_mumps_icntl_6 <0,...,7> - matrix prescaling options (see MUMPS User's Guide)
66424b6179bSKris Buschelman . -mat_mumps_icntl_7 <0,...,7> - matrix orderings (see MUMPS User's Guide)
66524b6179bSKris Buschelman . -mat_mumps_icntl_9 <1,2> - A or A^T x=b to be solved: 1 denotes A, 2 denotes A^T
66624b6179bSKris Buschelman . -mat_mumps_icntl_10 <n> - maximum number of iterative refinements
66724b6179bSKris Buschelman . -mat_mumps_icntl_11 <n> - error analysis, a positive value returns statistics during -sles_view
66824b6179bSKris Buschelman . -mat_mumps_icntl_12 <n> - efficiency control (see MUMPS User's Guide)
66924b6179bSKris Buschelman . -mat_mumps_icntl_13 <n> - efficiency control (see MUMPS User's Guide)
67024b6179bSKris Buschelman . -mat_mumps_icntl_14 <n> - efficiency control (see MUMPS User's Guide)
67124b6179bSKris Buschelman . -mat_mumps_icntl_15 <n> - efficiency control (see MUMPS User's Guide)
67224b6179bSKris Buschelman . -mat_mumps_cntl_1 <delta> - relative pivoting threshold
67324b6179bSKris Buschelman . -mat_mumps_cntl_2 <tol> - stopping criterion for refinement
67424b6179bSKris Buschelman - -mat_mumps_cntl_3 <adelta> - absolute pivoting threshold
67524b6179bSKris Buschelman 
67624b6179bSKris Buschelman   Level: beginner
67724b6179bSKris Buschelman 
67824b6179bSKris Buschelman .seealso: MATSBAIJMUMPS
67924b6179bSKris Buschelman M*/
68024b6179bSKris Buschelman 
681397b6df1SKris Buschelman EXTERN_C_BEGIN
682397b6df1SKris Buschelman #undef __FUNCT__
683397b6df1SKris Buschelman #define __FUNCT__ "MatCreate_AIJ_MUMPS"
684397b6df1SKris Buschelman int MatCreate_AIJ_MUMPS(Mat A) {
685397b6df1SKris Buschelman   int           ierr,size;
686397b6df1SKris Buschelman   MPI_Comm      comm;
687397b6df1SKris Buschelman 
688397b6df1SKris Buschelman   PetscFunctionBegin;
689397b6df1SKris Buschelman   ierr = PetscObjectGetComm((PetscObject)A,&comm);CHKERRQ(ierr);
690397b6df1SKris Buschelman   ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);CHKERRQ(ierr);
691397b6df1SKris Buschelman   if (size == 1) {
692397b6df1SKris Buschelman     ierr = MatSetType(A,MATSEQAIJ);CHKERRQ(ierr);
693397b6df1SKris Buschelman   } else {
694397b6df1SKris Buschelman     ierr = MatSetType(A,MATMPIAIJ);CHKERRQ(ierr);
695397b6df1SKris Buschelman   }
6969e8b7c08SKris Buschelman   ierr = MatConvert_AIJ_MUMPS(A,MATAIJMUMPS,&A);CHKERRQ(ierr);
697397b6df1SKris Buschelman   PetscFunctionReturn(0);
698397b6df1SKris Buschelman }
699397b6df1SKris Buschelman EXTERN_C_END
700397b6df1SKris Buschelman 
701f579278aSKris Buschelman EXTERN_C_BEGIN
702f579278aSKris Buschelman #undef __FUNCT__
703f579278aSKris Buschelman #define __FUNCT__ "MatLoad_AIJ_MUMPS"
704f579278aSKris Buschelman int MatLoad_AIJ_MUMPS(PetscViewer viewer,MatType type,Mat *A) {
705f579278aSKris Buschelman   int ierr,size,(*r)(PetscViewer,MatType,Mat*);
706f579278aSKris Buschelman   MPI_Comm comm;
707f579278aSKris Buschelman 
708f579278aSKris Buschelman   PetscFunctionBegin;
709f579278aSKris Buschelman   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
710f579278aSKris Buschelman   ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
711f579278aSKris Buschelman   if (size == 1) {
712f579278aSKris Buschelman     ierr = PetscFListFind(comm,MatLoadList,MATSEQAIJ,(void(**)(void))&r);CHKERRQ(ierr);
713f579278aSKris Buschelman   } else {
714f579278aSKris Buschelman     ierr = PetscFListFind(comm,MatLoadList,MATMPIAIJ,(void(**)(void))&r);CHKERRQ(ierr);
715f579278aSKris Buschelman   }
716f579278aSKris Buschelman   ierr = (*r)(viewer,type,A);CHKERRQ(ierr);
717f579278aSKris Buschelman   PetscFunctionReturn(0);
718f579278aSKris Buschelman }
719f579278aSKris Buschelman EXTERN_C_END
720f579278aSKris Buschelman 
721f579278aSKris Buschelman #undef __FUNCT__
722f579278aSKris Buschelman #define __FUNCT__ "MatAssemblyEnd_AIJ_MUMPS"
723f579278aSKris Buschelman int MatAssemblyEnd_SBAIJ_MUMPS(Mat A,MatAssemblyType mode) {
724f579278aSKris Buschelman   int           ierr;
725f579278aSKris Buschelman   Mat_AIJ_MUMPS *mumps=(Mat_AIJ_MUMPS*)A->spptr;
726f579278aSKris Buschelman 
727f579278aSKris Buschelman   PetscFunctionBegin;
728f579278aSKris Buschelman   ierr = (*mumps->MatAssemblyEnd)(A,mode);CHKERRQ(ierr);
729f579278aSKris Buschelman   mumps->MatLUFactorSymbolic       = A->ops->lufactorsymbolic;
730f579278aSKris Buschelman   mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
731f579278aSKris Buschelman   A->ops->choleskyfactorsymbolic   = MatCholeskyFactorSymbolic_AIJ_MUMPS;
732f579278aSKris Buschelman   PetscFunctionReturn(0);
733f579278aSKris Buschelman }
734f579278aSKris Buschelman 
735f579278aSKris Buschelman EXTERN_C_BEGIN
736f579278aSKris Buschelman #undef __FUNCT__
737f579278aSKris Buschelman #define __FUNCT__ "MatConvert_SBAIJ_MUMPS"
738f579278aSKris Buschelman int MatConvert_SBAIJ_MUMPS(Mat A,MatType newtype,Mat *newmat) {
739f579278aSKris Buschelman   int           ierr,size;
740f579278aSKris Buschelman   MPI_Comm      comm;
741f579278aSKris Buschelman   Mat           B=*newmat;
742f579278aSKris Buschelman   Mat_AIJ_MUMPS *mumps;
743f579278aSKris Buschelman 
744f579278aSKris Buschelman   PetscFunctionBegin;
745f579278aSKris Buschelman   if (B != A) {
746f579278aSKris Buschelman     ierr = MatDuplicate(A,MAT_COPY_VALUES,&B);CHKERRQ(ierr);
747f579278aSKris Buschelman   }
748f579278aSKris Buschelman 
749f579278aSKris Buschelman   ierr = PetscObjectGetComm((PetscObject)A,&comm);CHKERRQ(ierr);
750f579278aSKris Buschelman   ierr = PetscNew(Mat_AIJ_MUMPS,&mumps);CHKERRQ(ierr);
751f579278aSKris Buschelman 
752f579278aSKris Buschelman   mumps->MatView                   = A->ops->view;
753f579278aSKris Buschelman   mumps->MatAssemblyEnd            = A->ops->assemblyend;
754f579278aSKris Buschelman   mumps->MatLUFactorSymbolic       = A->ops->lufactorsymbolic;
755f579278aSKris Buschelman   mumps->MatCholeskyFactorSymbolic = A->ops->choleskyfactorsymbolic;
756f579278aSKris Buschelman   mumps->MatDestroy                = A->ops->destroy;
757f579278aSKris Buschelman   mumps->CleanUpMUMPS              = PETSC_FALSE;
758f579278aSKris Buschelman   mumps->isAIJ                     = PETSC_FALSE;
759f579278aSKris Buschelman 
760f579278aSKris Buschelman   B->spptr                         = (void *)mumps;
761f579278aSKris Buschelman   B->ops->view                     = MatView_AIJ_MUMPS;
762f579278aSKris Buschelman   B->ops->assemblyend              = MatAssemblyEnd_SBAIJ_MUMPS;
763f579278aSKris Buschelman   B->ops->choleskyfactorsymbolic   = MatCholeskyFactorSymbolic_AIJ_MUMPS;
764f579278aSKris Buschelman   B->ops->destroy                  = MatDestroy_AIJ_MUMPS;
765f579278aSKris Buschelman 
766f579278aSKris Buschelman   ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);CHKERRQ(ierr);
767f579278aSKris Buschelman   if (size == 1) {
768f579278aSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_seqsbaij_mumps_C",
769f579278aSKris Buschelman                                              "MatConvert_SBAIJ_MUMPS",MatConvert_SBAIJ_MUMPS);CHKERRQ(ierr);
770f579278aSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mumps_seqsbaij_C",
771f579278aSKris Buschelman                                              "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);CHKERRQ(ierr);
772f579278aSKris Buschelman   } else {
773f579278aSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mpisbaij_mumps_C",
774f579278aSKris Buschelman                                              "MatConvert_SBAIJ_MUMPS",MatConvert_SBAIJ_MUMPS);CHKERRQ(ierr);
775f579278aSKris Buschelman     ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatConvert_mumps_mpisbaij_C",
776f579278aSKris Buschelman                                              "MatConvert_MUMPS_Base",MatConvert_MUMPS_Base);CHKERRQ(ierr);
777f579278aSKris Buschelman   }
778f579278aSKris Buschelman 
779f579278aSKris Buschelman   PetscLogInfo(0,"Using MUMPS for Cholesky factorization and solves.");
780f579278aSKris Buschelman   ierr = PetscObjectChangeTypeName((PetscObject)B,newtype);CHKERRQ(ierr);
781f579278aSKris Buschelman   *newmat = B;
782f579278aSKris Buschelman   PetscFunctionReturn(0);
783f579278aSKris Buschelman }
784f579278aSKris Buschelman EXTERN_C_END
785f579278aSKris Buschelman 
78624b6179bSKris Buschelman /*MC
787f579278aSKris Buschelman   MATSBAIJMUMPS - a symmetric matrix type providing direct solvers (Cholesky) for
78824b6179bSKris Buschelman   distributed and sequential matrices via the external package MUMPS.
78924b6179bSKris Buschelman 
79024b6179bSKris Buschelman   If MUMPS is installed (see the manual for instructions
79124b6179bSKris Buschelman   on how to declare the existence of external packages),
79224b6179bSKris Buschelman   a matrix type can be constructed which invokes MUMPS solvers.
79324b6179bSKris Buschelman   After calling MatCreate(...,A), simply call MatSetType(A,MATSBAIJMUMPS).
79424b6179bSKris Buschelman   This matrix type is only supported for double precision real.
79524b6179bSKris Buschelman 
79624b6179bSKris Buschelman   If created with a single process communicator, this matrix type inherits from MATSEQSBAIJ.
79724b6179bSKris Buschelman   Otherwise, this matrix type inherits from MATMPISBAIJ.  Hence for single process communicators,
79824b6179bSKris Buschelman   MatSeqSBAIJSetPreallocation is supported, and similarly MatMPISBAIJSetPreallocation is supported
79924b6179bSKris Buschelman   for communicators controlling multiple processes.  It is recommended that you call both of
80024b6179bSKris Buschelman   the above preallocation routines for simplicity.
80124b6179bSKris Buschelman 
80224b6179bSKris Buschelman   Options Database Keys:
80324b6179bSKris Buschelman + -mat_type aijmumps
80424b6179bSKris Buschelman . -mat_mumps_sym <0,1,2> - 0 the matrix is unsymmetric, 1 symmetric positive definite, 2 symmetric
80524b6179bSKris Buschelman . -mat_mumps_icntl_4 <0,...,4> - print level
80624b6179bSKris Buschelman . -mat_mumps_icntl_6 <0,...,7> - matrix prescaling options (see MUMPS User's Guide)
80724b6179bSKris Buschelman . -mat_mumps_icntl_7 <0,...,7> - matrix orderings (see MUMPS User's Guide)
80824b6179bSKris Buschelman . -mat_mumps_icntl_9 <1,2> - A or A^T x=b to be solved: 1 denotes A, 2 denotes A^T
80924b6179bSKris Buschelman . -mat_mumps_icntl_10 <n> - maximum number of iterative refinements
81024b6179bSKris Buschelman . -mat_mumps_icntl_11 <n> - error analysis, a positive value returns statistics during -sles_view
81124b6179bSKris Buschelman . -mat_mumps_icntl_12 <n> - efficiency control (see MUMPS User's Guide)
81224b6179bSKris Buschelman . -mat_mumps_icntl_13 <n> - efficiency control (see MUMPS User's Guide)
81324b6179bSKris Buschelman . -mat_mumps_icntl_14 <n> - efficiency control (see MUMPS User's Guide)
81424b6179bSKris Buschelman . -mat_mumps_icntl_15 <n> - efficiency control (see MUMPS User's Guide)
81524b6179bSKris Buschelman . -mat_mumps_cntl_1 <delta> - relative pivoting threshold
81624b6179bSKris Buschelman . -mat_mumps_cntl_2 <tol> - stopping criterion for refinement
81724b6179bSKris Buschelman - -mat_mumps_cntl_3 <adelta> - absolute pivoting threshold
81824b6179bSKris Buschelman 
81924b6179bSKris Buschelman   Level: beginner
82024b6179bSKris Buschelman 
82124b6179bSKris Buschelman .seealso: MATAIJMUMPS
82224b6179bSKris Buschelman M*/
82324b6179bSKris Buschelman 
824397b6df1SKris Buschelman EXTERN_C_BEGIN
825397b6df1SKris Buschelman #undef __FUNCT__
826397b6df1SKris Buschelman #define __FUNCT__ "MatCreate_SBAIJ_MUMPS"
827397b6df1SKris Buschelman int MatCreate_SBAIJ_MUMPS(Mat A) {
828397b6df1SKris Buschelman   int           ierr,size;
829397b6df1SKris Buschelman   MPI_Comm      comm;
830397b6df1SKris Buschelman 
831397b6df1SKris Buschelman   PetscFunctionBegin;
832397b6df1SKris Buschelman   ierr = PetscObjectGetComm((PetscObject)A,&comm);CHKERRQ(ierr);
833397b6df1SKris Buschelman   ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);CHKERRQ(ierr);
834397b6df1SKris Buschelman   if (size == 1) {
835397b6df1SKris Buschelman     ierr = MatSetType(A,MATSEQSBAIJ);CHKERRQ(ierr);
836397b6df1SKris Buschelman   } else {
837397b6df1SKris Buschelman     ierr = MatSetType(A,MATMPISBAIJ);CHKERRQ(ierr);
838397b6df1SKris Buschelman   }
8399e8b7c08SKris Buschelman   ierr = MatConvert_SBAIJ_MUMPS(A,MATSBAIJMUMPS,&A);CHKERRQ(ierr);
840397b6df1SKris Buschelman   PetscFunctionReturn(0);
841397b6df1SKris Buschelman }
842397b6df1SKris Buschelman EXTERN_C_END
843397b6df1SKris Buschelman 
844397b6df1SKris Buschelman EXTERN_C_BEGIN
845397b6df1SKris Buschelman #undef __FUNCT__
846397b6df1SKris Buschelman #define __FUNCT__ "MatLoad_SBAIJ_MUMPS"
847397b6df1SKris Buschelman int MatLoad_SBAIJ_MUMPS(PetscViewer viewer,MatType type,Mat *A) {
848397b6df1SKris Buschelman   int ierr,size,(*r)(PetscViewer,MatType,Mat*);
849397b6df1SKris Buschelman   MPI_Comm comm;
850397b6df1SKris Buschelman 
851397b6df1SKris Buschelman   PetscFunctionBegin;
852397b6df1SKris Buschelman   ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
853397b6df1SKris Buschelman   ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
854397b6df1SKris Buschelman   if (size == 1) {
855397b6df1SKris Buschelman     ierr = PetscFListFind(comm,MatLoadList,MATSEQSBAIJ,(void(**)(void))&r);CHKERRQ(ierr);
856397b6df1SKris Buschelman   } else {
857397b6df1SKris Buschelman     ierr = PetscFListFind(comm,MatLoadList,MATMPISBAIJ,(void(**)(void))&r);CHKERRQ(ierr);
858397b6df1SKris Buschelman   }
859397b6df1SKris Buschelman   ierr = (*r)(viewer,type,A);CHKERRQ(ierr);
860397b6df1SKris Buschelman   PetscFunctionReturn(0);
861397b6df1SKris Buschelman }
862397b6df1SKris Buschelman EXTERN_C_END
863