Actual source code: aij.h

petsc-3.8.4 2018-03-24
Report Typos and Errors


  5:  #include <petsc/private/matimpl.h>
  6:  #include <petscctable.h>

  8: /*
  9:     Struct header shared by SeqAIJ, SeqBAIJ and SeqSBAIJ matrix formats
 10: */
 11: #define SEQAIJHEADER(datatype)        \
 12:   PetscBool roworiented;              /* if true, row-oriented input, default */ \
 13:   PetscInt  nonew;                    /* 1 don't add new nonzeros, -1 generate error on new */ \
 14:   PetscInt  nounused;                 /* -1 generate error on unused space */ \
 15:   PetscBool singlemalloc;             /* if true a, i, and j have been obtained with one big malloc */ \
 16:   PetscInt  maxnz;                    /* allocated nonzeros */ \
 17:   PetscInt  *imax;                    /* maximum space allocated for each row */ \
 18:   PetscInt  *ilen;                    /* actual length of each row */ \
 19:   PetscBool free_imax_ilen;  \
 20:   PetscInt  reallocs;                 /* number of mallocs done during MatSetValues() \
 21:                                         as more values are set than were prealloced */\
 22:   PetscInt          rmax;             /* max nonzeros in any row */ \
 23:   PetscBool         keepnonzeropattern;   /* keeps matrix structure same in calls to MatZeroRows()*/ \
 24:   PetscBool         ignorezeroentries; \
 25:   PetscBool         free_ij;          /* free the column indices j and row offsets i when the matrix is destroyed */ \
 26:   PetscBool         free_a;           /* free the numerical values when matrix is destroy */ \
 27:   Mat_CompressedRow compressedrow;    /* use compressed row format */                      \
 28:   PetscInt          nz;               /* nonzeros */                                       \
 29:   PetscInt          *i;               /* pointer to beginning of each row */               \
 30:   PetscInt          *j;               /* column values: j + i[k] - 1 is start of row k */  \
 31:   PetscInt          *diag;            /* pointers to diagonal elements */                  \
 32:   PetscInt          nonzerorowcnt;    /* how many rows have nonzero entries */             \
 33:   PetscBool         free_diag;         \
 34:   datatype          *a;               /* nonzero elements */                               \
 35:   PetscScalar       *solve_work;      /* work space used in MatSolve */                    \
 36:   IS                row, col, icol;   /* index sets, used for reorderings */ \
 37:   PetscBool         pivotinblocks;    /* pivot inside factorization of each diagonal block */ \
 38:   Mat               parent;           /* set if this matrix was formed with MatDuplicate(...,MAT_SHARE_NONZERO_PATTERN,....); \
 39:                                          means that this shares some data structures with the parent including diag, ilen, imax, i, j */\
 40:   Mat_SubSppt       *submatis1         /* used by MatCreateSubMatrices_MPIXAIJ_Local */

 42: typedef struct {
 43:   MatTransposeColoring matcoloring;
 44:   Mat                  Bt_den;       /* dense matrix of B^T */
 45:   Mat                  ABt_den;      /* dense matrix of A*B^T */
 46:   PetscBool            usecoloring;
 47:   PetscErrorCode (*destroy)(Mat);
 48: } Mat_MatMatTransMult;

 50: typedef struct { /* for MatTransposeMatMult_SeqAIJ_SeqDense() */
 51:   Mat          mA;           /* maij matrix of A */
 52:   Vec          bt,ct;        /* vectors to hold locally transposed arrays of B and C */
 53:   PetscErrorCode (*destroy)(Mat);
 54: } Mat_MatTransMatMult;

 56: typedef struct {
 57:   PetscInt    *api,*apj;       /* symbolic structure of A*P */
 58:   PetscScalar *apa;            /* temporary array for storing one row of A*P */
 59:   PetscErrorCode (*destroy)(Mat);
 60: } Mat_PtAP;

 62: typedef struct {
 63:   MatTransposeColoring matcoloring;
 64:   Mat                  Rt;    /* sparse or dense matrix of R^T */
 65:   Mat                  RARt;  /* dense matrix of R*A*R^T */
 66:   Mat                  ARt;   /* A*R^T used for the case -matrart_color_art */
 67:   MatScalar            *work; /* work array to store columns of A*R^T used in MatMatMatMultNumeric_SeqAIJ_SeqAIJ_SeqDense() */
 68:   PetscErrorCode (*destroy)(Mat);
 69: } Mat_RARt;

 71: typedef struct {
 72:   Mat BC;               /* temp matrix for storing B*C */
 73:   PetscErrorCode (*destroy)(Mat);
 74: } Mat_MatMatMatMult;

 76: /*
 77:   MATSEQAIJ format - Compressed row storage (also called Yale sparse matrix
 78:   format) or compressed sparse row (CSR).  The i[] and j[] arrays start at 0. For example,
 79:   j[i[k]+p] is the pth column in row k.  Note that the diagonal
 80:   matrix elements are stored with the rest of the nonzeros (not separately).
 81: */

 83: /* Info about i-nodes (identical nodes) helper class for SeqAIJ */
 84: typedef struct {
 85:   MatScalar        *bdiag,*ibdiag,*ssor_work;        /* diagonal blocks of matrix used for MatSOR_SeqAIJ_Inode() */
 86:   PetscInt         bdiagsize;                         /* length of bdiag and ibdiag */
 87:   PetscBool        ibdiagvalid;                       /* do ibdiag[] and bdiag[] contain the most recent values */

 89:   PetscBool        use;
 90:   PetscInt         node_count;                     /* number of inodes */
 91:   PetscInt         *size;                          /* size of each inode */
 92:   PetscInt         limit;                          /* inode limit */
 93:   PetscInt         max_limit;                      /* maximum supported inode limit */
 94:   PetscBool        checked;                        /* if inodes have been checked for */
 95:   PetscObjectState mat_nonzerostate;               /* non-zero state when inodes were checked for */
 96: } Mat_SeqAIJ_Inode;

 98: PETSC_INTERN PetscErrorCode MatView_SeqAIJ_Inode(Mat,PetscViewer);
 99: PETSC_INTERN PetscErrorCode MatAssemblyEnd_SeqAIJ_Inode(Mat,MatAssemblyType);
