xref: /petsc/src/mat/impls/aij/seq/aijsell/aijsell.c (revision d0609ced746bc51b019815ca91d747429db24893)
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. */
759566063dSJacob Faibussowitsch   PetscCall(MatDestroy_SeqAIJ(A));
764dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
774dfdc2d9SRichard Tran Mills }
784dfdc2d9SRichard Tran Mills 
79a2a1850bSRichard Tran Mills /* Build or update the shadow matrix if and only if needed.
80a2a1850bSRichard Tran Mills  * We track the ObjectState to determine when this needs to be done. */
81b0e5de86SRichard Tran Mills PETSC_INTERN PetscErrorCode MatSeqAIJSELL_build_shadow(Mat A)
82b0e5de86SRichard Tran Mills {
83b0e5de86SRichard Tran Mills   Mat_SeqAIJSELL   *aijsell = (Mat_SeqAIJSELL*) A->spptr;
84a2a1850bSRichard Tran Mills   PetscObjectState state;
85b0e5de86SRichard Tran Mills 
86b0e5de86SRichard Tran Mills   PetscFunctionBegin;
879566063dSJacob Faibussowitsch   PetscCall(PetscObjectStateGet((PetscObject)A,&state));
88a2a1850bSRichard Tran Mills   if (aijsell->S && aijsell->state == state) {
89a2a1850bSRichard Tran Mills     /* The existing shadow matrix is up-to-date, so simply exit. */
90a2a1850bSRichard Tran Mills     PetscFunctionReturn(0);
91a2a1850bSRichard Tran Mills   }
92a2a1850bSRichard Tran Mills 
939566063dSJacob Faibussowitsch   PetscCall(PetscLogEventBegin(MAT_Convert,A,0,0,0));
94b0e5de86SRichard Tran Mills   if (aijsell->S) {
959566063dSJacob Faibussowitsch     PetscCall(MatConvert_SeqAIJ_SeqSELL(A,MATSEQSELL,MAT_REUSE_MATRIX,&aijsell->S));
96b0e5de86SRichard Tran Mills   } else {
979566063dSJacob Faibussowitsch     PetscCall(MatConvert_SeqAIJ_SeqSELL(A,MATSEQSELL,MAT_INITIAL_MATRIX,&aijsell->S));
98b0e5de86SRichard Tran Mills   }
999566063dSJacob Faibussowitsch   PetscCall(PetscLogEventEnd(MAT_Convert,A,0,0,0));
100b0e5de86SRichard Tran Mills 
101b0e5de86SRichard Tran Mills   /* Record the ObjectState so that we can tell when the shadow matrix needs updating */
1029566063dSJacob Faibussowitsch   PetscCall(PetscObjectStateGet((PetscObject)A,&aijsell->state));
103b0e5de86SRichard Tran Mills 
104b0e5de86SRichard Tran Mills   PetscFunctionReturn(0);
105b0e5de86SRichard Tran Mills }
106b0e5de86SRichard Tran Mills 
1074dfdc2d9SRichard Tran Mills PetscErrorCode MatDuplicate_SeqAIJSELL(Mat A, MatDuplicateOption op, Mat *M)
1084dfdc2d9SRichard Tran Mills {
1094dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL *aijsell;
1104dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL *aijsell_dest;
1114dfdc2d9SRichard Tran Mills 
1124dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
1139566063dSJacob Faibussowitsch   PetscCall(MatDuplicate_SeqAIJ(A,op,M));
1144dfdc2d9SRichard Tran Mills   aijsell      = (Mat_SeqAIJSELL*) A->spptr;
1154dfdc2d9SRichard Tran Mills   aijsell_dest = (Mat_SeqAIJSELL*) (*M)->spptr;
1169566063dSJacob Faibussowitsch   PetscCall(PetscArraycpy(aijsell_dest,aijsell,1));
1174dfdc2d9SRichard Tran Mills   /* We don't duplicate the shadow matrix -- that will be constructed as needed. */
1184dfdc2d9SRichard Tran Mills   aijsell_dest->S = NULL;
11963663694SRichard Tran Mills   if (aijsell->eager_shadow) {
1209566063dSJacob Faibussowitsch     PetscCall(MatSeqAIJSELL_build_shadow(A));
12163663694SRichard Tran Mills   }
1224dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
1234dfdc2d9SRichard Tran Mills }
1244dfdc2d9SRichard Tran Mills 
1254dfdc2d9SRichard Tran Mills PetscErrorCode MatAssemblyEnd_SeqAIJSELL(Mat A, MatAssemblyType mode)
1264dfdc2d9SRichard Tran Mills {
1274dfdc2d9SRichard Tran Mills   Mat_SeqAIJ      *a = (Mat_SeqAIJ*)A->data;
1288cde19baSRichard Tran Mills   Mat_SeqAIJSELL  *aijsell = (Mat_SeqAIJSELL*)A->spptr;
1294dfdc2d9SRichard Tran Mills 
1304dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
1314dfdc2d9SRichard Tran Mills   if (mode == MAT_FLUSH_ASSEMBLY) PetscFunctionReturn(0);
1324dfdc2d9SRichard Tran Mills 
1334dfdc2d9SRichard Tran Mills   /* I disable the use of the inode routines so that the AIJSELL ones will be
1344dfdc2d9SRichard Tran Mills    * used instead, but I wonder if it might make sense (and is feasible) to
1354dfdc2d9SRichard Tran Mills    * use some of them. */
1364dfdc2d9SRichard Tran Mills   a->inode.use = PETSC_FALSE;
1374dfdc2d9SRichard Tran Mills 
1384dfdc2d9SRichard Tran Mills   /* Since a MATSEQAIJSELL matrix is really just a MATSEQAIJ with some
1394dfdc2d9SRichard Tran Mills    * extra information and some different methods, call the AssemblyEnd
1404dfdc2d9SRichard Tran Mills    * routine for a MATSEQAIJ.
1414dfdc2d9SRichard Tran Mills    * I'm not sure if this is the best way to do this, but it avoids
1424dfdc2d9SRichard Tran Mills    * a lot of code duplication. */
1434dfdc2d9SRichard Tran Mills 
1449566063dSJacob Faibussowitsch   PetscCall(MatAssemblyEnd_SeqAIJ(A, mode));
1454dfdc2d9SRichard Tran Mills 
1464dfdc2d9SRichard Tran Mills   /* If the user has requested "eager" shadowing, create the SELL shadow matrix (if needed; the function checks).
1474dfdc2d9SRichard Tran Mills    * (The default is to take a "lazy" approach, deferring this until something like MatMult() is called.) */
1484dfdc2d9SRichard Tran Mills   if (aijsell->eager_shadow) {
1499566063dSJacob Faibussowitsch     PetscCall(MatSeqAIJSELL_build_shadow(A));
1504dfdc2d9SRichard Tran Mills   }
1514dfdc2d9SRichard Tran Mills 
1524dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
1534dfdc2d9SRichard Tran Mills }
1544dfdc2d9SRichard Tran Mills 
155b0e5de86SRichard Tran Mills PetscErrorCode MatMult_SeqAIJSELL(Mat A,Vec xx,Vec yy)
156b0e5de86SRichard Tran Mills {
157b0e5de86SRichard Tran Mills   Mat_SeqAIJSELL    *aijsell = (Mat_SeqAIJSELL*)A->spptr;
158b0e5de86SRichard Tran Mills 
159b0e5de86SRichard Tran Mills   PetscFunctionBegin;
1609566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1619566063dSJacob Faibussowitsch   PetscCall(MatMult_SeqSELL(aijsell->S,xx,yy));
162b0e5de86SRichard Tran Mills   PetscFunctionReturn(0);
163b0e5de86SRichard Tran Mills }
164b0e5de86SRichard Tran Mills 
1654da9d7bdSRichard Tran Mills PetscErrorCode MatMultTranspose_SeqAIJSELL(Mat A,Vec xx,Vec yy)
1664da9d7bdSRichard Tran Mills {
1674da9d7bdSRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
1684da9d7bdSRichard Tran Mills 
1694da9d7bdSRichard Tran Mills   PetscFunctionBegin;
1709566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1719566063dSJacob Faibussowitsch   PetscCall(MatMultTranspose_SeqSELL(aijsell->S,xx,yy));
1724da9d7bdSRichard Tran Mills   PetscFunctionReturn(0);
1734da9d7bdSRichard Tran Mills }
1744da9d7bdSRichard Tran Mills 
1754da9d7bdSRichard Tran Mills PetscErrorCode MatMultAdd_SeqAIJSELL(Mat A,Vec xx,Vec yy,Vec zz)
1764da9d7bdSRichard Tran Mills {
1774da9d7bdSRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
1784da9d7bdSRichard Tran Mills 
1794da9d7bdSRichard Tran Mills   PetscFunctionBegin;
1809566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1819566063dSJacob Faibussowitsch   PetscCall(MatMultAdd_SeqSELL(aijsell->S,xx,yy,zz));
1824da9d7bdSRichard Tran Mills   PetscFunctionReturn(0);
1834da9d7bdSRichard Tran Mills }
1844da9d7bdSRichard Tran Mills 
1854da9d7bdSRichard Tran Mills PetscErrorCode MatMultTransposeAdd_SeqAIJSELL(Mat A,Vec xx,Vec yy,Vec zz)
1864da9d7bdSRichard Tran Mills {
1874da9d7bdSRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
1884da9d7bdSRichard Tran Mills 
1894da9d7bdSRichard Tran Mills   PetscFunctionBegin;
1909566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
1919566063dSJacob Faibussowitsch   PetscCall(MatMultTransposeAdd_SeqSELL(aijsell->S,xx,yy,zz));
1924da9d7bdSRichard Tran Mills   PetscFunctionReturn(0);
1934da9d7bdSRichard Tran Mills }
1944da9d7bdSRichard Tran Mills 
195af22a668SRichard Tran Mills PetscErrorCode MatSOR_SeqAIJSELL(Mat A,Vec bb,PetscReal omega,MatSORType flag,PetscReal fshift,PetscInt its,PetscInt lits,Vec xx)
196af22a668SRichard Tran Mills {
197af22a668SRichard Tran Mills   Mat_SeqAIJSELL    *aijsell=(Mat_SeqAIJSELL*)A->spptr;
198af22a668SRichard Tran Mills 
199af22a668SRichard Tran Mills   PetscFunctionBegin;
2009566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSELL_build_shadow(A));
2019566063dSJacob Faibussowitsch   PetscCall(MatSOR_SeqSELL(aijsell->S,bb,omega,flag,fshift,its,lits,xx));
202af22a668SRichard Tran Mills   PetscFunctionReturn(0);
203af22a668SRichard Tran Mills }
204af22a668SRichard Tran Mills 
2054dfdc2d9SRichard Tran Mills /* MatConvert_SeqAIJ_SeqAIJSELL converts a SeqAIJ matrix into a
2064dfdc2d9SRichard Tran Mills  * SeqAIJSELL matrix.  This routine is called by the MatCreate_SeqAIJSELL()
2074dfdc2d9SRichard Tran Mills  * routine, but can also be used to convert an assembled SeqAIJ matrix
2084dfdc2d9SRichard Tran Mills  * into a SeqAIJSELL one. */
2094dfdc2d9SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJSELL(Mat A,MatType type,MatReuse reuse,Mat *newmat)
2104dfdc2d9SRichard Tran Mills {
2114dfdc2d9SRichard Tran Mills   Mat            B = *newmat;
2124dfdc2d9SRichard Tran Mills   Mat_SeqAIJ     *b;
2134dfdc2d9SRichard Tran Mills   Mat_SeqAIJSELL *aijsell;
2144dfdc2d9SRichard Tran Mills   PetscBool      set;
2154dfdc2d9SRichard Tran Mills   PetscBool      sametype;
2164dfdc2d9SRichard Tran Mills 
2174dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
2184dfdc2d9SRichard Tran Mills   if (reuse == MAT_INITIAL_MATRIX) {
2199566063dSJacob Faibussowitsch     PetscCall(MatDuplicate(A,MAT_COPY_VALUES,&B));
2204dfdc2d9SRichard Tran Mills   }
2214dfdc2d9SRichard Tran Mills 
2229566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)A,type,&sametype));
2234dfdc2d9SRichard Tran Mills   if (sametype) PetscFunctionReturn(0);
2244dfdc2d9SRichard Tran Mills 
2259566063dSJacob Faibussowitsch   PetscCall(PetscNewLog(B,&aijsell));
2264dfdc2d9SRichard Tran Mills   b        = (Mat_SeqAIJ*) B->data;
2274dfdc2d9SRichard Tran Mills   B->spptr = (void*) aijsell;
2284dfdc2d9SRichard Tran Mills 
2294dfdc2d9SRichard Tran Mills   /* Disable use of the inode routines so that the AIJSELL ones will be used instead.
2304dfdc2d9SRichard Tran Mills    * This happens in MatAssemblyEnd_SeqAIJSELL as well, but the assembly end may not be called, so set it here, too.
2314dfdc2d9SRichard Tran Mills    * As noted elsewhere, I wonder if it might make sense and be feasible to use some of the inode routines. */
2324dfdc2d9SRichard Tran Mills   b->inode.use = PETSC_FALSE;
2334dfdc2d9SRichard Tran Mills 
2344dfdc2d9SRichard Tran Mills   /* Set function pointers for methods that we inherit from AIJ but override.
2354dfdc2d9SRichard Tran Mills    * We also parse some command line options below, since those determine some of the methods we point to. */
2364dfdc2d9SRichard Tran Mills   B->ops->duplicate        = MatDuplicate_SeqAIJSELL;
2374dfdc2d9SRichard Tran Mills   B->ops->assemblyend      = MatAssemblyEnd_SeqAIJSELL;
2384dfdc2d9SRichard Tran Mills   B->ops->destroy          = MatDestroy_SeqAIJSELL;
2394dfdc2d9SRichard Tran Mills 
2404dfdc2d9SRichard Tran Mills   aijsell->S = NULL;
2414dfdc2d9SRichard Tran Mills   aijsell->eager_shadow = PETSC_FALSE;
2424dfdc2d9SRichard Tran Mills 
2434dfdc2d9SRichard Tran Mills   /* Parse command line options. */
244*d0609cedSBarry Smith   PetscOptionsBegin(PetscObjectComm((PetscObject)A),((PetscObject)A)->prefix,"AIJSELL Options","Mat");
2459566063dSJacob Faibussowitsch   PetscCall(PetscOptionsBool("-mat_aijsell_eager_shadow","Eager Shadowing","None",(PetscBool)aijsell->eager_shadow,(PetscBool*)&aijsell->eager_shadow,&set));
246*d0609cedSBarry Smith   PetscOptionsEnd();
2474dfdc2d9SRichard Tran Mills 
2484dfdc2d9SRichard Tran Mills   /* If A has already been assembled and eager shadowing is specified, build the shadow matrix. */
24963663694SRichard Tran Mills   if (A->assembled && aijsell->eager_shadow) {
2509566063dSJacob Faibussowitsch     PetscCall(MatSeqAIJSELL_build_shadow(A));
2514dfdc2d9SRichard Tran Mills   }
2524dfdc2d9SRichard Tran Mills 
253b0e5de86SRichard Tran Mills   B->ops->mult             = MatMult_SeqAIJSELL;
254b0e5de86SRichard Tran Mills   B->ops->multtranspose    = MatMultTranspose_SeqAIJSELL;
255b0e5de86SRichard Tran Mills   B->ops->multadd          = MatMultAdd_SeqAIJSELL;
256b0e5de86SRichard Tran Mills   B->ops->multtransposeadd = MatMultTransposeAdd_SeqAIJSELL;
257af22a668SRichard Tran Mills   B->ops->sor              = MatSOR_SeqAIJSELL;
2584dfdc2d9SRichard Tran Mills 
2599566063dSJacob Faibussowitsch   PetscCall(PetscObjectComposeFunction((PetscObject)B,"MatConvert_seqaijsell_seqaij_C",MatConvert_SeqAIJSELL_SeqAIJ));
2604dfdc2d9SRichard Tran Mills 
2619566063dSJacob Faibussowitsch   PetscCall(PetscObjectChangeTypeName((PetscObject)B,MATSEQAIJSELL));
2624dfdc2d9SRichard Tran Mills   *newmat = B;
2634dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
2644dfdc2d9SRichard Tran Mills }
2654dfdc2d9SRichard Tran Mills 
2664dfdc2d9SRichard Tran Mills /*@C
2674dfdc2d9SRichard Tran Mills    MatCreateSeqAIJSELL - Creates a sparse matrix of type SEQAIJSELL.
2684dfdc2d9SRichard Tran Mills    This type inherits from AIJ and is largely identical, but keeps a "shadow"
2698197ac24SRichard Tran Mills    copy of the matrix in SEQSELL format, which is used when this format
2708197ac24SRichard Tran Mills    may be more suitable for a requested operation. Currently, SEQSELL format
2718197ac24SRichard Tran Mills    is used for MatMult, MatMultTranspose, MatMultAdd, MatMultTransposeAdd,
2728197ac24SRichard Tran Mills    and MatSOR operations.
273ca9cdca7SRichard Tran Mills    Because SEQAIJSELL is a subtype of SEQAIJ, the option "-mat_seqaij_type seqaijsell" can be used to make
274ca9cdca7SRichard Tran Mills    sequential AIJ matrices default to being instances of MATSEQAIJSELL.
2754dfdc2d9SRichard Tran Mills 
276d083f849SBarry Smith    Collective
2774dfdc2d9SRichard Tran Mills 
2784dfdc2d9SRichard Tran Mills    Input Parameters:
2794dfdc2d9SRichard Tran Mills +  comm - MPI communicator, set to PETSC_COMM_SELF
2804dfdc2d9SRichard Tran Mills .  m - number of rows
2814dfdc2d9SRichard Tran Mills .  n - number of columns
2824dfdc2d9SRichard Tran Mills .  nz - number of nonzeros per row (same for all rows)
2834dfdc2d9SRichard Tran Mills -  nnz - array containing the number of nonzeros in the various rows
2844dfdc2d9SRichard Tran Mills          (possibly different for each row) or NULL
2854dfdc2d9SRichard Tran Mills 
2864dfdc2d9SRichard Tran Mills    Output Parameter:
2874dfdc2d9SRichard Tran Mills .  A - the matrix
2884dfdc2d9SRichard Tran Mills 
2894dfdc2d9SRichard Tran Mills    Options Database Keys:
2904dfdc2d9SRichard 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
2914dfdc2d9SRichard Tran Mills 
2924dfdc2d9SRichard Tran Mills    Notes:
2934dfdc2d9SRichard Tran Mills    If nnz is given then nz is ignored
2944dfdc2d9SRichard Tran Mills 
2954dfdc2d9SRichard Tran Mills    Level: intermediate
2964dfdc2d9SRichard Tran Mills 
2974dfdc2d9SRichard Tran Mills .seealso: MatCreate(), MatCreateMPIAIJSELL(), MatSetValues()
2984dfdc2d9SRichard Tran Mills @*/
2994dfdc2d9SRichard Tran Mills PetscErrorCode  MatCreateSeqAIJSELL(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt nz,const PetscInt nnz[],Mat *A)
3004dfdc2d9SRichard Tran Mills {
3014dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
3029566063dSJacob Faibussowitsch   PetscCall(MatCreate(comm,A));
3039566063dSJacob Faibussowitsch   PetscCall(MatSetSizes(*A,m,n,m,n));
3049566063dSJacob Faibussowitsch   PetscCall(MatSetType(*A,MATSEQAIJSELL));
3059566063dSJacob Faibussowitsch   PetscCall(MatSeqAIJSetPreallocation_SeqAIJ(*A,nz,nnz));
3064dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
3074dfdc2d9SRichard Tran Mills }
3084dfdc2d9SRichard Tran Mills 
3094dfdc2d9SRichard Tran Mills PETSC_EXTERN PetscErrorCode MatCreate_SeqAIJSELL(Mat A)
3104dfdc2d9SRichard Tran Mills {
3114dfdc2d9SRichard Tran Mills   PetscFunctionBegin;
3129566063dSJacob Faibussowitsch   PetscCall(MatSetType(A,MATSEQAIJ));
3139566063dSJacob Faibussowitsch   PetscCall(MatConvert_SeqAIJ_SeqAIJSELL(A,MATSEQAIJSELL,MAT_INPLACE_MATRIX,&A));
3144dfdc2d9SRichard Tran Mills   PetscFunctionReturn(0);
3154dfdc2d9SRichard Tran Mills }
316