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