100: PETSC_INTERN PetscErrorCode MatDestroy_SeqAIJ_Inode(Mat);
101: PETSC_INTERN PetscErrorCode MatCreate_SeqAIJ_Inode(Mat);
102: PETSC_INTERN PetscErrorCode MatSetOption_SeqAIJ_Inode(Mat,MatOption,PetscBool);
103: PETSC_INTERN PetscErrorCode MatDuplicate_SeqAIJ_Inode(Mat,MatDuplicateOption,Mat*);
104: PETSC_INTERN PetscErrorCode MatDuplicateNoCreate_SeqAIJ(Mat,Mat,MatDuplicateOption,PetscBool);
105: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_Inode_inplace(Mat,Mat,const MatFactorInfo*);
106: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_Inode(Mat,Mat,const MatFactorInfo*);

108: typedef struct {
109:   SEQAIJHEADER(MatScalar);
110:   Mat_SeqAIJ_Inode inode;
111:   MatScalar        *saved_values;             /* location for stashing nonzero values of matrix */

113:   PetscScalar *idiag,*mdiag,*ssor_work;       /* inverse of diagonal entries, diagonal values and workspace for Eisenstat trick */
114:   PetscBool   idiagvalid;                     /* current idiag[] and mdiag[] are valid */
115:   PetscScalar *ibdiag;                        /* inverses of block diagonals */
116:   PetscBool   ibdiagvalid;                    /* inverses of block diagonals are valid. */
117:   PetscScalar fshift,omega;                   /* last used omega and fshift */

119:   ISColoring  coloring;                       /* set with MatADSetColoring() used by MatADSetValues() */

121:   PetscScalar         *matmult_abdense;    /* used by MatMatMult() */
122:   Mat_PtAP            *ptap;               /* used by MatPtAP() */
123:   Mat_MatMatMatMult   *matmatmatmult;      /* used by MatMatMatMult() */
124:   Mat_RARt            *rart;               /* used by MatRARt() */
125:   Mat_MatMatTransMult *abt;                /* used by MatMatTransposeMult() */
126: } Mat_SeqAIJ;

