xref: /petsc/src/mat/impls/aij/seq/inode2.c (revision 17667f9060a8aad9ce8a34f74735d38d2a7e6242)
1 #define PETSCMAT_DLL
2 #include "src/mat/impls/aij/seq/aij.h"
3 
4 EXTERN PetscErrorCode Mat_CheckInode(Mat,PetscTruth);
5 EXTERN_C_BEGIN
6 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT MatInodeAdjustForInodes_Inode(Mat,IS*,IS*);
7 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT MatInodeGetInodeSizes_Inode(Mat,PetscInt*,PetscInt*[],PetscInt*);
8 EXTERN_C_END
9 
10 #undef __FUNCT__
11 #define __FUNCT__ "MatView_Inode"
12 PetscErrorCode MatView_Inode(Mat A,PetscViewer viewer)
13 {
14   Mat_SeqAIJ         *a=(Mat_SeqAIJ*)A->data;
15   PetscErrorCode    ierr;
16   PetscTruth        iascii;
17   PetscViewerFormat format;
18 
19   PetscFunctionBegin;
20   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr);
21   if (iascii) {
22     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
23     if (format == PETSC_VIEWER_ASCII_INFO_DETAIL || format == PETSC_VIEWER_ASCII_INFO) {
24       if (a->inode.size) {
25         ierr = PetscViewerASCIIPrintf(viewer,"using I-node routines: found %D nodes, limit used is %D\n",
26                                       a->inode.node_count,a->inode.limit);CHKERRQ(ierr);
27       } else {
28         ierr = PetscViewerASCIIPrintf(viewer,"not using I-node routines\n");CHKERRQ(ierr);
29       }
30     }
31   }
32   PetscFunctionReturn(0);
33 }
34 
35 #undef __FUNCT__
36 #define __FUNCT__ "MatAssemblyEnd_Inode"
37 PetscErrorCode MatAssemblyEnd_Inode(Mat A, MatAssemblyType mode)
38 {
39   PetscErrorCode ierr;
40   PetscTruth     samestructure;
41 
42   PetscFunctionBegin;
43   /* info.nz_unneeded of zero denotes no structural change was made to the matrix during Assembly */
44   samestructure = (PetscTruth)(!A->info.nz_unneeded);
45   /* check for identical nodes. If found, use inode functions */
46   ierr = Mat_CheckInode(A,samestructure);CHKERRQ(ierr);
47   PetscFunctionReturn(0);
48 }
49 
50 #undef __FUNCT__
51 #define __FUNCT__ "MatDestroy_Inode"
52 PetscErrorCode MatDestroy_Inode(Mat A)
53 {
54   PetscErrorCode ierr;
55   Mat_SeqAIJ      *a=(Mat_SeqAIJ*)A->data;
56 
57   PetscFunctionBegin;
58   ierr = PetscFree(a->inode.size);CHKERRQ(ierr);
59   ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatInodeAdjustForInodes_C","",PETSC_NULL);CHKERRQ(ierr);
60   ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatInodeGetInodeSizes_C","",PETSC_NULL);CHKERRQ(ierr);
61   PetscFunctionReturn(0);
62 }
63 
64 /* MatCreate_Inode is not DLLEXPORTed because it is not a constructor for a complete type.    */
65 /* It is also not registered as a type for use within MatSetType.                             */
66 /* It is intended as a helper for the MATSEQAIJ class, so classes which desire Inodes should  */
67 /*    inherit off of MATSEQAIJ instead by calling MatSetType(MATSEQAIJ) in their constructor. */
68 /* Maybe this is a bad idea. (?) */
69 #undef __FUNCT__
70 #define __FUNCT__ "MatCreate_Inode"
71 PetscErrorCode MatCreate_Inode(Mat B)
72 {
73   Mat_SeqAIJ     *b=(Mat_SeqAIJ*)B->data;
74   PetscErrorCode ierr;
75 
76   PetscFunctionBegin;
77   b->inode.use         = PETSC_TRUE;
78   b->inode.node_count  = 0;
79   b->inode.size        = 0;
80   b->inode.limit       = 5;
81   b->inode.max_limit   = 5;
82 
83   ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatInodeAdjustForInodes_C",
84                                      "MatInodeAdjustForInodes_Inode",
85                                       MatInodeAdjustForInodes_Inode);CHKERRQ(ierr);
86   ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatInodeGetInodeSizes_C",
87                                      "MatInodeGetInodeSizes_Inode",
88                                       MatInodeGetInodeSizes_Inode);CHKERRQ(ierr);
89   PetscFunctionReturn(0);
90 }
91 
92 #undef __FUNCT__
93 #define __FUNCT__ "MatSetOption_Inode"
94 PetscErrorCode MatSetOption_Inode(Mat A,MatOption op)
95 {
96   Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data;
97   PetscFunctionBegin;
98   switch(op) {
99     case MAT_USE_INODES:
100       a->inode.use         = PETSC_TRUE;
101       break;
102     case MAT_DO_NOT_USE_INODES:
103       a->inode.use         = PETSC_FALSE;
104       break;
105     case MAT_INODE_LIMIT_1:
106       a->inode.limit  = 1;
107       break;
108     case MAT_INODE_LIMIT_2:
109       a->inode.limit  = 2;
110       break;
111     case MAT_INODE_LIMIT_3:
112       a->inode.limit  = 3;
113       break;
114     case MAT_INODE_LIMIT_4:
115       a->inode.limit  = 4;
116       break;
117     case MAT_INODE_LIMIT_5:
118       a->inode.limit  = 5;
119       break;
120     default:
121       break;
122   }
123   PetscFunctionReturn(0);
124 }
125 
126 #undef __FUNCT__
127 #define __FUNCT__ "MatDuplicate_Inode"
128 PetscErrorCode MatDuplicate_Inode(Mat A,MatDuplicateOption cpvalues,Mat *C)
129 {
130   Mat            B=*C;
131   Mat_SeqAIJ      *c=(Mat_SeqAIJ*)B->data,*a=(Mat_SeqAIJ*)A->data;
132   PetscErrorCode ierr;
133   PetscInt       m=A->rmap.n;
134 
135   PetscFunctionBegin;
136 
137   c->inode.use          = a->inode.use;
138   c->inode.limit        = a->inode.limit;
139   c->inode.max_limit    = a->inode.max_limit;
140   if (a->inode.size){
141     ierr                = PetscMalloc((m+1)*sizeof(PetscInt),&c->inode.size);CHKERRQ(ierr);
142     c->inode.node_count = a->inode.node_count;
143     ierr                = PetscMemcpy(c->inode.size,a->inode.size,(m+1)*sizeof(PetscInt));CHKERRQ(ierr);
144   } else {
145     c->inode.size       = 0;
146     c->inode.node_count = 0;
147   }
148   PetscFunctionReturn(0);
149 }
150 
151 #undef __FUNCT__
152 #define __FUNCT__ "MatILUDTFactor_Inode"
153 PetscErrorCode MatILUDTFactor_Inode(Mat A,IS isrow,IS iscol,MatFactorInfo *info,Mat *fact)
154 {
155   PetscErrorCode ierr;
156 
157   PetscFunctionBegin;
158     /* check for identical nodes. If found, use inode functions */
159   ierr = Mat_CheckInode(*fact,PETSC_FALSE);CHKERRQ(ierr);
160   PetscFunctionReturn(0);
161 }
162 
163 #undef __FUNCT__
164 #define __FUNCT__ "MatLUFactorSymbolic_Inode"
165 PetscErrorCode MatLUFactorSymbolic_Inode(Mat A,IS isrow,IS iscol,MatFactorInfo *info,Mat *fact)
166 {
167   PetscErrorCode ierr;
168 
169   PetscFunctionBegin;
170     /* check for identical nodes. If found, use inode functions */
171   ierr = Mat_CheckInode(*fact,PETSC_FALSE);CHKERRQ(ierr);
172   PetscFunctionReturn(0);
173 }
174 
175 #undef __FUNCT__
176 #define __FUNCT__ "MatILUFactorSymbolic_Inode"
177 PetscErrorCode MatILUFactorSymbolic_Inode(Mat A,IS isrow,IS iscol,MatFactorInfo *info,Mat *fact)
178 {
179   PetscErrorCode ierr;
180 
181   PetscFunctionBegin;
182     /* check for identical nodes. If found, use inode functions */
183   ierr = Mat_CheckInode(*fact,PETSC_FALSE);CHKERRQ(ierr);
184   PetscFunctionReturn(0);
185 }
186 
187 
188