xref: /petsc/src/mat/impls/aij/seq/inode2.c (revision 2205254efee3a00a594e5e2a3a70f74dcb40bc03)
17d0a6c19SBarry Smith 
2c6db04a5SJed Brown #include <../src/mat/impls/aij/seq/aij.h>
34c1414c8SBarry Smith 
409573ac7SBarry Smith extern PetscErrorCode Mat_CheckInode(Mat,PetscBool);
54c1414c8SBarry Smith EXTERN_C_BEGIN
67087cfbeSBarry Smith extern PetscErrorCode  MatInodeAdjustForInodes_SeqAIJ_Inode(Mat,IS*,IS*);
77087cfbeSBarry Smith extern PetscErrorCode  MatInodeGetInodeSizes_SeqAIJ_Inode(Mat,PetscInt*,PetscInt*[],PetscInt*);
84c1414c8SBarry Smith EXTERN_C_END
94c1414c8SBarry Smith 
104c1414c8SBarry Smith #undef __FUNCT__
114108e4d5SBarry Smith #define __FUNCT__ "MatView_SeqAIJ_Inode"
124108e4d5SBarry Smith PetscErrorCode MatView_SeqAIJ_Inode(Mat A,PetscViewer viewer)
134c1414c8SBarry Smith {
144c1414c8SBarry Smith   Mat_SeqAIJ        *a=(Mat_SeqAIJ*)A->data;
154c1414c8SBarry Smith   PetscErrorCode    ierr;
16ace3abfcSBarry Smith   PetscBool         iascii;
174c1414c8SBarry Smith   PetscViewerFormat format;
184c1414c8SBarry Smith 
194c1414c8SBarry Smith   PetscFunctionBegin;
20251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
214c1414c8SBarry Smith   if (iascii) {
224c1414c8SBarry Smith     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
234c1414c8SBarry Smith     if (format == PETSC_VIEWER_ASCII_INFO_DETAIL || format == PETSC_VIEWER_ASCII_INFO) {
244c1414c8SBarry Smith       if (a->inode.size) {
254c1414c8SBarry Smith         ierr = PetscViewerASCIIPrintf(viewer,"using I-node routines: found %D nodes, limit used is %D\n",
264c1414c8SBarry Smith                                       a->inode.node_count,a->inode.limit);CHKERRQ(ierr);
274c1414c8SBarry Smith       } else {
284c1414c8SBarry Smith         ierr = PetscViewerASCIIPrintf(viewer,"not using I-node routines\n");CHKERRQ(ierr);
294c1414c8SBarry Smith       }
304c1414c8SBarry Smith     }
314c1414c8SBarry Smith   }
324c1414c8SBarry Smith   PetscFunctionReturn(0);
334c1414c8SBarry Smith }
344c1414c8SBarry Smith 
354c1414c8SBarry Smith #undef __FUNCT__
364108e4d5SBarry Smith #define __FUNCT__ "MatAssemblyEnd_SeqAIJ_Inode"
374108e4d5SBarry Smith PetscErrorCode MatAssemblyEnd_SeqAIJ_Inode(Mat A, MatAssemblyType mode)
384c1414c8SBarry Smith {
3971f1c65dSBarry Smith   Mat_SeqAIJ     *a = (Mat_SeqAIJ*)A->data;
404c1414c8SBarry Smith   PetscErrorCode ierr;
41ace3abfcSBarry Smith   PetscBool      samestructure;
424c1414c8SBarry Smith 
434c1414c8SBarry Smith   PetscFunctionBegin;
444c1414c8SBarry Smith   /* info.nz_unneeded of zero denotes no structural change was made to the matrix during Assembly */
45ace3abfcSBarry Smith   samestructure = (PetscBool)(!A->info.nz_unneeded);
464c1414c8SBarry Smith   /* check for identical nodes. If found, use inode functions */
474c1414c8SBarry Smith   ierr = Mat_CheckInode(A,samestructure);CHKERRQ(ierr);
48*2205254eSKarl Rupp 
4971f1c65dSBarry Smith   a->inode.ibdiagvalid = PETSC_FALSE;
504c1414c8SBarry Smith   PetscFunctionReturn(0);
514c1414c8SBarry Smith }
524c1414c8SBarry Smith 
534c1414c8SBarry Smith #undef __FUNCT__
544108e4d5SBarry Smith #define __FUNCT__ "MatDestroy_SeqAIJ_Inode"
554108e4d5SBarry Smith PetscErrorCode MatDestroy_SeqAIJ_Inode(Mat A)
564c1414c8SBarry Smith {
574c1414c8SBarry Smith   PetscErrorCode ierr;
584c1414c8SBarry Smith   Mat_SeqAIJ     *a=(Mat_SeqAIJ*)A->data;
594c1414c8SBarry Smith 
604c1414c8SBarry Smith   PetscFunctionBegin;
614c1414c8SBarry Smith   ierr = PetscFree(a->inode.size);CHKERRQ(ierr);
6289c6957cSBarry Smith   ierr = PetscFree3(a->inode.ibdiag,a->inode.bdiag,a->inode.ssor_work);CHKERRQ(ierr);
634c1414c8SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatInodeAdjustForInodes_C","",PETSC_NULL);CHKERRQ(ierr);
644c1414c8SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatInodeGetInodeSizes_C","",PETSC_NULL);CHKERRQ(ierr);
654c1414c8SBarry Smith   PetscFunctionReturn(0);
664c1414c8SBarry Smith }
674c1414c8SBarry Smith 
684108e4d5SBarry Smith /* MatCreate_SeqAIJ_Inode is not DLLEXPORTed because it is not a constructor for a complete type.    */
694c1414c8SBarry Smith /* It is also not registered as a type for use within MatSetType.                             */
704c1414c8SBarry Smith /* It is intended as a helper for the MATSEQAIJ class, so classes which desire Inodes should  */
714c1414c8SBarry Smith /*    inherit off of MATSEQAIJ instead by calling MatSetType(MATSEQAIJ) in their constructor. */
724c1414c8SBarry Smith /* Maybe this is a bad idea. (?) */
734c1414c8SBarry Smith #undef __FUNCT__
744108e4d5SBarry Smith #define __FUNCT__ "MatCreate_SeqAIJ_Inode"
754108e4d5SBarry Smith PetscErrorCode MatCreate_SeqAIJ_Inode(Mat B)
764c1414c8SBarry Smith {
774c1414c8SBarry Smith   Mat_SeqAIJ     *b=(Mat_SeqAIJ*)B->data;
784c1414c8SBarry Smith   PetscErrorCode ierr;
79ace3abfcSBarry Smith   PetscBool      no_inode,no_unroll;
804c1414c8SBarry Smith 
814c1414c8SBarry Smith   PetscFunctionBegin;
82da9f3051SSatish Balay   no_inode             = PETSC_FALSE;
83da9f3051SSatish Balay   no_unroll            = PETSC_FALSE;
844c1414c8SBarry Smith   b->inode.node_count  = 0;
854c1414c8SBarry Smith   b->inode.size        = 0;
864c1414c8SBarry Smith   b->inode.limit       = 5;
874c1414c8SBarry Smith   b->inode.max_limit   = 5;
8871f1c65dSBarry Smith   b->inode.ibdiagvalid = PETSC_FALSE;
8971f1c65dSBarry Smith   b->inode.ibdiag      = 0;
9071f1c65dSBarry Smith   b->inode.bdiag       = 0;
914c1414c8SBarry Smith 
927adad957SLisandro Dalcin   ierr = PetscOptionsBegin(((PetscObject)B)->comm,((PetscObject)B)->prefix,"Options for SEQAIJ matrix","Mat");CHKERRQ(ierr);
93acfcf0e5SJed Brown   ierr = PetscOptionsBool("-mat_no_unroll","Do not optimize for inodes (slower)",PETSC_NULL,no_unroll,&no_unroll,PETSC_NULL);CHKERRQ(ierr);
94*2205254eSKarl Rupp   if (no_unroll) {
95*2205254eSKarl Rupp     ierr = PetscInfo(B,"Not using Inode routines due to -mat_no_unroll\n");CHKERRQ(ierr);
96*2205254eSKarl Rupp   }
97acfcf0e5SJed Brown   ierr = PetscOptionsBool("-mat_no_inode","Do not optimize for inodes -slower-",PETSC_NULL,no_inode,&no_inode,PETSC_NULL);CHKERRQ(ierr);
98*2205254eSKarl Rupp   if (no_inode) {
99*2205254eSKarl Rupp     ierr = PetscInfo(B,"Not using Inode routines due to -mat_no_inode\n");CHKERRQ(ierr);
100*2205254eSKarl Rupp   }
101d74fe821SBarry Smith   ierr = PetscOptionsInt("-mat_inode_limit","Do not use inodes larger then this value",PETSC_NULL,b->inode.limit,&b->inode.limit,PETSC_NULL);CHKERRQ(ierr);
102d74fe821SBarry Smith   ierr = PetscOptionsEnd();CHKERRQ(ierr);
103ace3abfcSBarry Smith   b->inode.use = (PetscBool)(!(no_unroll || no_inode));
104d74fe821SBarry Smith   if (b->inode.limit > b->inode.max_limit) b->inode.limit = b->inode.max_limit;
105d74fe821SBarry Smith 
1064c1414c8SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatInodeAdjustForInodes_C",
1074108e4d5SBarry Smith                                            "MatInodeAdjustForInodes_SeqAIJ_Inode",
1084108e4d5SBarry Smith                                            MatInodeAdjustForInodes_SeqAIJ_Inode);CHKERRQ(ierr);
1094c1414c8SBarry Smith   ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatInodeGetInodeSizes_C",
1104108e4d5SBarry Smith                                            "MatInodeGetInodeSizes_SeqAIJ_Inode",
1114108e4d5SBarry Smith                                            MatInodeGetInodeSizes_SeqAIJ_Inode);CHKERRQ(ierr);
1124c1414c8SBarry Smith   PetscFunctionReturn(0);
1134c1414c8SBarry Smith }
1144c1414c8SBarry Smith 
1154c1414c8SBarry Smith #undef __FUNCT__
1164108e4d5SBarry Smith #define __FUNCT__ "MatSetOption_SeqAIJ_Inode"
117ace3abfcSBarry Smith PetscErrorCode MatSetOption_SeqAIJ_Inode(Mat A,MatOption op,PetscBool flg)
1184c1414c8SBarry Smith {
1194c1414c8SBarry Smith   Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data;
120d74fe821SBarry Smith 
1214c1414c8SBarry Smith   PetscFunctionBegin;
1224c1414c8SBarry Smith   switch (op) {
1234c1414c8SBarry Smith   case MAT_USE_INODES:
1244e0d8c25SBarry Smith     a->inode.use = flg;
1254c1414c8SBarry Smith     break;
1264c1414c8SBarry Smith   default:
1274c1414c8SBarry Smith     break;
1284c1414c8SBarry Smith   }
1294c1414c8SBarry Smith   PetscFunctionReturn(0);
1304c1414c8SBarry Smith }
1314c1414c8SBarry Smith 
1324c1414c8SBarry Smith 
1334c1414c8SBarry Smith 
1344c1414c8SBarry Smith 
1354c1414c8SBarry Smith 
136