128: /*
129:   Frees the a, i, and j arrays from the XAIJ (AIJ, BAIJ, and SBAIJ) matrix types
130: */
131: PETSC_STATIC_INLINE PetscErrorCode MatSeqXAIJFreeAIJ(Mat AA,MatScalar **a,PetscInt **j,PetscInt **i)
132: {
134:   Mat_SeqAIJ     *A = (Mat_SeqAIJ*) AA->data;
135:   if (A->singlemalloc) {
136:     PetscFree3(*a,*j,*i);
137:   } else {
138:     if (A->free_a)  {PetscFree(*a);}
139:     if (A->free_ij) {PetscFree(*j);}
140:     if (A->free_ij) {PetscFree(*i);}
141:   }
142:   return 0;
143: }
144: /*
145:     Allocates larger a, i, and j arrays for the XAIJ (AIJ, BAIJ, and SBAIJ) matrix types
146:     This is a macro because it takes the datatype as an argument which can be either a Mat or a MatScalar
147: */
148: #define MatSeqXAIJReallocateAIJ(Amat,AM,BS2,NROW,ROW,COL,RMAX,AA,AI,AJ,RP,AP,AIMAX,NONEW,datatype) \
149:   if (NROW >= RMAX) { \
150:     Mat_SeqAIJ *Ain = (Mat_SeqAIJ*)Amat->data; \
151:     /* there is no extra room in row, therefore enlarge */ \
152:     PetscInt CHUNKSIZE = 15,new_nz = AI[AM] + CHUNKSIZE,len,*new_i=0,*new_j=0; \
153:     datatype *new_a; \
154:  \
155:     if (NONEW == -2) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"New nonzero at (%D,%D) caused a malloc\nUse MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to turn off this check",ROW,COL); \
156:     /* malloc new storage space */ \
157:     PetscMalloc3(BS2*new_nz,&new_a,new_nz,&new_j,AM+1,&new_i); \
158:  \
159:     /* copy over old data into new slots */ \
160:     for (ii=0; ii<ROW+1; ii++) {new_i[ii] = AI[ii];} \
161:     for (ii=ROW+1; ii<AM+1; ii++) {new_i[ii] = AI[ii]+CHUNKSIZE;} \
162:     PetscMemcpy(new_j,AJ,(AI[ROW]+NROW)*sizeof(PetscInt)); \
163:     len  = (new_nz - CHUNKSIZE - AI[ROW] - NROW); \
164:     PetscMemcpy(new_j+AI[ROW]+NROW+CHUNKSIZE,AJ+AI[ROW]+NROW,len*sizeof(PetscInt)); \
165:     PetscMemcpy(new_a,AA,BS2*(AI[ROW]+NROW)*sizeof(datatype)); \
166:     PetscMemzero(new_a+BS2*(AI[ROW]+NROW),BS2*CHUNKSIZE*sizeof(datatype)); \
167:     PetscMemcpy(new_a+BS2*(AI[ROW]+NROW+CHUNKSIZE),AA+BS2*(AI[ROW]+NROW),BS2*len*sizeof(datatype));  \
168:     /* free up old matrix storage */ \
169:     MatSeqXAIJFreeAIJ(A,&Ain->a,&Ain->j,&Ain->i); \
170:     AA                = new_a; \
171:     Ain->a            = (MatScalar*) new_a;                   \
172:     AI                = Ain->i = new_i; AJ = Ain->j = new_j;  \
173:     Ain->singlemalloc = PETSC_TRUE; \
174:  \
175:     RP          = AJ + AI[ROW]; AP = AA + BS2*AI[ROW]; \
176:     RMAX        = AIMAX[ROW] = AIMAX[ROW] + CHUNKSIZE; \
177:     Ain->maxnz += BS2*CHUNKSIZE; \
178:     Ain->reallocs++; \
179:   } \

181: #define MatSeqXAIJReallocateAIJ_structure_only(Amat,AM,BS2,NROW,ROW,COL,RMAX,AI,AJ,RP,AIMAX,NONEW,datatype) \
182:   if (NROW >= RMAX) { \
183:     Mat_SeqAIJ *Ain = (Mat_SeqAIJ*)Amat->data; \
184:     /* there is no extra room in row, therefore enlarge */ \
185:     PetscInt CHUNKSIZE = 15,new_nz = AI[AM] + CHUNKSIZE,len,*new_i=0,*new_j=0; \
186:  \
187:     if (NONEW == -2) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"New nonzero at (%D,%D) caused a malloc\nUse MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to turn off this check",ROW,COL); \
188:     /* malloc new storage space */ \
189:     PetscMalloc1(new_nz,&new_j); \
190:     PetscMalloc1(AM+1,&new_i);\
191:  \
192:     /* copy over old data into new slots */ \
193:     for (ii=0; ii<ROW+1; ii++) {new_i[ii] = AI[ii];} \
194:     for (ii=ROW+1; ii<AM+1; ii++) {new_i[ii] = AI[ii]+CHUNKSIZE;} \
195:     PetscMemcpy(new_j,AJ,(AI[ROW]+NROW)*sizeof(PetscInt)); \
196:     len  = (new_nz - CHUNKSIZE - AI[ROW] - NROW); \
197:     PetscMemcpy(new_j+AI[ROW]+NROW+CHUNKSIZE,AJ+AI[ROW]+NROW,len*sizeof(PetscInt)); \
198:  \
199:     /* free up old matrix storage */ \
200:     MatSeqXAIJFreeAIJ(A,&Ain->a,&Ain->j,&Ain->i); \
201:     Ain->a            = NULL;                   \
202:     AI                = Ain->i = new_i; AJ = Ain->j = new_j;  \
203:     Ain->singlemalloc = PETSC_FALSE; \
204:     Ain->free_a       = PETSC_FALSE;             \
205:  \
206:     RP          = AJ + AI[ROW];    \
207:     RMAX        = AIMAX[ROW] = AIMAX[ROW] + CHUNKSIZE; \
208:     Ain->maxnz += BS2*CHUNKSIZE; \
209:     Ain->reallocs++; \
210:   } \

