xref: /petsc/src/mat/impls/aij/seq/aij.h (revision 09573ac72a50d3e7ecd55a2b7f0ef28450cd0a8b)
1b8a66259SBarry Smith 
22d40f771SBarry Smith #if !defined(__AIJ_H)
32d40f771SBarry Smith #define __AIJ_H
4e6b907acSBarry Smith 
57c4f633dSBarry Smith #include "private/matimpl.h"
68f690400SShri Abhyankar 
7e6b907acSBarry Smith /*
8e6b907acSBarry Smith     Struct header shared by SeqAIJ, SeqBAIJ and SeqSBAIJ matrix formats
9e6b907acSBarry Smith */
10421e10b8SBarry Smith #define SEQAIJHEADER(datatype)	\
11ace3abfcSBarry Smith   PetscBool         roworiented;      /* if true, row-oriented input, default */\
12e6b907acSBarry Smith   PetscInt          nonew;            /* 1 don't add new nonzeros, -1 generate error on new */\
1328b2fa4aSMatthew Knepley   PetscInt          nounused;         /* -1 generate error on unused space */\
14ace3abfcSBarry Smith   PetscBool         singlemalloc;     /* if true a, i, and j have been obtained with one big malloc */\
15e6b907acSBarry Smith   PetscInt          maxnz;            /* allocated nonzeros */\
16e6b907acSBarry Smith   PetscInt          *imax;            /* maximum space allocated for each row */\
17e6b907acSBarry Smith   PetscInt          *ilen;            /* actual length of each row */\
18ace3abfcSBarry Smith   PetscBool         free_imax_ilen;  \
19e6b907acSBarry Smith   PetscInt          reallocs;         /* number of mallocs done during MatSetValues() \
20e6b907acSBarry Smith                                         as more values are set than were prealloced */\
21e6b907acSBarry Smith   PetscInt          rmax;             /* max nonzeros in any row */\
22ace3abfcSBarry Smith   PetscBool         keepnonzeropattern;   /* keeps matrix structure same in calls to MatZeroRows()*/\
23ace3abfcSBarry Smith   PetscBool         ignorezeroentries; \
24e6b907acSBarry Smith   PetscInt          *xtoy,*xtoyB;     /* map nonzero pattern of X into Y's, used by MatAXPY() */\
25e6b907acSBarry Smith   Mat               XtoY;             /* used by MatAXPY() */\
26ace3abfcSBarry Smith   PetscBool         free_ij;          /* free the column indices j and row offsets i when the matrix is destroyed */ \
27ace3abfcSBarry Smith   PetscBool         free_a;           /* free the numerical values when matrix is destroy */ \
28e6b907acSBarry Smith   Mat_CompressedRow compressedrow;    /* use compressed row format */                      \
29e6b907acSBarry Smith   PetscInt          nz;               /* nonzeros */                                       \
30e6b907acSBarry Smith   PetscInt          *i;               /* pointer to beginning of each row */               \
31e6b907acSBarry Smith   PetscInt          *j;               /* column values: j + i[k] - 1 is start of row k */  \
32e6b907acSBarry Smith   PetscInt          *diag;            /* pointers to diagonal elements */                  \
33ace3abfcSBarry Smith   PetscBool         free_diag;         \
34421e10b8SBarry Smith   datatype          *a;               /* nonzero elements */                               \
35e6b907acSBarry Smith   PetscScalar       *solve_work;      /* work space used in MatSolve */                    \
364fd072dbSBarry Smith   IS                row, col, icol;   /* index sets, used for reorderings */ \
37ace3abfcSBarry Smith   PetscBool         pivotinblocks;    /* pivot inside factorization of each diagonal block */ \
384fd072dbSBarry Smith   Mat               parent             /* set if this matrix was formed with MatDuplicate(...,MAT_SHARE_NONZERO_PATTERN,....);
394fd072dbSBarry Smith                                          means that this shares some data structures with the parent including diag, ilen, imax, i, j */
40e6b907acSBarry Smith 
412d40f771SBarry Smith /*
42ec8511deSBarry Smith   MATSEQAIJ format - Compressed row storage (also called Yale sparse matrix
43e6b907acSBarry Smith   format) or compressed sparse row (CSR).  The i[] and j[] arrays start at 0. For example,
44dfbc5765Svictorle   j[i[k]+p] is the pth column in row k.  Note that the diagonal
455768c4f9SLois Curfman McInnes   matrix elements are stored with the rest of the nonzeros (not separately).
462d40f771SBarry Smith */
47d35516d3SLois Curfman McInnes 
48e6b907acSBarry Smith /* Info about i-nodes (identical nodes) helper class for SeqAIJ */
49b8a66259SBarry Smith typedef struct {
504108e4d5SBarry Smith   MatScalar   *bdiag,*ibdiag,*ssor_work;      /* diagonal blocks of matrix used for MatSOR_SeqAIJ_Inode() */
51f0d39aaaSBarry Smith   PetscInt    bdiagsize;                       /* length of bdiag and ibdiag */
52ace3abfcSBarry Smith   PetscBool   ibdiagvalid;                     /* do ibdiag[] and bdiag[] contain the most recent values */
53f0d39aaaSBarry Smith 
54ace3abfcSBarry Smith   PetscBool  use;
55e6b907acSBarry Smith   PetscInt   node_count;                    /* number of inodes */
56e6b907acSBarry Smith   PetscInt   *size;                         /* size of each inode */
57e6b907acSBarry Smith   PetscInt   limit;                         /* inode limit */
58e6b907acSBarry Smith   PetscInt   max_limit;                     /* maximum supported inode limit */
59ace3abfcSBarry Smith   PetscBool  checked;                       /* if inodes have been checked for */
604108e4d5SBarry Smith } Mat_SeqAIJ_Inode;
61e6b907acSBarry Smith 
62*09573ac7SBarry Smith extern PetscErrorCode MatView_SeqAIJ_Inode(Mat,PetscViewer);
63*09573ac7SBarry Smith extern PetscErrorCode MatAssemblyEnd_SeqAIJ_Inode(Mat,MatAssemblyType);
64*09573ac7SBarry Smith extern PetscErrorCode MatDestroy_SeqAIJ_Inode(Mat);
65*09573ac7SBarry Smith extern PetscErrorCode MatCreate_SeqAIJ_Inode(Mat);
66*09573ac7SBarry Smith extern PetscErrorCode MatSetOption_SeqAIJ_Inode(Mat,MatOption,PetscBool );
67*09573ac7SBarry Smith extern PetscErrorCode MatDuplicate_SeqAIJ_Inode(Mat,MatDuplicateOption,Mat*);
68*09573ac7SBarry Smith extern PetscErrorCode MatDuplicateNoCreate_SeqAIJ(Mat,Mat,MatDuplicateOption,PetscBool );
69*09573ac7SBarry Smith extern PetscErrorCode MatLUFactorNumeric_SeqAIJ_Inode_inplace(Mat,Mat,const MatFactorInfo*);
70*09573ac7SBarry Smith extern PetscErrorCode MatLUFactorNumeric_SeqAIJ_Inode(Mat,Mat,const MatFactorInfo*);
71e6b907acSBarry Smith 
72e6b907acSBarry Smith typedef struct {
7354f21887SBarry Smith   SEQAIJHEADER(MatScalar);
744108e4d5SBarry Smith   Mat_SeqAIJ_Inode inode;
7554f21887SBarry Smith   MatScalar        *saved_values;             /* location for stashing nonzero values of matrix */
7671f1c65dSBarry Smith 
7771f1c65dSBarry Smith   PetscScalar      *idiag,*mdiag,*ssor_work;  /* inverse of diagonal entries, diagonal values and workspace for Eisenstat trick */
78ace3abfcSBarry Smith   PetscBool        idiagvalid;                     /* current idiag[] and mdiag[] are valid */
7971f1c65dSBarry Smith   PetscScalar      fshift,omega;                   /* last used omega and fshift */
8071f1c65dSBarry Smith 
813a7fca6bSBarry Smith   ISColoring       coloring;                  /* set with MatADSetColoring() used by MatADSetValues() */
82ec8511deSBarry Smith } Mat_SeqAIJ;
83b8a66259SBarry Smith 
84e6b907acSBarry Smith /*
85e6b907acSBarry Smith   Frees the a, i, and j arrays from the XAIJ (AIJ, BAIJ, and SBAIJ) matrix types
86e6b907acSBarry Smith */
87e6b907acSBarry Smith #undef __FUNCT__
88e6b907acSBarry Smith #define __FUNCT__ "MatSeqXAIJFreeAIJ"
89d0f46423SBarry Smith PETSC_STATIC_INLINE PetscErrorCode MatSeqXAIJFreeAIJ(Mat AA,MatScalar **a,PetscInt **j,PetscInt **i)
90d0f46423SBarry Smith {
91e6b907acSBarry Smith                                      PetscErrorCode ierr;
92e6b907acSBarry Smith                                      Mat_SeqAIJ     *A = (Mat_SeqAIJ*) AA->data;
93e6b907acSBarry Smith                                      if (A->singlemalloc) {
94e6b907acSBarry Smith                                        ierr = PetscFree3(*a,*j,*i);CHKERRQ(ierr);
95e6b907acSBarry Smith                                      } else {
96e6b907acSBarry Smith                                        if (A->free_a  && *a) {ierr = PetscFree(*a);CHKERRQ(ierr);}
97e6b907acSBarry Smith                                        if (A->free_ij && *j) {ierr = PetscFree(*j);CHKERRQ(ierr);}
98e6b907acSBarry Smith                                        if (A->free_ij && *i) {ierr = PetscFree(*i);CHKERRQ(ierr);}
99e6b907acSBarry Smith                                      }
100e6b907acSBarry Smith                                      *a = 0; *j = 0; *i = 0;
101e6b907acSBarry Smith                                      return 0;
102e6b907acSBarry Smith                                    }
103e6b907acSBarry Smith /*
104e6b907acSBarry Smith     Allocates larger a, i, and j arrays for the XAIJ (AIJ, BAIJ, and SBAIJ) matrix types
105357fed3dSBarry Smith     This is a macro because it takes the datatype as an argument which can be either a Mat or a MatScalar
106e6b907acSBarry Smith */
107fef13f97SBarry Smith #define MatSeqXAIJReallocateAIJ(Amat,AM,BS2,NROW,ROW,COL,RMAX,AA,AI,AJ,RP,AP,AIMAX,NONEW,datatype) \
108fef13f97SBarry Smith   if (NROW >= RMAX) {\
109fef13f97SBarry Smith 	Mat_SeqAIJ *Ain = (Mat_SeqAIJ*)Amat->data;\
110fef13f97SBarry Smith         /* there is no extra room in row, therefore enlarge */ \
111fef13f97SBarry Smith         PetscInt   CHUNKSIZE = 15,new_nz = AI[AM] + CHUNKSIZE,len,*new_i=0,*new_j=0; \
112fef13f97SBarry Smith         datatype   *new_a; \
113fef13f97SBarry Smith  \
114fef13f97SBarry Smith         if (NONEW == -2) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"New nonzero at (%D,%D) caused a malloc",ROW,COL); \
115fef13f97SBarry Smith         /* malloc new storage space */ \
116fef13f97SBarry Smith         ierr = PetscMalloc3(BS2*new_nz,datatype,&new_a,new_nz,PetscInt,&new_j,AM+1,PetscInt,&new_i);CHKERRQ(ierr);\
117fef13f97SBarry Smith  \
118fef13f97SBarry Smith         /* copy over old data into new slots */ \
119fef13f97SBarry Smith         for (ii=0; ii<ROW+1; ii++) {new_i[ii] = AI[ii];} \
120fef13f97SBarry Smith         for (ii=ROW+1; ii<AM+1; ii++) {new_i[ii] = AI[ii]+CHUNKSIZE;} \
121fef13f97SBarry Smith         ierr = PetscMemcpy(new_j,AJ,(AI[ROW]+NROW)*sizeof(PetscInt));CHKERRQ(ierr); \
122fef13f97SBarry Smith         len = (new_nz - CHUNKSIZE - AI[ROW] - NROW); \
123fef13f97SBarry Smith         ierr = PetscMemcpy(new_j+AI[ROW]+NROW+CHUNKSIZE,AJ+AI[ROW]+NROW,len*sizeof(PetscInt));CHKERRQ(ierr); \
124fef13f97SBarry Smith         ierr = PetscMemcpy(new_a,AA,BS2*(AI[ROW]+NROW)*sizeof(datatype));CHKERRQ(ierr); \
125fef13f97SBarry Smith         ierr = PetscMemzero(new_a+BS2*(AI[ROW]+NROW),BS2*CHUNKSIZE*sizeof(datatype));CHKERRQ(ierr);\
126fef13f97SBarry Smith         ierr = PetscMemcpy(new_a+BS2*(AI[ROW]+NROW+CHUNKSIZE),AA+BS2*(AI[ROW]+NROW),BS2*len*sizeof(datatype));CHKERRQ(ierr);  \
127fef13f97SBarry Smith         /* free up old matrix storage */ \
128fef13f97SBarry Smith         ierr = MatSeqXAIJFreeAIJ(A,&Ain->a,&Ain->j,&Ain->i);CHKERRQ(ierr);\
129fef13f97SBarry Smith         AA = new_a; \
130fef13f97SBarry Smith         Ain->a = (MatScalar*) new_a;		   \
131fef13f97SBarry Smith         AI = Ain->i = new_i; AJ = Ain->j = new_j;  \
132fef13f97SBarry Smith         Ain->singlemalloc = PETSC_TRUE; \
133fef13f97SBarry Smith  \
134fef13f97SBarry Smith         RP          = AJ + AI[ROW]; AP = AA + BS2*AI[ROW]; \
135fef13f97SBarry Smith         RMAX        = AIMAX[ROW] = AIMAX[ROW] + CHUNKSIZE; \
136fef13f97SBarry Smith         Ain->maxnz += BS2*CHUNKSIZE; \
137fef13f97SBarry Smith         Ain->reallocs++; \
138fef13f97SBarry Smith       } \
13917454e89SShri Abhyankar 
140e6b907acSBarry Smith 
141f349cc81SSatish Balay EXTERN_C_BEGIN
142*09573ac7SBarry Smith extern PetscErrorCode MatSeqAIJSetPreallocation_SeqAIJ(Mat,PetscInt,const PetscInt*);
143f349cc81SSatish Balay EXTERN_C_END
144*09573ac7SBarry Smith extern PetscErrorCode MatILUFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,IS,const MatFactorInfo*);
145*09573ac7SBarry Smith extern PetscErrorCode MatILUFactorSymbolic_SeqAIJ(Mat,Mat,IS,IS,const MatFactorInfo*);
146*09573ac7SBarry Smith extern PetscErrorCode MatILUFactorSymbolic_SeqAIJ_ilu0(Mat,Mat,IS,IS,const MatFactorInfo*);
1471df811f5SHong Zhang 
148*09573ac7SBarry Smith extern PetscErrorCode MatICCFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,const MatFactorInfo*);
149*09573ac7SBarry Smith extern PetscErrorCode MatICCFactorSymbolic_SeqAIJ(Mat,Mat,IS,const MatFactorInfo*);
150*09573ac7SBarry Smith extern PetscErrorCode MatCholeskyFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,const MatFactorInfo*);
151*09573ac7SBarry Smith extern PetscErrorCode MatCholeskyFactorSymbolic_SeqAIJ(Mat,Mat,IS,const MatFactorInfo*);
152*09573ac7SBarry Smith extern PetscErrorCode MatCholeskyFactorNumeric_SeqAIJ_inplace(Mat,Mat,const MatFactorInfo*);
153*09573ac7SBarry Smith extern PetscErrorCode MatCholeskyFactorNumeric_SeqAIJ(Mat,Mat,const MatFactorInfo*);
154*09573ac7SBarry Smith extern PetscErrorCode MatDuplicate_SeqAIJ(Mat,MatDuplicateOption,Mat*);
155*09573ac7SBarry Smith extern PetscErrorCode MatCopy_SeqAIJ(Mat,Mat,MatStructure);
156*09573ac7SBarry Smith extern PetscErrorCode MatMissingDiagonal_SeqAIJ(Mat,PetscBool *,PetscInt*);
157*09573ac7SBarry Smith extern PetscErrorCode MatMarkDiagonal_SeqAIJ(Mat);
15808480c60SBarry Smith 
159*09573ac7SBarry Smith extern PetscErrorCode MatMult_SeqAIJ(Mat A,Vec,Vec);
160*09573ac7SBarry Smith extern PetscErrorCode MatMultAdd_SeqAIJ(Mat A,Vec,Vec,Vec);
161*09573ac7SBarry Smith extern PetscErrorCode MatMultTranspose_SeqAIJ(Mat A,Vec,Vec);
162*09573ac7SBarry Smith extern PetscErrorCode MatMultTransposeAdd_SeqAIJ(Mat A,Vec,Vec,Vec);
163*09573ac7SBarry Smith extern PetscErrorCode MatSOR_SeqAIJ(Mat,Vec,PetscReal,MatSORType,PetscReal,PetscInt,PetscInt,Vec);
16408480c60SBarry Smith 
165*09573ac7SBarry Smith extern PetscErrorCode MatSetColoring_SeqAIJ(Mat,ISColoring);
166*09573ac7SBarry Smith extern PetscErrorCode MatSetValuesAdic_SeqAIJ(Mat,void*);
167*09573ac7SBarry Smith extern PetscErrorCode MatSetValuesAdifor_SeqAIJ(Mat,PetscInt,void*);
1683a7fca6bSBarry Smith 
169*09573ac7SBarry Smith extern PetscErrorCode MatGetSymbolicTranspose_SeqAIJ(Mat,PetscInt *[],PetscInt *[]);
170*09573ac7SBarry Smith extern PetscErrorCode MatGetSymbolicTransposeReduced_SeqAIJ(Mat,PetscInt,PetscInt,PetscInt *[],PetscInt *[]);
171*09573ac7SBarry Smith extern PetscErrorCode MatRestoreSymbolicTranspose_SeqAIJ(Mat,PetscInt *[],PetscInt *[]);
172*09573ac7SBarry Smith extern PetscErrorCode MatToSymmetricIJ_SeqAIJ(PetscInt,PetscInt*,PetscInt*,PetscInt,PetscInt,PetscInt**,PetscInt**);
173*09573ac7SBarry Smith extern PetscErrorCode MatLUFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,IS,const MatFactorInfo*);
174*09573ac7SBarry Smith extern PetscErrorCode MatLUFactorSymbolic_SeqAIJ(Mat,Mat,IS,IS,const MatFactorInfo*);
175*09573ac7SBarry Smith extern PetscErrorCode MatLUFactorNumeric_SeqAIJ_inplace(Mat,Mat,const MatFactorInfo*);
176*09573ac7SBarry Smith extern PetscErrorCode MatLUFactorNumeric_SeqAIJ(Mat,Mat,const MatFactorInfo*);
177*09573ac7SBarry Smith extern PetscErrorCode MatLUFactorNumeric_SeqAIJ_InplaceWithPerm(Mat,Mat,const MatFactorInfo*);
178*09573ac7SBarry Smith extern PetscErrorCode MatLUFactor_SeqAIJ(Mat,IS,IS,const MatFactorInfo*);
179*09573ac7SBarry Smith extern PetscErrorCode MatSolve_SeqAIJ_inplace(Mat,Vec,Vec);
180*09573ac7SBarry Smith extern PetscErrorCode MatSolve_SeqAIJ(Mat,Vec,Vec);
181*09573ac7SBarry Smith extern PetscErrorCode MatSolve_SeqAIJ_Inode_inplace(Mat,Vec,Vec);
182*09573ac7SBarry Smith extern PetscErrorCode MatSolve_SeqAIJ_Inode(Mat,Vec,Vec);
183*09573ac7SBarry Smith extern PetscErrorCode MatSolve_SeqAIJ_NaturalOrdering_inplace(Mat,Vec,Vec);
184*09573ac7SBarry Smith extern PetscErrorCode MatSolve_SeqAIJ_NaturalOrdering(Mat,Vec,Vec);
185*09573ac7SBarry Smith extern PetscErrorCode MatSolve_SeqAIJ_InplaceWithPerm(Mat,Vec,Vec);
186*09573ac7SBarry Smith extern PetscErrorCode MatSolveAdd_SeqAIJ_inplace(Mat,Vec,Vec,Vec);
187*09573ac7SBarry Smith extern PetscErrorCode MatSolveAdd_SeqAIJ(Mat,Vec,Vec,Vec);
188*09573ac7SBarry Smith extern PetscErrorCode MatSolveTranspose_SeqAIJ_inplace(Mat,Vec,Vec);
189*09573ac7SBarry Smith extern PetscErrorCode MatSolveTranspose_SeqAIJ(Mat,Vec,Vec);
190*09573ac7SBarry Smith extern PetscErrorCode MatSolveTransposeAdd_SeqAIJ_inplace(Mat,Vec,Vec,Vec);
191*09573ac7SBarry Smith extern PetscErrorCode MatSolveTransposeAdd_SeqAIJ(Mat,Vec,Vec,Vec);
192*09573ac7SBarry Smith extern PetscErrorCode MatMatSolve_SeqAIJ_inplace(Mat,Mat,Mat);
193*09573ac7SBarry Smith extern PetscErrorCode MatMatSolve_SeqAIJ(Mat,Mat,Mat);
194*09573ac7SBarry Smith extern PetscErrorCode MatEqual_SeqAIJ(Mat A,Mat B,PetscBool * flg);
195*09573ac7SBarry Smith extern PetscErrorCode MatFDColoringCreate_SeqAIJ(Mat,ISColoring,MatFDColoring);
196*09573ac7SBarry Smith extern PetscErrorCode MatLoad_SeqAIJ(Mat,PetscViewer);
197*09573ac7SBarry Smith extern PetscErrorCode RegisterApplyPtAPRoutines_Private(Mat);
198*09573ac7SBarry Smith extern PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
199*09573ac7SBarry Smith extern PetscErrorCode MatMatMultNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
200*09573ac7SBarry Smith extern PetscErrorCode MatPtAPSymbolic_SeqAIJ(Mat,Mat,PetscReal,Mat*);
201*09573ac7SBarry Smith extern PetscErrorCode MatPtAPNumeric_SeqAIJ(Mat,Mat,Mat);
202*09573ac7SBarry Smith extern PetscErrorCode MatPtAPSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
203*09573ac7SBarry Smith extern PetscErrorCode MatPtAPNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
204*09573ac7SBarry Smith extern PetscErrorCode MatMatMultTranspose_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
205*09573ac7SBarry Smith extern PetscErrorCode MatMatMultTransposeSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
206*09573ac7SBarry Smith extern PetscErrorCode MatMatMultTransposeNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
207*09573ac7SBarry Smith extern PetscErrorCode MatSetValues_SeqAIJ(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
208*09573ac7SBarry Smith extern PetscErrorCode MatGetRow_SeqAIJ(Mat,PetscInt,PetscInt*,PetscInt**,PetscScalar**);
209*09573ac7SBarry Smith extern PetscErrorCode MatRestoreRow_SeqAIJ(Mat,PetscInt,PetscInt*,PetscInt**,PetscScalar**);
210*09573ac7SBarry Smith extern PetscErrorCode MatAXPY_SeqAIJ(Mat,PetscScalar,Mat,MatStructure);
211*09573ac7SBarry Smith extern PetscErrorCode MatGetRowIJ_SeqAIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt*,PetscInt *[],PetscInt *[],PetscBool  *);
212*09573ac7SBarry Smith extern PetscErrorCode MatRestoreRowIJ_SeqAIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt *,PetscInt *[],PetscInt *[],PetscBool  *);
213*09573ac7SBarry Smith extern PetscErrorCode MatGetColumnIJ_SeqAIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt*,PetscInt *[],PetscInt *[],PetscBool  *);
214*09573ac7SBarry Smith extern PetscErrorCode MatRestoreColumnIJ_SeqAIJ(Mat,PetscInt,PetscBool ,PetscBool ,PetscInt *,PetscInt *[],PetscInt *[],PetscBool  *);
215*09573ac7SBarry Smith extern PetscErrorCode MatDestroy_SeqAIJ(Mat);
216*09573ac7SBarry Smith extern PetscErrorCode MatView_SeqAIJ(Mat,PetscViewer);
2179af31e4aSHong Zhang 
218*09573ac7SBarry Smith extern PetscErrorCode Mat_CheckInode(Mat,PetscBool );
219*09573ac7SBarry Smith extern PetscErrorCode Mat_CheckInode_FactorLU(Mat,PetscBool );
220019b515eSShri Abhyankar 
221*09573ac7SBarry Smith extern PetscErrorCode MatAXPYGetPreallocation_SeqAIJ(Mat,Mat,PetscInt*);
2229f5f6813SShri Abhyankar 
22397304618SKris Buschelman EXTERN_C_BEGIN
224*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatConvert_SeqAIJ_SeqSBAIJ(Mat,const MatType,MatReuse,Mat*);
225*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatConvert_SeqAIJ_SeqBAIJ(Mat,const MatType,MatReuse,Mat*);
226*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatConvert_SeqAIJ_SeqAIJPERM(Mat,const MatType,MatReuse,Mat*);
227*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatReorderForNonzeroDiagonal_SeqAIJ(Mat,PetscReal,IS,IS);
228*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatMatMult_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
229*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatCreate_SeqAIJ(Mat);
23097304618SKris Buschelman EXTERN_C_END
231*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatAssemblyEnd_SeqAIJ(Mat,MatAssemblyType);
232*09573ac7SBarry Smith extern PetscErrorCode PETSCMAT_DLLEXPORT MatDestroy_SeqAIJ(Mat);
2332f947c57SVictor Minden 
23470f19b1fSKris Buschelman 
235003131ecSBarry Smith /*
236003131ecSBarry Smith     PetscSparseDenseMinusDot - The inner kernel of triangular solves and Gauss-Siedel smoothing. \sum_i xv[i] * r[xi[i]] for CSR storage
237003131ecSBarry Smith 
238003131ecSBarry Smith   Input Parameters:
239003131ecSBarry Smith +  nnz - the number of entries
240003131ecSBarry Smith .  r - the array of vector values
241003131ecSBarry Smith .  xv - the matrix values for the row
242003131ecSBarry Smith -  xi - the column indices of the nonzeros in the row
243003131ecSBarry Smith 
244003131ecSBarry Smith   Output Parameter:
245003131ecSBarry Smith .  sum - negative the sum of results
246003131ecSBarry Smith 
247003131ecSBarry Smith   PETSc compile flags:
248b2843cf1SBarry Smith +   PETSC_KERNEL_USE_UNROLL_4 -   don't use this; it changes nnz and hence is WRONG
249e0e43300SBarry Smith -   PETSC_KERNEL_USE_UNROLL_2 -
250003131ecSBarry Smith 
251003131ecSBarry Smith .seealso: PetscSparseDensePlusDot()
252003131ecSBarry Smith 
253003131ecSBarry Smith */
254003131ecSBarry Smith #ifdef PETSC_KERNEL_USE_UNROLL_4
255003131ecSBarry Smith #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) {\
256003131ecSBarry Smith if (nnz > 0) {\
257003131ecSBarry Smith switch (nnz & 0x3) {\
258003131ecSBarry Smith case 3: sum -= *xv++ * r[*xi++];\
259003131ecSBarry Smith case 2: sum -= *xv++ * r[*xi++];\
260003131ecSBarry Smith case 1: sum -= *xv++ * r[*xi++];\
261003131ecSBarry Smith nnz -= 4;}\
262003131ecSBarry Smith while (nnz > 0) {\
263003131ecSBarry Smith sum -=  xv[0] * r[xi[0]] - xv[1] * r[xi[1]] -\
264003131ecSBarry Smith 	xv[2] * r[xi[2]] - xv[3] * r[xi[3]];\
265003131ecSBarry Smith xv  += 4; xi += 4; nnz -= 4; }}}
266003131ecSBarry Smith 
267003131ecSBarry Smith #elif defined(PETSC_KERNEL_USE_UNROLL_2)
268003131ecSBarry Smith #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) {\
269003131ecSBarry Smith PetscInt __i,__i1,__i2;\
270003131ecSBarry Smith for(__i=0;__i<nnz-1;__i+=2) {__i1 = xi[__i]; __i2=xi[__i+1];\
271003131ecSBarry Smith sum -= (xv[__i]*r[__i1] + xv[__i+1]*r[__i2]);}\
272003131ecSBarry Smith if (nnz & 0x1) sum -= xv[__i] * r[xi[__i]];}
273003131ecSBarry Smith 
274003131ecSBarry Smith #else
275003131ecSBarry Smith #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) {\
276003131ecSBarry Smith PetscInt __i;\
277003131ecSBarry Smith for(__i=0;__i<nnz;__i++) sum -= xv[__i] * r[xi[__i]];}
278003131ecSBarry Smith #endif
279003131ecSBarry Smith 
280003131ecSBarry Smith 
281003131ecSBarry Smith 
282003131ecSBarry Smith /*
283003131ecSBarry Smith     PetscSparseDensePlusDot - The inner kernel of matrix-vector product \sum_i xv[i] * r[xi[i]] for CSR storage
284003131ecSBarry Smith 
285003131ecSBarry Smith   Input Parameters:
286003131ecSBarry Smith +  nnz - the number of entries
287003131ecSBarry Smith .  r - the array of vector values
288003131ecSBarry Smith .  xv - the matrix values for the row
289003131ecSBarry Smith -  xi - the column indices of the nonzeros in the row
290003131ecSBarry Smith 
291003131ecSBarry Smith   Output Parameter:
292003131ecSBarry Smith .  sum - the sum of results
293003131ecSBarry Smith 
294003131ecSBarry Smith   PETSc compile flags:
295b2843cf1SBarry Smith +   PETSC_KERNEL_USE_UNROLL_4 -  don't use this; it changes nnz and hence is WRONG
296e0e43300SBarry Smith -   PETSC_KERNEL_USE_UNROLL_2 -
297003131ecSBarry Smith 
298003131ecSBarry Smith .seealso: PetscSparseDenseMinusDot()
299003131ecSBarry Smith 
300003131ecSBarry Smith */
301003131ecSBarry Smith #ifdef PETSC_KERNEL_USE_UNROLL_4
302003131ecSBarry Smith #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) {\
303003131ecSBarry Smith if (nnz > 0) {\
304003131ecSBarry Smith switch (nnz & 0x3) {\
305003131ecSBarry Smith case 3: sum += *xv++ * r[*xi++];\
306003131ecSBarry Smith case 2: sum += *xv++ * r[*xi++];\
307003131ecSBarry Smith case 1: sum += *xv++ * r[*xi++];\
308003131ecSBarry Smith nnz -= 4;}\
309003131ecSBarry Smith while (nnz > 0) {\
310003131ecSBarry Smith sum +=  xv[0] * r[xi[0]] + xv[1] * r[xi[1]] +\
311003131ecSBarry Smith 	xv[2] * r[xi[2]] + xv[3] * r[xi[3]];\
312003131ecSBarry Smith xv  += 4; xi += 4; nnz -= 4; }}}
313003131ecSBarry Smith 
314003131ecSBarry Smith #elif defined(PETSC_KERNEL_USE_UNROLL_2)
315003131ecSBarry Smith #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) {\
316003131ecSBarry Smith PetscInt __i,__i1,__i2;\
317003131ecSBarry Smith for(__i=0;__i<nnz-1;__i+=2) {__i1 = xi[__i]; __i2=xi[__i+1];\
318003131ecSBarry Smith sum += (xv[__i]*r[__i1] + xv[__i+1]*r[__i2]);}\
319003131ecSBarry Smith if (nnz & 0x1) sum += xv[__i] * r[xi[__i]];}
320003131ecSBarry Smith 
321003131ecSBarry Smith #else
322003131ecSBarry Smith #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) {\
323003131ecSBarry Smith  PetscInt __i;\
324003131ecSBarry Smith for(__i=0;__i<nnz;__i++) sum += xv[__i] * r[xi[__i]];}
325003131ecSBarry Smith #endif
326003131ecSBarry Smith 
3272d40f771SBarry Smith #endif
328