xref: /petsc/src/mat/impls/aij/seq/inode2.c (revision 6a5217c03994f2d95bb2e6dbd8bed42381aeb015)
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   PetscErrorCode ierr;
59   PetscBool      no_inode,no_unroll;
60 
61   PetscFunctionBegin;
62   no_inode             = PETSC_FALSE;
63   no_unroll            = PETSC_FALSE;
64   b->inode.checked     = PETSC_FALSE;
65   b->inode.node_count  = 0;
66   b->inode.size        = NULL;
67   b->inode.limit       = 5;
68   b->inode.max_limit   = 5;
69   b->inode.ibdiagvalid = PETSC_FALSE;
70   b->inode.ibdiag      = NULL;
71   b->inode.bdiag       = NULL;
72 
73   ierr = PetscOptionsBegin(PetscObjectComm((PetscObject)B),((PetscObject)B)->prefix,"Options for SEQAIJ matrix","Mat");PetscCall(ierr);
74   PetscCall(PetscOptionsBool("-mat_no_unroll","Do not optimize for inodes (slower)",NULL,no_unroll,&no_unroll,NULL));
75   if (no_unroll) {
76     PetscCall(PetscInfo(B,"Not using Inode routines due to -mat_no_unroll\n"));
77   }
78   PetscCall(PetscOptionsBool("-mat_no_inode","Do not optimize for inodes -slower-",NULL,no_inode,&no_inode,NULL));
79   if (no_inode) {
80     PetscCall(PetscInfo(B,"Not using Inode routines due to -mat_no_inode\n"));
81   }
82   PetscCall(PetscOptionsInt("-mat_inode_limit","Do not use inodes larger then this value",NULL,b->inode.limit,&b->inode.limit,NULL));
83   ierr = PetscOptionsEnd();PetscCall(ierr);
84 
85   b->inode.use = (PetscBool)(!(no_unroll || no_inode));
86   if (b->inode.limit > b->inode.max_limit) b->inode.limit = b->inode.max_limit;
87 
88   PetscCall(PetscObjectComposeFunction((PetscObject)B,"MatInodeAdjustForInodes_C",MatInodeAdjustForInodes_SeqAIJ_Inode));
89   PetscCall(PetscObjectComposeFunction((PetscObject)B,"MatInodeGetInodeSizes_C",MatInodeGetInodeSizes_SeqAIJ_Inode));
90   PetscFunctionReturn(0);
91 }
92 
93 PetscErrorCode MatSetOption_SeqAIJ_Inode(Mat A,MatOption op,PetscBool flg)
94 {
95   Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data;
96 
97   PetscFunctionBegin;
98   switch (op) {
99   case MAT_USE_INODES:
100     a->inode.use = flg;
101     break;
102   default:
103     break;
104   }
105   PetscFunctionReturn(0);
106 }
107