212: PETSC_INTERN PetscErrorCode MatSeqAIJSetPreallocation_SeqAIJ(Mat,PetscInt,const PetscInt*);
213: PETSC_INTERN PetscErrorCode MatILUFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,IS,const MatFactorInfo*);
214: PETSC_INTERN PetscErrorCode MatILUFactorSymbolic_SeqAIJ(Mat,Mat,IS,IS,const MatFactorInfo*);
215: PETSC_INTERN PetscErrorCode MatILUFactorSymbolic_SeqAIJ_ilu0(Mat,Mat,IS,IS,const MatFactorInfo*);

217: PETSC_INTERN PetscErrorCode MatICCFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,const MatFactorInfo*);
218: PETSC_INTERN PetscErrorCode MatICCFactorSymbolic_SeqAIJ(Mat,Mat,IS,const MatFactorInfo*);
219: PETSC_INTERN PetscErrorCode MatCholeskyFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,const MatFactorInfo*);
220: PETSC_INTERN PetscErrorCode MatCholeskyFactorSymbolic_SeqAIJ(Mat,Mat,IS,const MatFactorInfo*);
221: PETSC_INTERN PetscErrorCode MatCholeskyFactorNumeric_SeqAIJ_inplace(Mat,Mat,const MatFactorInfo*);
222: PETSC_INTERN PetscErrorCode MatCholeskyFactorNumeric_SeqAIJ(Mat,Mat,const MatFactorInfo*);
223: PETSC_INTERN PetscErrorCode MatDuplicate_SeqAIJ(Mat,MatDuplicateOption,Mat*);
224: PETSC_INTERN PetscErrorCode MatCopy_SeqAIJ(Mat,Mat,MatStructure);
225: PETSC_INTERN PetscErrorCode MatMissingDiagonal_SeqAIJ(Mat,PetscBool*,PetscInt*);
226: PETSC_INTERN PetscErrorCode MatMarkDiagonal_SeqAIJ(Mat);
227: PETSC_INTERN PetscErrorCode MatFindZeroDiagonals_SeqAIJ_Private(Mat,PetscInt*,PetscInt**);

229: PETSC_INTERN PetscErrorCode MatMult_SeqAIJ(Mat A,Vec,Vec);
230: PETSC_INTERN PetscErrorCode MatMultAdd_SeqAIJ(Mat A,Vec,Vec,Vec);
231: PETSC_INTERN PetscErrorCode MatMultTranspose_SeqAIJ(Mat A,Vec,Vec);
232: PETSC_INTERN PetscErrorCode MatMultTransposeAdd_SeqAIJ(Mat A,Vec,Vec,Vec);
233: PETSC_INTERN PetscErrorCode MatSOR_SeqAIJ(Mat,Vec,PetscReal,MatSORType,PetscReal,PetscInt,PetscInt,Vec);

235: PETSC_INTERN PetscErrorCode MatSetOption_SeqAIJ(Mat,MatOption,PetscBool);

