Date: 2013-07-02T14:41:43+00:00

Actual source code: aij.h
petsc-3.4.2 2013-07-02

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

      7: /*
      8:     Struct header shared by SeqAIJ, SeqBAIJ and SeqSBAIJ matrix formats
      9: */
     10: #define SEQAIJHEADER(datatype)        \
     11:   PetscBool roworiented;              /* if true, row-oriented input, default */ \
     12:   PetscInt  nonew;                    /* 1 don't add new nonzeros, -1 generate error on new */ \
     13:   PetscInt  nounused;                 /* -1 generate error on unused space */ \
     14:   PetscBool singlemalloc;             /* if true a, i, and j have been obtained with one big malloc */ \
     15:   PetscInt  maxnz;                    /* allocated nonzeros */ \
     16:   PetscInt  *imax;                    /* maximum space allocated for each row */ \
     17:   PetscInt  *ilen;                    /* actual length of each row */ \
     18:   PetscBool free_imax_ilen;  \
     19:   PetscInt  reallocs;                 /* number of mallocs done during MatSetValues() \
     20:                                         as more values are set than were prealloced */\
     21:   PetscInt          rmax;             /* max nonzeros in any row */ \
     22:   PetscBool         keepnonzeropattern;   /* keeps matrix structure same in calls to MatZeroRows()*/ \
     23:   PetscBool         ignorezeroentries; \
     24:   PetscInt          *xtoy,*xtoyB;     /* map nonzero pattern of X into Y's, used by MatAXPY() */ \
     25:   Mat               XtoY;             /* used by MatAXPY() */ \
     26:   PetscBool         free_ij;          /* free the column indices j and row offsets i when the matrix is destroyed */ \
     27:   PetscBool         free_a;           /* free the numerical values when matrix is destroy */ \
     28:   Mat_CompressedRow compressedrow;    /* use compressed row format */                      \
     29:   PetscInt          nz;               /* nonzeros */                                       \
     30:   PetscInt          *i;               /* pointer to beginning of each row */               \
     31:   PetscInt          *j;               /* column values: j + i[k] - 1 is start of row k */  \
     32:   PetscInt          *diag;            /* pointers to diagonal elements */                  \
     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 */

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

     49: typedef struct {
     50:   PetscInt    *api,*apj;       /* symbolic structure of A*P */
     51:   PetscScalar *apa;            /* temporary array for storing one row of A*P */
     52:   PetscErrorCode (*destroy)(Mat);
     53: } Mat_PtAP;

     55: typedef struct {
     56:   MatTransposeColoring matcoloring;
     57:   Mat                  Rt;    /* dense matrix of R^T */
     58:   Mat                  RARt;  /* dense matrix of R*A*R^T */
     59:   MatScalar            *work; /* work array to store columns of A*R^T used in MatMatMatMultNumeric_SeqAIJ_SeqAIJ_SeqDense() */
     60:   PetscErrorCode (*destroy)(Mat);
     61: } Mat_RARt;

     63: typedef struct {
     64:   Mat BC;               /* temp matrix for storing B*C */
     65:   PetscErrorCode (*destroy)(Mat);
     66: } Mat_MatMatMatMult;

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

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

     81:   PetscBool use;
     82:   PetscInt  node_count;                     /* number of inodes */
     83:   PetscInt  *size;                          /* size of each inode */
     84:   PetscInt  limit;                          /* inode limit */
     85:   PetscInt  max_limit;                      /* maximum supported inode limit */
     86:   PetscBool checked;                        /* if inodes have been checked for */
     87: } Mat_SeqAIJ_Inode;

     89: PETSC_INTERN PetscErrorCode MatView_SeqAIJ_Inode(Mat,PetscViewer);
     90: PETSC_INTERN PetscErrorCode MatAssemblyEnd_SeqAIJ_Inode(Mat,MatAssemblyType);
     91: PETSC_INTERN PetscErrorCode MatDestroy_SeqAIJ_Inode(Mat);
     92: PETSC_INTERN PetscErrorCode MatCreate_SeqAIJ_Inode(Mat);
     93: PETSC_INTERN PetscErrorCode MatSetOption_SeqAIJ_Inode(Mat,MatOption,PetscBool);
     94: PETSC_INTERN PetscErrorCode MatDuplicate_SeqAIJ_Inode(Mat,MatDuplicateOption,Mat*);
     95: PETSC_INTERN PetscErrorCode MatDuplicateNoCreate_SeqAIJ(Mat,Mat,MatDuplicateOption,PetscBool);
     96: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_Inode_inplace(Mat,Mat,const MatFactorInfo*);
     97: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_Inode(Mat,Mat,const MatFactorInfo*);

     99: typedef struct {
    100:   SEQAIJHEADER(MatScalar);
    101:   Mat_SeqAIJ_Inode inode;
    102:   MatScalar        *saved_values;             /* location for stashing nonzero values of matrix */

    104:   PetscScalar *idiag,*mdiag,*ssor_work;       /* inverse of diagonal entries, diagonal values and workspace for Eisenstat trick */
    105:   PetscBool   idiagvalid;                     /* current idiag[] and mdiag[] are valid */
    106:   PetscScalar *ibdiag;                        /* inverses of block diagonals */
    107:   PetscBool   ibdiagvalid;                    /* inverses of block diagonals are valid. */
    108:   PetscScalar fshift,omega;                   /* last used omega and fshift */

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

    112:   PetscScalar       *matmult_abdense;    /* used by MatMatMult() */
    113:   Mat_PtAP          *ptap;               /* used by MatPtAP() */
    114:   Mat_MatMatMatMult *matmatmatmult;      /* used by MatMatMatMult() */
    115: } Mat_SeqAIJ;

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

    173: PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocation_SeqAIJ(Mat,PetscInt,const PetscInt*);
    174: PETSC_INTERN PetscErrorCode MatILUFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,IS,const MatFactorInfo*);
    175: PETSC_INTERN PetscErrorCode MatILUFactorSymbolic_SeqAIJ(Mat,Mat,IS,IS,const MatFactorInfo*);
    176: PETSC_INTERN PetscErrorCode MatILUFactorSymbolic_SeqAIJ_ilu0(Mat,Mat,IS,IS,const MatFactorInfo*);

    178: PETSC_INTERN PetscErrorCode MatICCFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,const MatFactorInfo*);
    179: PETSC_INTERN PetscErrorCode MatICCFactorSymbolic_SeqAIJ(Mat,Mat,IS,const MatFactorInfo*);
    180: PETSC_INTERN PetscErrorCode MatCholeskyFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,const MatFactorInfo*);
    181: PETSC_INTERN PetscErrorCode MatCholeskyFactorSymbolic_SeqAIJ(Mat,Mat,IS,const MatFactorInfo*);
    182: PETSC_INTERN PetscErrorCode MatCholeskyFactorNumeric_SeqAIJ_inplace(Mat,Mat,const MatFactorInfo*);
    183: PETSC_INTERN PetscErrorCode MatCholeskyFactorNumeric_SeqAIJ(Mat,Mat,const MatFactorInfo*);
    184: PETSC_INTERN PetscErrorCode MatDuplicate_SeqAIJ(Mat,MatDuplicateOption,Mat*);
    185: PETSC_INTERN PetscErrorCode MatCopy_SeqAIJ(Mat,Mat,MatStructure);
    186: PETSC_INTERN PetscErrorCode MatMissingDiagonal_SeqAIJ(Mat,PetscBool*,PetscInt*);
    187: PETSC_INTERN PetscErrorCode MatMarkDiagonal_SeqAIJ(Mat);
    188: PETSC_INTERN PetscErrorCode MatFindZeroDiagonals_SeqAIJ_Private(Mat,PetscInt*,PetscInt**);

    190: PETSC_INTERN PetscErrorCode MatMult_SeqAIJ(Mat A,Vec,Vec);
    191: PETSC_INTERN PetscErrorCode MatMultAdd_SeqAIJ(Mat A,Vec,Vec,Vec);
    192: PETSC_INTERN PetscErrorCode MatMultTranspose_SeqAIJ(Mat A,Vec,Vec);
    193: PETSC_INTERN PetscErrorCode MatMultTransposeAdd_SeqAIJ(Mat A,Vec,Vec,Vec);
    194: PETSC_INTERN PetscErrorCode MatSOR_SeqAIJ(Mat,Vec,PetscReal,MatSORType,PetscReal,PetscInt,PetscInt,Vec);

    196: PETSC_INTERN PetscErrorCode MatSetOption_SeqAIJ(Mat,MatOption,PetscBool);
    197: PETSC_INTERN PetscErrorCode MatSetColoring_SeqAIJ(Mat,ISColoring);
    198: PETSC_INTERN PetscErrorCode MatSetValuesAdifor_SeqAIJ(Mat,PetscInt,void*);

    200: PETSC_INTERN PetscErrorCode MatGetSymbolicTranspose_SeqAIJ(Mat,PetscInt *[],PetscInt *[]);
    201: PETSC_INTERN PetscErrorCode MatGetSymbolicTransposeReduced_SeqAIJ(Mat,PetscInt,PetscInt,PetscInt *[],PetscInt *[]);
    202: PETSC_INTERN PetscErrorCode MatRestoreSymbolicTranspose_SeqAIJ(Mat,PetscInt *[],PetscInt *[]);
    203: PETSC_INTERN PetscErrorCode MatTransposeSymbolic_SeqAIJ(Mat,Mat*);
    204: PETSC_INTERN PetscErrorCode MatToSymmetricIJ_SeqAIJ(PetscInt,PetscInt*,PetscInt*,PetscInt,PetscInt,PetscInt**,PetscInt**);
    205: PETSC_INTERN PetscErrorCode MatLUFactorSymbolic_SeqAIJ_inplace(Mat,Mat,IS,IS,const MatFactorInfo*);
    206: PETSC_INTERN PetscErrorCode MatLUFactorSymbolic_SeqAIJ(Mat,Mat,IS,IS,const MatFactorInfo*);
    207: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_inplace(Mat,Mat,const MatFactorInfo*);
    208: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ(Mat,Mat,const MatFactorInfo*);
    209: PETSC_INTERN PetscErrorCode MatLUFactorNumeric_SeqAIJ_InplaceWithPerm(Mat,Mat,const MatFactorInfo*);
    210: PETSC_INTERN PetscErrorCode MatLUFactor_SeqAIJ(Mat,IS,IS,const MatFactorInfo*);
    211: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_inplace(Mat,Vec,Vec);
    212: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ(Mat,Vec,Vec);
    213: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_Inode_inplace(Mat,Vec,Vec);
    214: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_Inode(Mat,Vec,Vec);
    215: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_NaturalOrdering_inplace(Mat,Vec,Vec);
    216: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_NaturalOrdering(Mat,Vec,Vec);
    217: PETSC_INTERN PetscErrorCode MatSolve_SeqAIJ_InplaceWithPerm(Mat,Vec,Vec);
    218: PETSC_INTERN PetscErrorCode MatSolveAdd_SeqAIJ_inplace(Mat,Vec,Vec,Vec);
    219: PETSC_INTERN PetscErrorCode MatSolveAdd_SeqAIJ(Mat,Vec,Vec,Vec);
    220: PETSC_INTERN PetscErrorCode MatSolveTranspose_SeqAIJ_inplace(Mat,Vec,Vec);
    221: PETSC_INTERN PetscErrorCode MatSolveTranspose_SeqAIJ(Mat,Vec,Vec);
    222: PETSC_INTERN PetscErrorCode MatSolveTransposeAdd_SeqAIJ_inplace(Mat,Vec,Vec,Vec);
    223: PETSC_INTERN PetscErrorCode MatSolveTransposeAdd_SeqAIJ(Mat,Vec,Vec,Vec);
    224: PETSC_INTERN PetscErrorCode MatMatSolve_SeqAIJ_inplace(Mat,Mat,Mat);
    225: PETSC_INTERN PetscErrorCode MatMatSolve_SeqAIJ(Mat,Mat,Mat);
    226: PETSC_INTERN PetscErrorCode MatEqual_SeqAIJ(Mat A,Mat B,PetscBool * flg);
    227: PETSC_INTERN PetscErrorCode MatFDColoringCreate_SeqAIJ(Mat,ISColoring,MatFDColoring);
    228: PETSC_INTERN PetscErrorCode MatLoad_SeqAIJ(Mat,PetscViewer);
    229: PETSC_INTERN PetscErrorCode RegisterApplyPtAPRoutines_Private(Mat);

    231: PETSC_INTERN PetscErrorCode MatMatMult_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
    232: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
    233: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_Scalable(Mat,Mat,PetscReal,Mat*);
    234: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_Scalable_fast(Mat,Mat,PetscReal,Mat*);
    235: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_Heap(Mat,Mat,PetscReal,Mat*);
    236: PETSC_INTERN PetscErrorCode MatMatMultSymbolic_SeqAIJ_SeqAIJ_BTHeap(Mat,Mat,PetscReal,Mat*);
    237: PETSC_INTERN PetscErrorCode MatMatMultNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
    238: PETSC_INTERN PetscErrorCode MatMatMultNumeric_SeqAIJ_SeqAIJ_Scalable(Mat,Mat,Mat);

    240: PETSC_INTERN PetscErrorCode MatPtAP_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
    241: PETSC_INTERN PetscErrorCode MatPtAPSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
    242: PETSC_INTERN PetscErrorCode MatPtAPSymbolic_SeqAIJ_SeqAIJ_SparseAxpy(Mat,Mat,PetscReal,Mat*);
    243: PETSC_INTERN PetscErrorCode MatPtAPNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
    244: PETSC_INTERN PetscErrorCode MatPtAPNumeric_SeqAIJ_SeqAIJ_SparseAxpy(Mat,Mat,Mat);

    246: PETSC_INTERN PetscErrorCode MatRARtSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
    247: PETSC_INTERN PetscErrorCode MatRARtNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);

    249: PETSC_INTERN PetscErrorCode MatTransposeMatMult_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
    250: PETSC_INTERN PetscErrorCode MatTransposeMatMultSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
    251: PETSC_INTERN PetscErrorCode MatTransposeMatMultNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
    252: PETSC_INTERN PetscErrorCode MatMatTransposeMult_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
    253: PETSC_INTERN PetscErrorCode MatMatTransposeMultSymbolic_SeqAIJ_SeqAIJ(Mat,Mat,PetscReal,Mat*);
    254: PETSC_INTERN PetscErrorCode MatMatTransposeMultNumeric_SeqAIJ_SeqAIJ(Mat,Mat,Mat);
    255: PETSC_INTERN PetscErrorCode MatTransposeColoringCreate_SeqAIJ(Mat,ISColoring,MatTransposeColoring);
    256: PETSC_INTERN PetscErrorCode MatTransColoringApplySpToDen_SeqAIJ(MatTransposeColoring,Mat,Mat);
    257: PETSC_INTERN PetscErrorCode MatTransColoringApplyDenToSp_SeqAIJ(MatTransposeColoring,Mat,Mat);

    259: PETSC_INTERN PetscErrorCode MatMatMatMult_SeqAIJ_SeqAIJ_SeqAIJ(Mat,Mat,Mat,MatReuse,PetscReal,Mat*);
    260: PETSC_INTERN PetscErrorCode MatMatMatMultSymbolic_SeqAIJ_SeqAIJ_SeqAIJ(Mat,Mat,Mat,PetscReal,Mat*);
    261: PETSC_INTERN PetscErrorCode MatMatMatMultNumeric_SeqAIJ_SeqAIJ_SeqAIJ(Mat,Mat,Mat,Mat);

    263: PETSC_INTERN PetscErrorCode MatSetValues_SeqAIJ(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[],const PetscScalar[],InsertMode);
    264: PETSC_INTERN PetscErrorCode MatGetRow_SeqAIJ(Mat,PetscInt,PetscInt*,PetscInt**,PetscScalar**);
    265: PETSC_INTERN PetscErrorCode MatRestoreRow_SeqAIJ(Mat,PetscInt,PetscInt*,PetscInt**,PetscScalar**);
    266: PETSC_INTERN PetscErrorCode MatAXPY_SeqAIJ(Mat,PetscScalar,Mat,MatStructure);
    267: PETSC_INTERN PetscErrorCode MatGetRowIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
    268: PETSC_INTERN PetscErrorCode MatRestoreRowIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
    269: PETSC_INTERN PetscErrorCode MatGetColumnIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
    270: PETSC_INTERN PetscErrorCode MatRestoreColumnIJ_SeqAIJ(Mat,PetscInt,PetscBool,PetscBool,PetscInt*,const PetscInt *[],const PetscInt *[],PetscBool*);
    271: PETSC_INTERN PetscErrorCode MatDestroy_SeqAIJ(Mat);
    272: PETSC_INTERN PetscErrorCode MatSetUp_SeqAIJ(Mat);
    273: PETSC_INTERN PetscErrorCode MatView_SeqAIJ(Mat,PetscViewer);

    275: PETSC_INTERN PetscErrorCode MatSeqAIJInvalidateDiagonal(Mat);
    276: PETSC_INTERN PetscErrorCode MatSeqAIJInvalidateDiagonal_Inode(Mat);
    277: PETSC_INTERN PetscErrorCode Mat_CheckInode(Mat,PetscBool);
    278: PETSC_INTERN PetscErrorCode Mat_CheckInode_FactorLU(Mat,PetscBool);

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

    282: PETSC_EXTERN PetscErrorCode MatConvert_SeqAIJ_SeqSBAIJ(Mat,MatType,MatReuse,Mat*);
    283: PETSC_EXTERN PetscErrorCode MatConvert_SeqAIJ_SeqBAIJ(Mat,MatType,MatReuse,Mat*);
    284: PETSC_EXTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJPERM(Mat,MatType,MatReuse,Mat*);
    285: PETSC_INTERN PetscErrorCode MatReorderForNonzeroDiagonal_SeqAIJ(Mat,PetscReal,IS,IS);
    286: PETSC_INTERN PetscErrorCode MatMatMult_SeqDense_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
    287: PETSC_INTERN PetscErrorCode MatRARt_SeqAIJ_SeqAIJ(Mat,Mat,MatReuse,PetscReal,Mat*);
    288: PETSC_EXTERN PetscErrorCode MatCreate_SeqAIJ(Mat);
    289: PETSC_INTERN PetscErrorCode MatAssemblyEnd_SeqAIJ(Mat,MatAssemblyType);
    290: PETSC_INTERN PetscErrorCode MatDestroy_SeqAIJ(Mat);

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

    296:   Input Parameters:
    297: +  nnz - the number of entries
    298: .  r - the array of vector values
    299: .  xv - the matrix values for the row
    300: -  xi - the column indices of the nonzeros in the row

    302:   Output Parameter:
    303: .  sum - negative the sum of results

    305:   PETSc compile flags:
    306: +   PETSC_KERNEL_USE_UNROLL_4 -   don't use this; it changes nnz and hence is WRONG
    307: -   PETSC_KERNEL_USE_UNROLL_2 -

    309: .seealso: PetscSparseDensePlusDot()

    311: */
    312: #if defined(PETSC_KERNEL_USE_UNROLL_4)
    313: #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) { \
    314:     if (nnz > 0) { \
    315:       switch (nnz & 0x3) { \
    316:       case 3: sum -= *xv++ *r[*xi++]; \
    317:       case 2: sum -= *xv++ *r[*xi++]; \
    318:       case 1: sum -= *xv++ *r[*xi++]; \
    319:         nnz       -= 4;} \
    320:       while (nnz > 0) { \
    321:         sum -=  xv[0] * r[xi[0]] - xv[1] * r[xi[1]] - \
    322:                xv[2] * r[xi[2]] - xv[3] * r[xi[3]]; \
    323:         xv += 4; xi += 4; nnz -= 4; }}}

    325: #elif defined(PETSC_KERNEL_USE_UNROLL_2)
    326: #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) { \
    327:     PetscInt __i,__i1,__i2; \
    328:     for (__i=0; __i<nnz-1; __i+=2) {__i1 = xi[__i]; __i2=xi[__i+1]; \
    329:                                     sum -= (xv[__i]*r[__i1] + xv[__i+1]*r[__i2]);} \
    330:     if (nnz & 0x1) sum -= xv[__i] * r[xi[__i]];}

    332: #else
    333: #define PetscSparseDenseMinusDot(sum,r,xv,xi,nnz) { \
    334:     PetscInt __i; \
    335:     for (__i=0; __i<nnz; __i++) sum -= xv[__i] * r[xi[__i]];}
    336: #endif

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

    343:   Input Parameters:
    344: +  nnz - the number of entries
    345: .  r - the array of vector values
    346: .  xv - the matrix values for the row
    347: -  xi - the column indices of the nonzeros in the row

    349:   Output Parameter:
    350: .  sum - the sum of results

    352:   PETSc compile flags:
    353: +   PETSC_KERNEL_USE_UNROLL_4 -  don't use this; it changes nnz and hence is WRONG
    354: -   PETSC_KERNEL_USE_UNROLL_2 -

    356: .seealso: PetscSparseDenseMinusDot()

    358: */
    359: #if defined(PETSC_KERNEL_USE_UNROLL_4)
    360: #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) { \
    361:     if (nnz > 0) { \
    362:       switch (nnz & 0x3) { \
    363:       case 3: sum += *xv++ *r[*xi++]; \
    364:       case 2: sum += *xv++ *r[*xi++]; \
    365:       case 1: sum += *xv++ *r[*xi++]; \
    366:         nnz       -= 4;} \
    367:       while (nnz > 0) { \
    368:         sum +=  xv[0] * r[xi[0]] + xv[1] * r[xi[1]] + \
    369:                xv[2] * r[xi[2]] + xv[3] * r[xi[3]]; \
    370:         xv += 4; xi += 4; nnz -= 4; }}}

    372: #elif defined(PETSC_KERNEL_USE_UNROLL_2)
    373: #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) { \
    374:     PetscInt __i,__i1,__i2; \
    375:     for (__i=0; __i<nnz-1; __i+=2) {__i1 = xi[__i]; __i2=xi[__i+1]; \
    376:                                     sum += (xv[__i]*r[__i1] + xv[__i+1]*r[__i2]);} \
    377:     if (nnz & 0x1) sum += xv[__i] * r[xi[__i]];}

    379: #else
    380: #define PetscSparseDensePlusDot(sum,r,xv,xi,nnz) { \
    381:     PetscInt __i; \
    382:     for (__i=0; __i<nnz; __i++) sum += xv[__i] * r[xi[__i]];}
    383: #endif

    385: #endif