1 2 #include <../src/mat/impls/aij/seq/aij.h> 3 4 extern PetscErrorCode MatInodeAdjustForInodes_SeqAIJ_Inode(Mat, IS *, IS *); 5 extern PetscErrorCode MatInodeGetInodeSizes_SeqAIJ_Inode(Mat, PetscInt *, PetscInt *[], PetscInt *); 6 7 PetscErrorCode MatView_SeqAIJ_Inode(Mat A, PetscViewer viewer) 8 { 9 Mat_SeqAIJ *a = (Mat_SeqAIJ *)A->data; 10 PetscBool iascii; 11 PetscViewerFormat format; 12 13 PetscFunctionBegin; 14 PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &iascii)); 15 if (iascii) { 16 PetscCall(PetscViewerGetFormat(viewer, &format)); 17 if (format == PETSC_VIEWER_ASCII_INFO_DETAIL || format == PETSC_VIEWER_ASCII_INFO) { 18 if (a->inode.size) { 19 PetscCall(PetscViewerASCIIPrintf(viewer, "using I-node routines: found %" PetscInt_FMT " nodes, limit used is %" PetscInt_FMT "\n", a->inode.node_count, a->inode.limit)); 20 } else { 21 PetscCall(PetscViewerASCIIPrintf(viewer, "not using I-node routines\n")); 22 } 23 } 24 } 25 PetscFunctionReturn(0); 26 } 27 28 PetscErrorCode MatAssemblyEnd_SeqAIJ_Inode(Mat A, MatAssemblyType mode) 29 { 30 Mat_SeqAIJ *a = (Mat_SeqAIJ *)A->data; 31 32 PetscFunctionBegin; 33 PetscCall(MatSeqAIJCheckInode(A)); 34 a->inode.ibdiagvalid = PETSC_FALSE; 35 PetscFunctionReturn(0); 36 } 37 38 PetscErrorCode MatDestroy_SeqAIJ_Inode(Mat A) 39 { 40 Mat_SeqAIJ *a = (Mat_SeqAIJ *)A->data; 41 42 PetscFunctionBegin; 43 PetscCall(PetscFree(a->inode.size)); 44 PetscCall(PetscFree3(a->inode.ibdiag, a->inode.bdiag, a->inode.ssor_work)); 45 PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatInodeAdjustForInodes_C", NULL)); 46 PetscCall(PetscObjectComposeFunction((PetscObject)A, "MatInodeGetInodeSizes_C", NULL)); 47 PetscFunctionReturn(0); 48 } 49 50 /* MatCreate_SeqAIJ_Inode is not DLLEXPORTed because it is not a constructor for a complete type. */ 51 /* It is also not registered as a type for use within MatSetType. */ 52 /* It is intended as a helper for the MATSEQAIJ class, so classes which desire Inodes should */ 53 /* inherit off of MATSEQAIJ instead by calling MatSetType(MATSEQAIJ) in their constructor. */ 54 /* Maybe this is a bad idea. (?) */ 55 PetscErrorCode MatCreate_SeqAIJ_Inode(Mat B) 56 { 57 Mat_SeqAIJ *b = (Mat_SeqAIJ *)B->data; 58 PetscBool no_inode, no_unroll; 59 60 PetscFunctionBegin; 61 no_inode = PETSC_FALSE; 62 no_unroll = PETSC_FALSE; 63 b->inode.checked = PETSC_FALSE; 64 b->inode.node_count = 0; 65 b->inode.size = NULL; 66 b->inode.limit = 5; 67 b->inode.max_limit = 5; 68 b->inode.ibdiagvalid = PETSC_FALSE; 69 b->inode.ibdiag = NULL; 70 b->inode.bdiag = NULL; 71 72 PetscOptionsBegin(PetscObjectComm((PetscObject)B), ((PetscObject)B)->prefix, "Options for SEQAIJ matrix", "Mat"); 73 PetscCall(PetscOptionsBool("-mat_no_unroll", "Do not optimize for inodes (slower)", NULL, no_unroll, &no_unroll, NULL)); 74 if (no_unroll) PetscCall(PetscInfo(B, "Not using Inode routines due to -mat_no_unroll\n")); 75 PetscCall(PetscOptionsBool("-mat_no_inode", "Do not optimize for inodes -slower-", NULL, no_inode, &no_inode, NULL)); 76 if (no_inode) PetscCall(PetscInfo(B, "Not using Inode routines due to -mat_no_inode\n")); 77 PetscCall(PetscOptionsInt("-mat_inode_limit", "Do not use inodes larger then this value", NULL, b->inode.limit, &b->inode.limit, NULL)); 78 PetscOptionsEnd(); 79 80 b->inode.use = (PetscBool)(!(no_unroll || no_inode)); 81 if (b->inode.limit > b->inode.max_limit) b->inode.limit = b->inode.max_limit; 82 83 PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatInodeAdjustForInodes_C", MatInodeAdjustForInodes_SeqAIJ_Inode)); 84 PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatInodeGetInodeSizes_C", MatInodeGetInodeSizes_SeqAIJ_Inode)); 85 PetscFunctionReturn(0); 86 } 87 88 PetscErrorCode MatSetOption_SeqAIJ_Inode(Mat A, MatOption op, PetscBool flg) 89 { 90 Mat_SeqAIJ *a = (Mat_SeqAIJ *)A->data; 91 92 PetscFunctionBegin; 93 switch (op) { 94 case MAT_USE_INODES: 95 a->inode.use = flg; 96 break; 97 default: 98 break; 99 } 100 PetscFunctionReturn(0); 101 } 102