237: PETSC_INTERN PetscErrorCode MatGetSymbolicTranspose_SeqAIJ(Mat,PetscInt *[],PetscInt *[]);
238: PETSC_INTERN PetscErrorCode MatGetSymbolicTransposeReduced_SeqAIJ(Mat,PetscInt,PetscInt,PetscInt *[],PetscInt *[]);
239: PETSC_INTERN PetscErrorCode MatRestoreSymbolicTranspose_SeqAIJ(Mat,PetscInt *[],PetscInt *[]);
240: PETSC_INTERN PetscErrorCode MatTransposeSymbolic_SeqAIJ(Mat,Mat*);
241: PETSC_INTERN PetscErrorCode MatTranspose_SeqAIJ(Mat,MatReuse,Mat*);
242: PETSC_INTERN PetscErrorCode MatToSymmetricIJ_SeqAIJ(PetscInt,PetscInt*,PetscInt*,PetscBool,PetscInt,PetscInt,PetscInt**,PetscInt**);
243: PETSC_INTERN PetscErrorCode MatLUFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,IS,const MatFactorInfo*);
244: PETSC_INTERN PetscErrorCode MatLUFactorSymbolic_SeqAIJ(Mat,Mat,IS,IS,const MatFactorInfo*);
245: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_inplace(Mat,Mat,const MatFactorInfo*);
246: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ(Mat,Mat,const MatFactorInfo*);
247: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_InplaceWithPerm(Mat,Mat,const MatFactorInfo*);
248: PETSC_INTERN PetscErrorCode MatLUFactor_SeqAIJ(Mat,IS,IS,const MatFactorInfo*);
249: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_inplace(Mat,Vec,Vec);
250: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ(Mat,Vec,Vec);
251: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_Inode_inplace(Mat,Vec,Vec);
252: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_Inode(Mat,Vec,Vec);
253: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_NaturalOrdering_inplace(Mat,Vec,Vec);
254: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_NaturalOrdering(Mat,Vec,Vec);
255: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_InplaceWithPerm(Mat,Vec,Vec);
256: PETSC_INTERN PetscErrorCode MatSolveAdd_SeqAIJ_inplace(Mat,Vec,Vec,Vec);
257: PETSC_INTERN PetscErrorCode MatSolveAdd_SeqAIJ(Mat,Vec,Vec,Vec);
258: PETSC_INTERN PetscErrorCode MatSolveTranspose_SeqAIJ_inplace(Mat,Vec,Vec);
259: PETSC_INTERN PetscErrorCode MatSolveTranspose_SeqAIJ(Mat,Vec,Vec);
260: PETSC_INTERN PetscErrorCode MatSolveTransposeAdd_SeqAIJ_inplace(Mat,Vec,Vec,Vec);
261: PETSC_INTERN PetscErrorCode MatSolveTransposeAdd_SeqAIJ(Mat,Vec,Vec,Vec);
262: PETSC_INTERN PetscErrorCode MatMatSolve_SeqAIJ_inplace(Mat,Mat,Mat);
263: PETSC_INTERN PetscErrorCode MatMatSolve_SeqAIJ(Mat,Mat,Mat);
264: PETSC_INTERN PetscErrorCode MatEqual_SeqAIJ(Mat,Mat,PetscBool*);
265: PETSC_INTERN PetscErrorCode MatFDColoringCreate_SeqXAIJ(Mat,ISColoring,MatFDColoring);
266: PETSC_INTERN PetscErrorCode MatFDColoringSetUp_SeqXAIJ(Mat,ISColoring,MatFDColoring);
267: PETSC_INTERN PetscErrorCode MatFDColoringSetUpBlocked_AIJ_Private(Mat,MatFDColoring,PetscInt);
268: PETSC_INTERN PetscErrorCode MatLoad_SeqAIJ(Mat,PetscViewer);
269: PETSC_INTERN PetscErrorCode RegisterApplyPtAPRoutines_Private(Mat);

271: PETSC_INTERN PetscErrorCode MatMatMult_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
272: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
273: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqDense_SeqAIJ(Mat,Mat,PetscReal,Mat*);
274: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_Scalable(Mat,Mat,PetscReal,Mat*);
275: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_Scalable_fast(Mat,Mat,PetscReal,Mat*);
276: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_Heap(Mat,Mat,PetscReal,Mat*);
277: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_BTHeap(Mat,Mat,PetscReal,Mat*);
278: PETSC_INTERN PetscErrorCode MatMatMultNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
279: PETSC_INTERN PetscErrorCode MatMatMultNumeric_SeqDense_SeqAIJ(Mat,Mat,Mat);
280: PETSC_INTERN PetscErrorCode MatMatMultNumeric_SeqAIJ_SeqAIJ_Scalable(Mat,Mat,Mat);

282: PETSC_INTERN PetscErrorCode MatPtAP_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
283: PETSC_INTERN PetscErrorCode MatPtAPSymbolic_SeqAIJ_SeqAIJ_DenseAxpy(Mat,Mat,PetscReal,Mat*);
284: PETSC_INTERN PetscErrorCode MatPtAPSymbolic_SeqAIJ_SeqAIJ_SparseAxpy(Mat,Mat,PetscReal,Mat*);
285: PETSC_INTERN PetscErrorCode MatPtAPNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
286: PETSC_INTERN PetscErrorCode MatPtAPNumeric_SeqAIJ_SeqAIJ_SparseAxpy(Mat,Mat,Mat);

288: PETSC_INTERN PetscErrorCode MatRARtSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
289: PETSC_INTERN PetscErrorCode MatRARtSymbolic_SeqAIJ_SeqAIJ_matmattransposemult(Mat,Mat,PetscReal,Mat*);
290: PETSC_INTERN PetscErrorCode MatRARtSymbolic_SeqAIJ_SeqAIJ_colorrart(Mat,Mat,PetscReal,Mat*);
291: PETSC_INTERN PetscErrorCode MatRARtNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
292: PETSC_INTERN PetscErrorCode MatRARtNumeric_SeqAIJ_SeqAIJ_matmattransposemult(Mat,Mat,Mat);
293: PETSC_INTERN PetscErrorCode MatRARtNumeric_SeqAIJ_SeqAIJ_colorrart(Mat,Mat,Mat);

