2: #include <petsc-private/matimpl.h> /*I "petscmat.h" I*/
6: /*@C
7: MatCheckCompressedRow - Determines whether the compressed row matrix format should be used.
8: If the format is to be used, this routine creates Mat_CompressedRow struct.
9: Compressed row format provides high performance routines by taking advantage of zero rows.
10: Supported types are MATAIJ, MATBAIJ and MATSBAIJ.
12: Collective
14: Input Parameters:
15: + A - the matrix
16: . nrows - number of rows with nonzero entries
17: . compressedrow - pointer to the struct Mat_CompressedRow
18: . ai - row pointer used by seqaij and seqbaij
19: . mbs - number of (block) rows represented by ai
20: - ratio - ratio of (num of zero rows)/m, used to determine if the compressed row format should be used
22: Notes: By default PETSc will not check for compressed rows on sequential matrices. Call MatSetOption(Mat,MAT_CHECK_COMPRESSED_ROW,PETSC_TRUE); before
23: MatAssemblyBegin() to have it check.
25: Developer Note: The reason this takes the compressedrow, ai and mbs arguments is because it is called by both the SeqAIJ and SEQBAIJ matrices and
26: the values are not therefore obtained by directly taking the values from the matrix object.
27: This is not a general public routine and hence is not listed in petscmat.h (it exposes a private data structure) but it is used
28: by some preconditioners and hence is labeled as PETSC_EXTERN
30: Level: developer
31: @*/
32: PETSC_EXTERN PetscErrorCodeMatCheckCompressedRow(Mat A,PetscInt nrows,Mat_CompressedRow *compressedrow,PetscInt *ai,PetscInt mbs,PetscReal ratio) 33: {
35: PetscInt *cpi=NULL,*ridx=NULL,nz,i,row;
38: /* in case this is being reused, delete old space */
39: PetscFree2(compressedrow->i,compressedrow->rindex);
41: compressedrow->i = NULL;
42: compressedrow->rindex = NULL;
45: /* compute number of zero rows */
46: nrows = mbs - nrows;
48: /* if a large number of zero rows is found, use compressedrow data structure */
49: if (nrows < ratio*mbs) {
50: compressedrow->use = PETSC_FALSE;
52: PetscInfo3(A,"Found the ratio (num_zerorows %d)/(num_localrows %d) < %g. Do not use CompressedRow routines.\n",nrows,mbs,(double)ratio);
53: } else {
54: compressedrow->use = PETSC_TRUE;
56: PetscInfo3(A,"Found the ratio (num_zerorows %d)/(num_localrows %d) > %g. Use CompressedRow routines.\n",nrows,mbs,(double)ratio);
58: /* set compressed row format */
59: nrows = mbs - nrows; /* num of non-zero rows */
60: PetscMalloc2(nrows+1,&cpi,nrows,&ridx);
61: row = 0;
62: cpi[0] = 0;
63: for (i=0; i<mbs; i++) {
64: nz = ai[i+1] - ai[i];
65: if (nz == 0) continue;
66: cpi[row+1] = ai[i+1]; /* compressed row pointer */
67: ridx[row++] = i; /* compressed row local index */
68: }
69: compressedrow->nrows = nrows;
70: compressedrow->i = cpi;
71: compressedrow->rindex = ridx;
72: }
73: return(0);
74: }