xref: /petsc/src/mat/impls/aij/seq/aijsell/aijsell.c (revision 1baa6e3354bfe224b33a0c158f482508792a8a6e)
14dfdc2d9SRichard Tran Mills /*
24dfdc2d9SRichard Tran Mills   Defines basic operations for the MATSEQAIJSELL matrix class.
34dfdc2d9SRichard Tran Mills   This class is derived from the MATAIJCLASS, but maintains a "shadow" copy
44dfdc2d9SRichard Tran Mills   of the matrix stored in MATSEQSELL format, which is used as appropriate for
54dfdc2d9SRichard Tran Mills   performing operations for which this format is more suitable.
64dfdc2d9SRichard Tran Mills */
74dfdc2d9SRichard Tran Mills 
84dfdc2d9SRichard Tran Mills #include <../src/mat/impls/aij/seq/aij.h>
9b0e5de86SRichard Tran Mills #include <../src/mat/impls/sell/seq/sell.h>
104dfdc2d9SRichard Tran Mills 
114dfdc2d9SRichard Tran Mills typedef struct {
124dfdc2d9SRichard Tran Mills   Mat              S; /* The SELL formatted "shadow" matrix. */
134dfdc2d9SRichard Tran Mills   PetscBool        eager_shadow;
144dfdc2d9SRichard Tran Mills   PetscObjectState state; /* State of the matrix when shadow matrix was last constructed. */
154dfdc2d9SRichard Tran Mills } Mat_SeqAIJSELL;
164dfdc2d9SRichard Tran Mills 
174dfdc2d9SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJSELL_SeqAIJ(Mat A,MatType type,MatReuse reuse,Mat *newmat)
184dfdc2d9SRichard Tran Mills {
194dfdc2d9SRichard Tran Mills   /* This routine is only called to convert a MATAIJSELL to its base PETSc type, */
204dfdc2d9SRichard Tran Mills   /* so we will ignore 'MatType type'. */
214dfdc2d9SRichard Tran Mills   Mat            B        = *newmat;
224dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL *aijsell = (Mat_SeqAIJSELL*) A->spptr;
234dfdc2d9SRichard Tran Mills 
244dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
254dfdc2d9SRichard Tran Mills   if (reuse == MAT_INITIAL_MATRIX) {
269566063dSJacob Faibussowitsch     PetscCall(MatDuplicate(A,MAT_COPY_VALUES,&B));
274dfdc2d9SRichard Tran Mills   }
284dfdc2d9SRichard Tran Mills 
294dfdc2d9SRichard Tran Mills   /* Reset the original function pointers. */
304dfdc2d9SRichard Tran Mills   B->ops->duplicate        = MatDuplicate_SeqAIJ;
314dfdc2d9SRichard Tran Mills   B->ops->assemblyend      = MatAssemblyEnd_SeqAIJ;
324dfdc2d9SRichard Tran Mills   B->ops->destroy          = MatDestroy_SeqAIJ;
334dfdc2d9SRichard Tran Mills   B->ops->mult             = MatMult_SeqAIJ;
344dfdc2d9SRichard Tran Mills   B->ops->multtranspose    = MatMultTranspose_SeqAIJ;
354dfdc2d9SRichard Tran Mills   B->ops->multadd          = MatMultAdd_SeqAIJ;
364dfdc2d9SRichard Tran Mills   B->ops->multtransposeadd = MatMultTransposeAdd_SeqAIJ;
37af22a668SRichard Tran Mills   B->ops->sor              = MatSOR_SeqAIJ;
384dfdc2d9SRichard Tran Mills 
399566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)B,"MatConvert_seqaijsell_seqaij_C",NULL));
404dfdc2d9SRichard Tran Mills 
414dfdc2d9SRichard Tran Mills   if (reuse == MAT_INITIAL_MATRIX) aijsell = (Mat_SeqAIJSELL*)B->spptr;
424dfdc2d9SRichard Tran Mills 
438cde19baSRichard Tran Mills   /* Clean up the Mat_SeqAIJSELL data structure.
448cde19baSRichard Tran Mills    * Note that MatDestroy() simply returns if passed a NULL value, so it's OK to call even if the shadow matrix was never constructed. */
459566063dSJacob Faibussowitsch   PetscCall(MatDestroy(&aijsell->S));
469566063dSJacob Faibussowitsch   PetscCall(PetscFree(B->spptr));
474dfdc2d9SRichard Tran Mills 
484dfdc2d9SRichard Tran Mills   /* Change the type of B to MATSEQAIJ. */
499566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject)B, MATSEQAIJ));
504dfdc2d9SRichard Tran Mills 
514dfdc2d9SRichard Tran Mills   *newmat = B;
524dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
534dfdc2d9SRichard Tran Mills }
544dfdc2d9SRichard Tran Mills 
554dfdc2d9SRichard Tran Mills PetscErrorCode MatDestroy_SeqAIJSELL(Mat A)
564dfdc2d9SRichard Tran Mills {
574dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL  *aijsell = (Mat_SeqAIJSELL*) A->spptr;
584dfdc2d9SRichard Tran Mills 
594dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
604dfdc2d9SRichard Tran Mills 
614dfdc2d9SRichard Tran Mills   /* If MatHeaderMerge() was used, then this SeqAIJSELL matrix will not have an
624dfdc2d9SRichard Tran Mills    * spptr pointer. */
634dfdc2d9SRichard Tran Mills   if (aijsell) {
644dfdc2d9SRichard Tran Mills     /* Clean up everything in the Mat_SeqAIJSELL data structure, then free A->spptr. */
659566063dSJacob Faibussowitsch     PetscCall(MatDestroy(&aijsell->S));
669566063dSJacob Faibussowitsch     PetscCall(PetscFree(A->spptr));
674dfdc2d9SRichard Tran Mills   }
684dfdc2d9SRichard Tran Mills 
694dfdc2d9SRichard Tran Mills   /* Change the type of A back to SEQAIJ and use MatDestroy_SeqAIJ()
704dfdc2d9SRichard Tran Mills    * to destroy everything that remains. */
719566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject)A, MATSEQAIJ));
724dfdc2d9SRichard Tran Mills   /* Note that I don't call MatSetType().  I believe this is because that
734dfdc2d9SRichard Tran Mills    * is only to be called when *building* a matrix.  I could be wrong, but
744dfdc2d9SRichard Tran Mills    * that is how things work for the SuperLU matrix class. */
752e956fe4SStefano Zampini   PetscCall(PetscObjectComposeFunction((PetscObject)A,"MatConvert_seqaijsell_seqaij_C",NULL));
769566063dSJacob Faibussowitsch   PetscCall(MatDestroy_SeqAIJ(A));
774dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
784dfdc2d9SRichard Tran Mills }
794dfdc2d9SRichard Tran Mills 
80a2a1850bSRichard Tran Mills /* Build or update the shadow matrix if and only if needed.
81a2a1850bSRichard Tran Mills  * We track the ObjectState to determine when this needs to be done. */
82b0e5de86SRichard Tran Mills PETSC_INTERN PetscErrorCode MatSeqAIJSELL_build_shadow(Mat A)
83b0e5de86SRichard Tran Mills {
84b0e5de86SRichard Tran Mills   Mat_SeqAIJSELL   *aijsell = (Mat_SeqAIJSELL*) A->spptr;
85a2a1850bSRichard Tran Mills   PetscObjectState state;
86b0e5de86SRichard Tran Mills 
87b0e5de86SRichard Tran Mills   PetscFunctionBegin;
889566063dSJacob Faibussowitsch   PetscCall(PetscObjectStateGet((PetscObject)A,&state));
89a2a1850bSRichard Tran Mills   if (aijsell->S && aijsell->state == state) {
90a2a1850bSRichard Tran Mills     /* The existing shadow matrix is up-to-date, so simply exit. */
91a2a1850bSRichard Tran Mills     PetscFunctionReturn(0);
92a2a1850bSRichard Tran Mills   }
93a2a1850bSRichard Tran Mills 
949566063dSJacob Faibussowitsch   PetscCall(PetscLogEventBegin(MAT_Convert,A,0,0,0));
95b0e5de86SRichard Tran Mills   if (aijsell->S) {
969566063dSJacob Faibussowitsch     PetscCall(MatConvert_SeqAIJ_SeqSELL(A,MATSEQSELL,MAT_REUSE_MATRIX,&aijsell->S));
97b0e5de86SRichard Tran Mills   } else {
989566063dSJacob Faibussowitsch     PetscCall(MatConvert_SeqAIJ_SeqSELL(A,MATSEQSELL,MAT_INITIAL_MATRIX,&aijsell->S));
99b0e5de86SRichard Tran Mills   }
1009566063dSJacob Faibussowitsch   PetscCall(PetscLogEventEnd(MAT_Convert,A,0,0,0));
101b0e5de86SRichard Tran Mills 
102b0e5de86SRichard Tran Mills   /* Record the ObjectState so that we can tell when the shadow matrix needs updating */
1039566063dSJacob Faibussowitsch   PetscCall(PetscObjectStateGet((PetscObject)A,&aijsell->state));
104b0e5de86SRichard Tran Mills 
105b0e5de86SRichard Tran Mills   PetscFunctionReturn(0);
106b0e5de86SRichard Tran Mills }
107b0e5de86SRichard Tran Mills 
1084dfdc2d9SRichard Tran Mills PetscErrorCode MatDuplicate_SeqAIJSELL(Mat A, MatDuplicateOption op, Mat *M)
1094dfdc2d9SRichard Tran Mills {
1104dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL *aijsell;
1114dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL *aijsell_dest;
1124dfdc2d9SRichard Tran Mills 
1134dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
1149566063dSJacob Faibussowitsch   PetscCall(MatDuplicate_SeqAIJ(A,op,M));
1154dfdc2d9SRichard Tran Mills   aijsell      = (Mat_SeqAIJSELL*) A->spptr;
1164dfdc2d9SRichard Tran Mills   aijsell_dest = (Mat_SeqAIJSELL*) (*M)->spptr;
1179566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy(aijsell_dest,aijsell,1));
1184dfdc2d9SRichard Tran Mills   /* We don't duplicate the shadow matrix -- that will be constructed as needed. */
1194dfdc2d9SRichard Tran Mills   aijsell_dest->S = NULL;
120*1baa6e33SBarry Smith   if (aijsell->eager_shadow) PetscCall(MatSeqAIJSELL_build_shadow(A));
1214dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
1224dfdc2d9SRichard Tran Mills }
1234dfdc2d9SRichard Tran Mills 
1244dfdc2d9SRichard Tran Mills PetscErrorCode MatAssemblyEnd_SeqAIJSELL(Mat A, MatAssemblyType mode)
1254dfdc2d9SRichard Tran Mills {
1264dfdc2d9SRichard Tran Mills   Mat_SeqAIJ      *a = (Mat_SeqAIJ*)A->data;
1278cde19baSRichard Tran Mills   Mat_SeqAIJSELL  *aijsell = (Mat_SeqAIJSELL*)A->spptr;
1284dfdc2d9SRichard Tran Mills 
1294dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
1304dfdc2d9SRichard Tran Mills   if (mode == MAT_FLUSH_ASSEMBLY) PetscFunctionReturn(0);
1314dfdc2d9SRichard Tran Mills 
1324dfdc2d9SRichard Tran Mills   /* I disable the use of the inode routines so that the AIJSELL ones will be
1334dfdc2d9SRichard Tran Mills    * used instead, but I wonder if it might make sense (and is feasible) to
1344dfdc2d9SRichard Tran Mills    * use some of them. */
1354dfdc2d9SRichard Tran Mills   a->inode.use = PETSC_FALSE;
1364dfdc2d9SRichard Tran Mills 
1374dfdc2d9SRichard Tran Mills   /* Since a MATSEQAIJSELL matrix is really just a MATSEQAIJ with some
1384dfdc2d9SRichard Tran Mills    * extra information and some different methods, call the AssemblyEnd
1394dfdc2d9SRichard Tran Mills    * routine for a MATSEQAIJ.
1404dfdc2d9SRichard Tran Mills    * I'm not sure if this is the best way to do this, but it avoids
1414dfdc2d9SRichard Tran Mills    * a lot of code duplication. */
1424dfdc2d9SRichard Tran Mills 
1439566063dSJacob Faibussowitsch   PetscCall(MatAssemblyEnd_SeqAIJ(A, mode));
1444dfdc2d9SRichard Tran Mills 
1454dfdc2d9SRichard Tran Mills   /* If the user has requested "eager" shadowing, create the SELL shadow matrix (if needed; the function checks).
1464dfdc2d9SRichard Tran Mills    * (The default is to take a "lazy" approach, deferring this until something like MatMult() is called.) */
147*1baa6e33SBarry Smith   if (aijsell->eager_shadow) PetscCall(MatSeqAIJSELL_build_shadow(A));
1484dfdc2d9SRichard Tran Mills 
1494dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
1504dfdc2d9SRichard Tran Mills }
1514dfdc2d9SRichard Tran Mills 
152b0e5de86SRichard Tran Mills PetscErrorCode MatMult_SeqAIJSELL(Mat A,Vec xx,Vec yy)
153b0e5de86SRichard Tran Mills {
154b0e5de86SRichard Tran Mills   Mat_SeqAIJSELL    *aijsell = (Mat_SeqAIJSELL*)A->spptr;
155b0e5de86SRichard Tran Mills 
156b0e5de86SRichard Tran Mills   PetscFunctionBegin;
1579566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1589566063dSJacob Faibussowitsch   PetscCall(MatMult_SeqSELL(aijsell->S,xx,yy));
159b0e5de86SRichard Tran Mills   PetscFunctionReturn(0);
160b0e5de86SRichard Tran Mills }
161b0e5de86SRichard Tran Mills 
1624da9d7bdSRichard Tran Mills PetscErrorCode MatMultTranspose_SeqAIJSELL(Mat A,Vec xx,Vec yy)
1634da9d7bdSRichard Tran Mills {
1644da9d7bdSRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
1654da9d7bdSRichard Tran Mills 
1664da9d7bdSRichard Tran Mills   PetscFunctionBegin;
1679566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1689566063dSJacob Faibussowitsch   PetscCall(MatMultTranspose_SeqSELL(aijsell->S,xx,yy));
1694da9d7bdSRichard Tran Mills   PetscFunctionReturn(0);
1704da9d7bdSRichard Tran Mills }
1714da9d7bdSRichard Tran Mills 
1724da9d7bdSRichard Tran Mills PetscErrorCode MatMultAdd_SeqAIJSELL(Mat A,Vec xx,Vec yy,Vec zz)
1734da9d7bdSRichard Tran Mills {
1744da9d7bdSRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
1754da9d7bdSRichard Tran Mills 
1764da9d7bdSRichard Tran Mills   PetscFunctionBegin;
1779566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1789566063dSJacob Faibussowitsch   PetscCall(MatMultAdd_SeqSELL(aijsell->S,xx,yy,zz));
1794da9d7bdSRichard Tran Mills   PetscFunctionReturn(0);
1804da9d7bdSRichard Tran Mills }
1814da9d7bdSRichard Tran Mills 
1824da9d7bdSRichard Tran Mills PetscErrorCode MatMultTransposeAdd_SeqAIJSELL(Mat A,Vec xx,Vec yy,Vec zz)
1834da9d7bdSRichard Tran Mills {
1844da9d7bdSRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
1854da9d7bdSRichard Tran Mills 
1864da9d7bdSRichard Tran Mills   PetscFunctionBegin;
1879566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1889566063dSJacob Faibussowitsch   PetscCall(MatMultTransposeAdd_SeqSELL(aijsell->S,xx,yy,zz));
1894da9d7bdSRichard Tran Mills   PetscFunctionReturn(0);
1904da9d7bdSRichard Tran Mills }
1914da9d7bdSRichard Tran Mills 
192af22a668SRichard Tran Mills PetscErrorCode MatSOR_SeqAIJSELL(Mat A,Vec bb,PetscReal omega,MatSORType flag,PetscReal fshift,PetscInt its,PetscInt lits,Vec xx)
193af22a668SRichard Tran Mills {
194af22a668SRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
195af22a668SRichard Tran Mills 
196af22a668SRichard Tran Mills   PetscFunctionBegin;
1979566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1989566063dSJacob Faibussowitsch   PetscCall(MatSOR_SeqSELL(aijsell->S,bb,omega,flag,fshift,its,lits,xx));
199af22a668SRichard Tran Mills   PetscFunctionReturn(0);
200af22a668SRichard Tran Mills }
201af22a668SRichard Tran Mills 
2024dfdc2d9SRichard Tran Mills /* MatConvert_SeqAIJ_SeqAIJSELL converts a SeqAIJ matrix into a
2034dfdc2d9SRichard Tran Mills  * SeqAIJSELL matrix.  This routine is called by the MatCreate_SeqAIJSELL()
2044dfdc2d9SRichard Tran Mills  * routine, but can also be used to convert an assembled SeqAIJ matrix
2054dfdc2d9SRichard Tran Mills  * into a SeqAIJSELL one. */
2064dfdc2d9SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJSELL(Mat A,MatType type,MatReuse reuse,Mat *newmat)
2074dfdc2d9SRichard Tran Mills {
2084dfdc2d9SRichard Tran Mills   Mat            B = *newmat;
2094dfdc2d9SRichard Tran Mills   Mat_SeqAIJ     *b;
2104dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL *aijsell;
2114dfdc2d9SRichard Tran Mills   PetscBool      set;
2124dfdc2d9SRichard Tran Mills   PetscBool      sametype;
2134dfdc2d9SRichard Tran Mills 
2144dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
2154dfdc2d9SRichard Tran Mills   if (reuse == MAT_INITIAL_MATRIX) {
2169566063dSJacob Faibussowitsch     PetscCall(MatDuplicate(A,MAT_COPY_VALUES,&B));
2174dfdc2d9SRichard Tran Mills   }
2184dfdc2d9SRichard Tran Mills 
2199566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)A,type,&sametype));
2204dfdc2d9SRichard Tran Mills   if (sametype) PetscFunctionReturn(0);
2214dfdc2d9SRichard Tran Mills 
2229566063dSJacob Faibussowitsch   PetscCall(PetscNewLog(B,&aijsell));
2234dfdc2d9SRichard Tran Mills   b        = (Mat_SeqAIJ*) B->data;
2244dfdc2d9SRichard Tran Mills   B->spptr = (void*) aijsell;
2254dfdc2d9SRichard Tran Mills 
2264dfdc2d9SRichard Tran Mills   /* Disable use of the inode routines so that the AIJSELL ones will be used instead.
2274dfdc2d9SRichard Tran Mills    * This happens in MatAssemblyEnd_SeqAIJSELL as well, but the assembly end may not be called, so set it here, too.
2284dfdc2d9SRichard Tran Mills    * As noted elsewhere, I wonder if it might make sense and be feasible to use some of the inode routines. */
2294dfdc2d9SRichard Tran Mills   b->inode.use = PETSC_FALSE;
2304dfdc2d9SRichard Tran Mills 
2314dfdc2d9SRichard Tran Mills   /* Set function pointers for methods that we inherit from AIJ but override.
2324dfdc2d9SRichard Tran Mills    * We also parse some command line options below, since those determine some of the methods we point to. */
2334dfdc2d9SRichard Tran Mills   B->ops->duplicate        = MatDuplicate_SeqAIJSELL;
2344dfdc2d9SRichard Tran Mills   B->ops->assemblyend      = MatAssemblyEnd_SeqAIJSELL;
2354dfdc2d9SRichard Tran Mills   B->ops->destroy          = MatDestroy_SeqAIJSELL;
2364dfdc2d9SRichard Tran Mills 
2374dfdc2d9SRichard Tran Mills   aijsell->S = NULL;
2384dfdc2d9SRichard Tran Mills   aijsell->eager_shadow = PETSC_FALSE;
2394dfdc2d9SRichard Tran Mills 
2404dfdc2d9SRichard Tran Mills   /* Parse command line options. */
241d0609cedSBarry Smith   PetscOptionsBegin(PetscObjectComm((PetscObject)A),((PetscObject)A)->prefix,"AIJSELL Options","Mat");
2429566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBool("-mat_aijsell_eager_shadow","Eager Shadowing","None",(PetscBool)aijsell->eager_shadow,(PetscBool*)&aijsell->eager_shadow,&set));
243d0609cedSBarry Smith   PetscOptionsEnd();
2444dfdc2d9SRichard Tran Mills 
2454dfdc2d9SRichard Tran Mills   /* If A has already been assembled and eager shadowing is specified, build the shadow matrix. */
24663663694SRichard Tran Mills   if (A->assembled && aijsell->eager_shadow) {
2479566063dSJacob Faibussowitsch     PetscCall(MatSeqAIJSELL_build_shadow(A));
2484dfdc2d9SRichard Tran Mills   }
2494dfdc2d9SRichard Tran Mills 
250b0e5de86SRichard Tran Mills   B->ops->mult             = MatMult_SeqAIJSELL;
251b0e5de86SRichard Tran Mills   B->ops->multtranspose    = MatMultTranspose_SeqAIJSELL;
252b0e5de86SRichard Tran Mills   B->ops->multadd          = MatMultAdd_SeqAIJSELL;
253b0e5de86SRichard Tran Mills   B->ops->multtransposeadd = MatMultTransposeAdd_SeqAIJSELL;
254af22a668SRichard Tran Mills   B->ops->sor              = MatSOR_SeqAIJSELL;
2554dfdc2d9SRichard Tran Mills 
2569566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)B,"MatConvert_seqaijsell_seqaij_C",MatConvert_SeqAIJSELL_SeqAIJ));
2574dfdc2d9SRichard Tran Mills 
2589566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject)B,MATSEQAIJSELL));
2594dfdc2d9SRichard Tran Mills   *newmat = B;
2604dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
2614dfdc2d9SRichard Tran Mills }
2624dfdc2d9SRichard Tran Mills 
2634dfdc2d9SRichard Tran Mills /*@C
2644dfdc2d9SRichard Tran Mills    MatCreateSeqAIJSELL - Creates a sparse matrix of type SEQAIJSELL.
2654dfdc2d9SRichard Tran Mills    This type inherits from AIJ and is largely identical, but keeps a "shadow"
2668197ac24SRichard Tran Mills    copy of the matrix in SEQSELL format, which is used when this format
2678197ac24SRichard Tran Mills    may be more suitable for a requested operation. Currently, SEQSELL format
2688197ac24SRichard Tran Mills    is used for MatMult, MatMultTranspose, MatMultAdd, MatMultTransposeAdd,
2698197ac24SRichard Tran Mills    and MatSOR operations.
270ca9cdca7SRichard Tran Mills    Because SEQAIJSELL is a subtype of SEQAIJ, the option "-mat_seqaij_type seqaijsell" can be used to make
271ca9cdca7SRichard Tran Mills    sequential AIJ matrices default to being instances of MATSEQAIJSELL.
2724dfdc2d9SRichard Tran Mills 
273d083f849SBarry Smith    Collective
2744dfdc2d9SRichard Tran Mills 
2754dfdc2d9SRichard Tran Mills    Input Parameters:
2764dfdc2d9SRichard Tran Mills +  comm - MPI communicator, set to PETSC_COMM_SELF
2774dfdc2d9SRichard Tran Mills .  m - number of rows
2784dfdc2d9SRichard Tran Mills .  n - number of columns
2794dfdc2d9SRichard Tran Mills .  nz - number of nonzeros per row (same for all rows)
2804dfdc2d9SRichard Tran Mills -  nnz - array containing the number of nonzeros in the various rows
2814dfdc2d9SRichard Tran Mills          (possibly different for each row) or NULL
2824dfdc2d9SRichard Tran Mills 
2834dfdc2d9SRichard Tran Mills    Output Parameter:
2844dfdc2d9SRichard Tran Mills .  A - the matrix
2854dfdc2d9SRichard Tran Mills 
2864dfdc2d9SRichard Tran Mills    Options Database Keys:
2874dfdc2d9SRichard Tran Mills .  -mat_aijsell_eager_shadow - Construct shadow matrix upon matrix assembly; default is to take a "lazy" approach, performing this step the first time the matrix is applied
2884dfdc2d9SRichard Tran Mills 
2894dfdc2d9SRichard Tran Mills    Notes:
2904dfdc2d9SRichard Tran Mills    If nnz is given then nz is ignored
2914dfdc2d9SRichard Tran Mills 
2924dfdc2d9SRichard Tran Mills    Level: intermediate
2934dfdc2d9SRichard Tran Mills 
294db781477SPatrick Sanan .seealso: `MatCreate()`, `MatCreateMPIAIJSELL()`, `MatSetValues()`
2954dfdc2d9SRichard Tran Mills @*/
2964dfdc2d9SRichard Tran Mills PetscErrorCode  MatCreateSeqAIJSELL(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt nz,const PetscInt nnz[],Mat *A)
2974dfdc2d9SRichard Tran Mills {
2984dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
2999566063dSJacob Faibussowitsch   PetscCall(MatCreate(comm,A));
3009566063dSJacob Faibussowitsch   PetscCall(MatSetSizes(*A,m,n,m,n));
3019566063dSJacob Faibussowitsch   PetscCall(MatSetType(*A,MATSEQAIJSELL));
3029566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSetPreallocation_SeqAIJ(*A,nz,nnz));
3034dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
3044dfdc2d9SRichard Tran Mills }
3054dfdc2d9SRichard Tran Mills 
3064dfdc2d9SRichard Tran Mills PETSC_EXTERN PetscErrorCode MatCreate_SeqAIJSELL(Mat A)
3074dfdc2d9SRichard Tran Mills {
3084dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
3099566063dSJacob Faibussowitsch   PetscCall(MatSetType(A,MATSEQAIJ));
3109566063dSJacob Faibussowitsch   PetscCall(MatConvert_SeqAIJ_SeqAIJSELL(A,MATSEQAIJSELL,MAT_INPLACE_MATRIX,&A));
3114dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
3124dfdc2d9SRichard Tran Mills }
313