295: PETSC_INTERN PetscErrorCode MatTransposeMatMult_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
296: PETSC_INTERN PetscErrorCode MatTransposeMatMultSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
297: PETSC_INTERN PetscErrorCode MatTransposeMatMultNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);

299: PETSC_INTERN PetscErrorCode MatTransposeMatMult_SeqAIJ_SeqDense(Mat,Mat,MatReuse,PetscReal,Mat*);
300: PETSC_INTERN PetscErrorCode MatTransposeMatMultSymbolic_SeqAIJ_SeqDense(Mat,Mat,PetscReal,Mat*);
301: PETSC_INTERN PetscErrorCode MatTransposeMatMultNumeric_SeqAIJ_SeqDense(Mat,Mat,Mat);

303: PETSC_INTERN PetscErrorCode MatMatTransposeMult_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
304: PETSC_INTERN PetscErrorCode MatMatTransposeMultSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
305: PETSC_INTERN PetscErrorCode MatMatTransposeMultNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
306: PETSC_INTERN PetscErrorCode MatTransposeColoringCreate_SeqAIJ(Mat,ISColoring,MatTransposeColoring);
307: PETSC_INTERN PetscErrorCode MatTransColoringApplySpToDen_SeqAIJ(MatTransposeColoring,Mat,Mat);
308: PETSC_INTERN PetscErrorCode MatTransColoringApplyDenToSp_SeqAIJ(MatTransposeColoring,Mat,Mat);

310: PETSC_INTERN PetscErrorCode MatMatMatMult_SeqAIJ_SeqAIJ_SeqAIJ(Mat,Mat,Mat,MatReuse,PetscReal,Mat*);
311: PETSC_INTERN PetscErrorCode MatMatMatMultSymbolic_SeqAIJ_SeqAIJ_SeqAIJ(Mat,Mat,Mat,PetscReal,Mat*);
312: PETSC_INTERN PetscErrorCode MatMatMatMultNumeric_SeqAIJ_SeqAIJ_SeqAIJ(Mat,Mat,Mat,Mat);

314: PETSC_INTERN PetscErrorCode MatSetValues_SeqAIJ(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
315: PETSC_INTERN PetscErrorCode MatGetRow_SeqAIJ(Mat,PetscInt,PetscInt*,PetscInt**,PetscScalar**);
316: PETSC_INTERN PetscErrorCode MatRestoreRow_SeqAIJ(Mat,PetscInt,PetscInt*,PetscInt**,PetscScalar**);
317: PETSC_INTERN PetscErrorCode MatScale_SeqAIJ(Mat,PetscScalar);
318: PETSC_INTERN PetscErrorCode MatDiagonalScale_SeqAIJ(Mat,Vec,Vec);
319: PETSC_INTERN PetscErrorCode MatDiagonalSet_SeqAIJ(Mat,Vec,InsertMode);
320: PETSC_INTERN PetscErrorCode MatAXPY_SeqAIJ(Mat,PetscScalar,Mat,MatStructure);
321: PETSC_INTERN PetscErrorCode MatGetRowIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
322: PETSC_INTERN PetscErrorCode MatRestoreRowIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
323: PETSC_INTERN PetscErrorCode MatGetColumnIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
324: PETSC_INTERN PetscErrorCode MatRestoreColumnIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
325: PETSC_INTERN PetscErrorCode MatGetColumnIJ_SeqAIJ_Color(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscInt *[],PetscBool*);
326: PETSC_INTERN PetscErrorCode MatRestoreColumnIJ_SeqAIJ_Color(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscInt *[],PetscBool*);
327: PETSC_INTERN PetscErrorCode MatDestroy_SeqAIJ(Mat);
328: PETSC_INTERN PetscErrorCode MatSetUp_SeqAIJ(Mat);
329: PETSC_INTERN PetscErrorCode MatView_SeqAIJ(Mat,PetscViewer);

331: PETSC_INTERN PetscErrorCode MatSeqAIJInvalidateDiagonal(Mat);
332: PETSC_INTERN PetscErrorCode MatSeqAIJInvalidateDiagonal_Inode(Mat);
333: PETSC_INTERN PetscErrorCode MatSeqAIJCheckInode(Mat);
334: PETSC_INTERN PetscErrorCode MatSeqAIJCheckInode_FactorLU(Mat);

336: PETSC_INTERN PetscErrorCode MatAXPYGetPreallocation_SeqAIJ(Mat,Mat,PetscInt*);

338: PETSC_INTERN PetscErrorCode MatMatMatMult_Transpose_AIJ_AIJ(Mat,Mat,Mat,MatReuse,PetscReal,Mat*);
339: PETSC_EXTERN PetscErrorCode MatlabEnginePut_SeqAIJ(PetscObject,void*);
340: PETSC_EXTERN PetscErrorCode MatlabEngineGet_SeqAIJ(PetscObject,void*);
341: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqSBAIJ(Mat,MatType,MatReuse,Mat*);
342: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqBAIJ(Mat,MatType,MatReuse,Mat*);
343: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqDense(Mat,MatType,MatReuse,Mat*);
344: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJCRL(Mat,MatType,MatReuse,Mat*);
345: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_Elemental(Mat,MatType,MatReuse,Mat*);
346: PETSC_INTERN PetscErrorCode MatConvert_AIJ_HYPRE(Mat,MatType,MatReuse,Mat*);
347: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJPERM(Mat,MatType,MatReuse,Mat*);
348: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJMKL(Mat,MatType,MatReuse,Mat*);
349: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJViennaCL(Mat,MatType,MatReuse,Mat*);
350: PETSC_INTERN PetscErrorCode MatReorderForNonzeroDiagonal_SeqAIJ(Mat,PetscReal,IS,IS);
351: PETSC_INTERN PetscErrorCode MatMatMult_SeqDense_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
352: PETSC_INTERN PetscErrorCode MatRARt_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
353: PETSC_EXTERN PetscErrorCode MatCreate_SeqAIJ(Mat);
354: PETSC_INTERN PetscErrorCode MatAssemblyEnd_SeqAIJ(Mat,MatAssemblyType);

356: PETSC_INTERN PetscErrorCode MatAXPYGetPreallocation_SeqX_private(PetscInt,const PetscInt*,const PetscInt*,const PetscInt*,const PetscInt*,PetscInt*);
357: PETSC_INTERN PetscErrorCode MatCreateMPIMatConcatenateSeqMat_SeqAIJ(MPI_Comm,Mat,PetscInt,MatReuse,Mat*);
358: PETSC_INTERN PetscErrorCode MatCreateMPIMatConcatenateSeqMat_MPIAIJ(MPI_Comm,Mat,PetscInt,MatReuse,Mat*);

360: PETSC_INTERN PetscErrorCode MatSetSeqMat_SeqAIJ(Mat,IS,IS,MatStructure,Mat);
361: PETSC_INTERN PetscErrorCode MatDestroySubMatrix_Private(Mat_SubSppt*);
362: PETSC_INTERN PetscErrorCode MatDestroySubMatrix_SeqAIJ(Mat);
363: PETSC_INTERN PetscErrorCode MatDestroySubMatrix_Dummy(Mat);
364: PETSC_INTERN PetscErrorCode MatCreateSubMatrix_SeqAIJ(Mat,IS,IS,PetscInt,MatReuse,Mat*);

366: /*
367:     PetscSparseDenseMinusDot - The inner kernel of triangular solves and Gauss-Siedel smoothing. \sum_i xv[i] * r[xi[i]] for CSR storage

369:   Input Parameters:
370: +  nnz - the number of entries
371: .  r - the array of vector values
372: .  xv - the matrix values for the row
373: -  xi - the column indices of the nonzeros in the row

375:   Output Parameter:
376: .  sum - negative the sum of results

378:   PETSc compile flags:
379: +   PETSC_KERNEL_USE_UNROLL_4 -   don't use this; it changes nnz and hence is WRONG
380: -   PETSC_KERNEL_USE_UNROLL_2 -

382: .seealso: PetscSparseDensePlusDot()

384: */
385: #if defined(PETSC_KERNEL_USE_UNROLL_4)
386: #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) { \
387:     if (nnz > 0) { \
388:       switch (nnz & 0x3) { \
389:       case 3: sum -= *xv++ *r[*xi++]; \
390:       case 2: sum -= *xv++ *r[*xi++]; \
391:       case 1: sum -= *xv++ *r[*xi++]; \
392:         nnz       -= 4;} \
393:       while (nnz > 0) { \
394:         sum -=  xv[0] * r[xi[0]] - xv[1] * r[xi[1]] - \
395:                xv[2] * r[xi[2]] - xv[3] * r[xi[3]]; \
396:         xv += 4; xi += 4; nnz -= 4; }}}

398: #elif defined(PETSC_KERNEL_USE_UNROLL_2)
399: #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) { \
400:     PetscInt __i,__i1,__i2; \
401:     for (__i=0; __i<nnz-1; __i+=2) {__i1 = xi[__i]; __i2=xi[__i+1]; \
402:                                     sum -= (xv[__i]*r[__i1] + xv[__i+1]*r[__i2]);} \
403:     if (nnz & 0x1) sum -= xv[__i] * r[xi[__i]];}

405: #else
406: #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) { \
407:     PetscInt __i; \
408:     for (__i=0; __i<nnz; __i++) sum -= xv[__i] * r[xi[__i]];}
409: #endif



413: /*
414:     PetscSparseDensePlusDot - The inner kernel of matrix-vector product \sum_i xv[i] * r[xi[i]] for CSR storage

416:   Input Parameters:
417: +  nnz - the number of entries
418: .  r - the array of vector values
419: .  xv - the matrix values for the row
420: -  xi - the column indices of the nonzeros in the row

422:   Output Parameter:
423: .  sum - the sum of results

425:   PETSc compile flags:
426: +   PETSC_KERNEL_USE_UNROLL_4 -  don't use this; it changes nnz and hence is WRONG
427: -   PETSC_KERNEL_USE_UNROLL_2 -

429: .seealso: PetscSparseDenseMinusDot()

431: */
432: #if defined(PETSC_KERNEL_USE_UNROLL_4)
433: #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) { \
434:     if (nnz > 0) { \
435:       switch (nnz & 0x3) { \
436:       case 3: sum += *xv++ *r[*xi++]; \
437:       case 2: sum += *xv++ *r[*xi++]; \
438:       case 1: sum += *xv++ *r[*xi++]; \
439:         nnz       -= 4;} \
440:       while (nnz > 0) { \
441:         sum +=  xv[0] * r[xi[0]] + xv[1] * r[xi[1]] + \
442:                xv[2] * r[xi[2]] + xv[3] * r[xi[3]]; \
443:         xv += 4; xi += 4; nnz -= 4; }}}

445: #elif defined(PETSC_KERNEL_USE_UNROLL_2)
446: #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) { \
447:     PetscInt __i,__i1,__i2; \
448:     for (__i=0; __i<nnz-1; __i+=2) {__i1 = xi[__i]; __i2=xi[__i+1]; \
449:                                     sum += (xv[__i]*r[__i1] + xv[__i+1]*r[__i2]);} \
450:     if (nnz & 0x1) sum += xv[__i] * r[xi[__i]];}

452: #else
453: #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) { \
454:     PetscInt __i; \
455:     for (__i=0; __i<nnz; __i++) sum += xv[__i] * r[xi[__i]];}
456: #endif


459: /*
460:     PetscSparseDenseMaxDot - The inner kernel of a modified matrix-vector product \max_i xv[i] * r[xi[i]] for CSR storage

462:   Input Parameters:
463: +  nnz - the number of entries
464: .  r - the array of vector values
465: .  xv - the matrix values for the row
466: -  xi - the column indices of the nonzeros in the row

468:   Output Parameter:
469: .  max - the max of results

471: .seealso: PetscSparseDensePlusDot(), PetscSparseDenseMinusDot()

473: */
474: #define PetscSparseDenseMaxDot(max,r,xv,xi,nnz) { \
475:     PetscInt __i; \
476:     for (__i=0; __i<nnz; __i++) max = PetscMax(PetscRealPart(max), PetscRealPart(xv[__i] * r[xi[__i]]));}

478: /*
479:  Add column indices into table for counting the max nonzeros of merged rows
480:  */
481: #define MatRowMergeMax_SeqAIJ(mat,nrows,ta) {       \
482:     PetscInt _j,_row,_nz,*_col;                     \
483:     if (mat) { \
484:       for (_row=0; _row<nrows; _row++) {   \
485:         _nz = mat->i[_row+1] - mat->i[_row];    \
486:         for (_j=0; _j<_nz; _j++) {               \
487:           _col = _j + mat->j + mat->i[_row];       \
488:           PetscTableAdd(ta,*_col+1,1,INSERT_VALUES);                    \
489:         }                                                               \
490:       }                                                                 \
491:     }    \
492: }

494: /*
495:  Add column indices into table for counting the nonzeros of merged rows
496:  */
497: #define MatMergeRows_SeqAIJ(mat,nrows,rows,ta) {    \
498:   PetscInt _j,_row,_nz,*_col,_i;                      \
499:     for (_i=0; _i<nrows; _i++) {\
500:       _row = rows[_i]; \
501:       _nz = mat->i[_row+1] - mat->i[_row]; \
502:       for (_j=0; _j<_nz; _j++) {                \
503:         _col = _j + mat->j + mat->i[_row];       \
504:         PetscTableAdd(ta,*_col+1,1,INSERT_VALUES); \
505:       }                                                                 \
506:     }                                                                   \
507: }

509: #endif