xref: /petsc/src/mat/impls/aij/seq/inode2.c (revision ec710b6acee97ecb7c6d9b176ebf365d3891e033)
17d0a6c19SBarry Smith 
2c6db04a5SJed Brown #include <../src/mat/impls/aij/seq/aij.h>
34c1414c8SBarry Smith 
47087cfbeSBarry Smith extern PetscErrorCode MatInodeAdjustForInodes_SeqAIJ_Inode(Mat,IS*,IS*);
57087cfbeSBarry Smith extern PetscErrorCode MatInodeGetInodeSizes_SeqAIJ_Inode(Mat,PetscInt*,PetscInt*[],PetscInt*);
64c1414c8SBarry Smith 
74108e4d5SBarry Smith PetscErrorCode MatView_SeqAIJ_Inode(Mat A,PetscViewer viewer)
84c1414c8SBarry Smith {
94c1414c8SBarry Smith   Mat_SeqAIJ        *a=(Mat_SeqAIJ*)A->data;
104c1414c8SBarry Smith   PetscErrorCode    ierr;
11ace3abfcSBarry Smith   PetscBool         iascii;
124c1414c8SBarry Smith   PetscViewerFormat format;
134c1414c8SBarry Smith 
144c1414c8SBarry Smith   PetscFunctionBegin;
15251f4c67SDmitry Karpeev   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
164c1414c8SBarry Smith   if (iascii) {
174c1414c8SBarry Smith     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
184c1414c8SBarry Smith     if (format == PETSC_VIEWER_ASCII_INFO_DETAIL || format == PETSC_VIEWER_ASCII_INFO) {
194c1414c8SBarry Smith       if (a->inode.size) {
20b9c12af5SBarry Smith         ierr = PetscViewerASCIIPrintf(viewer,"using I-node routines: found %D nodes, limit used is %D\n",a->inode.node_count,a->inode.limit);CHKERRQ(ierr);
214c1414c8SBarry Smith       } else {
224c1414c8SBarry Smith         ierr = PetscViewerASCIIPrintf(viewer,"not using I-node routines\n");CHKERRQ(ierr);
234c1414c8SBarry Smith       }
244c1414c8SBarry Smith     }
254c1414c8SBarry Smith   }
264c1414c8SBarry Smith   PetscFunctionReturn(0);
274c1414c8SBarry Smith }
284c1414c8SBarry Smith 
294108e4d5SBarry Smith PetscErrorCode MatAssemblyEnd_SeqAIJ_Inode(Mat A, MatAssemblyType mode)
304c1414c8SBarry Smith {
3171f1c65dSBarry Smith   Mat_SeqAIJ     *a = (Mat_SeqAIJ*)A->data;
324c1414c8SBarry Smith   PetscErrorCode ierr;
334c1414c8SBarry Smith 
344c1414c8SBarry Smith   PetscFunctionBegin;
35a02bda8eSBarry Smith   ierr = MatSeqAIJCheckInode(A);CHKERRQ(ierr);
3671f1c65dSBarry Smith   a->inode.ibdiagvalid = PETSC_FALSE;
374c1414c8SBarry Smith   PetscFunctionReturn(0);
384c1414c8SBarry Smith }
394c1414c8SBarry Smith 
404108e4d5SBarry Smith PetscErrorCode MatDestroy_SeqAIJ_Inode(Mat A)
414c1414c8SBarry Smith {
424c1414c8SBarry Smith   PetscErrorCode ierr;
434c1414c8SBarry Smith   Mat_SeqAIJ     *a=(Mat_SeqAIJ*)A->data;
444c1414c8SBarry Smith 
454c1414c8SBarry Smith   PetscFunctionBegin;
464c1414c8SBarry Smith   ierr = PetscFree(a->inode.size);CHKERRQ(ierr);
4789c6957cSBarry Smith   ierr = PetscFree3(a->inode.ibdiag,a->inode.bdiag,a->inode.ssor_work);CHKERRQ(ierr);
48bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)A,"MatInodeAdjustForInodes_C",NULL);CHKERRQ(ierr);
49bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)A,"MatInodeGetInodeSizes_C",NULL);CHKERRQ(ierr);
504c1414c8SBarry Smith   PetscFunctionReturn(0);
514c1414c8SBarry Smith }
524c1414c8SBarry Smith 
534108e4d5SBarry Smith /* MatCreate_SeqAIJ_Inode is not DLLEXPORTed because it is not a constructor for a complete type.    */
544c1414c8SBarry Smith /* It is also not registered as a type for use within MatSetType.                             */
554c1414c8SBarry Smith /* It is intended as a helper for the MATSEQAIJ class, so classes which desire Inodes should  */
564c1414c8SBarry Smith /*    inherit off of MATSEQAIJ instead by calling MatSetType(MATSEQAIJ) in their constructor. */
574c1414c8SBarry Smith /* Maybe this is a bad idea. (?) */
584108e4d5SBarry Smith PetscErrorCode MatCreate_SeqAIJ_Inode(Mat B)
594c1414c8SBarry Smith {
604c1414c8SBarry Smith   Mat_SeqAIJ     *b=(Mat_SeqAIJ*)B->data;
614c1414c8SBarry Smith   PetscErrorCode ierr;
62ace3abfcSBarry Smith   PetscBool      no_inode,no_unroll;
634c1414c8SBarry Smith 
644c1414c8SBarry Smith   PetscFunctionBegin;
65da9f3051SSatish Balay   no_inode             = PETSC_FALSE;
66da9f3051SSatish Balay   no_unroll            = PETSC_FALSE;
67*ec710b6aSStefano Zampini   b->inode.checked     = PETSC_FALSE;
684c1414c8SBarry Smith   b->inode.node_count  = 0;
69f4259b30SLisandro Dalcin   b->inode.size        = NULL;
704c1414c8SBarry Smith   b->inode.limit       = 5;
714c1414c8SBarry Smith   b->inode.max_limit   = 5;
7271f1c65dSBarry Smith   b->inode.ibdiagvalid = PETSC_FALSE;
73f4259b30SLisandro Dalcin   b->inode.ibdiag      = NULL;
74f4259b30SLisandro Dalcin   b->inode.bdiag       = NULL;
754c1414c8SBarry Smith 
76ce94432eSBarry Smith   ierr = PetscOptionsBegin(PetscObjectComm((PetscObject)B),((PetscObject)B)->prefix,"Options for SEQAIJ matrix","Mat");CHKERRQ(ierr);
770298fd71SBarry Smith   ierr = PetscOptionsBool("-mat_no_unroll","Do not optimize for inodes (slower)",NULL,no_unroll,&no_unroll,NULL);CHKERRQ(ierr);
782205254eSKarl Rupp   if (no_unroll) {
792205254eSKarl Rupp     ierr = PetscInfo(B,"Not using Inode routines due to -mat_no_unroll\n");CHKERRQ(ierr);
802205254eSKarl Rupp   }
810298fd71SBarry Smith   ierr = PetscOptionsBool("-mat_no_inode","Do not optimize for inodes -slower-",NULL,no_inode,&no_inode,NULL);CHKERRQ(ierr);
822205254eSKarl Rupp   if (no_inode) {
832205254eSKarl Rupp     ierr = PetscInfo(B,"Not using Inode routines due to -mat_no_inode\n");CHKERRQ(ierr);
842205254eSKarl Rupp   }
850298fd71SBarry Smith   ierr = PetscOptionsInt("-mat_inode_limit","Do not use inodes larger then this value",NULL,b->inode.limit,&b->inode.limit,NULL);CHKERRQ(ierr);
86d74fe821SBarry Smith   ierr = PetscOptionsEnd();CHKERRQ(ierr);
8726fbe8dcSKarl Rupp 
88ace3abfcSBarry Smith   b->inode.use = (PetscBool)(!(no_unroll || no_inode));
89d74fe821SBarry Smith   if (b->inode.limit > b->inode.max_limit) b->inode.limit = b->inode.max_limit;
90d74fe821SBarry Smith 
91bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)B,"MatInodeAdjustForInodes_C",MatInodeAdjustForInodes_SeqAIJ_Inode);CHKERRQ(ierr);
92bdf89e91SBarry Smith   ierr = PetscObjectComposeFunction((PetscObject)B,"MatInodeGetInodeSizes_C",MatInodeGetInodeSizes_SeqAIJ_Inode);CHKERRQ(ierr);
934c1414c8SBarry Smith   PetscFunctionReturn(0);
944c1414c8SBarry Smith }
954c1414c8SBarry Smith 
96ace3abfcSBarry Smith PetscErrorCode MatSetOption_SeqAIJ_Inode(Mat A,MatOption op,PetscBool flg)
974c1414c8SBarry Smith {
984c1414c8SBarry Smith   Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data;
99d74fe821SBarry Smith 
1004c1414c8SBarry Smith   PetscFunctionBegin;
1014c1414c8SBarry Smith   switch (op) {
1024c1414c8SBarry Smith   case MAT_USE_INODES:
1034e0d8c25SBarry Smith     a->inode.use = flg;
1044c1414c8SBarry Smith     break;
1054c1414c8SBarry Smith   default:
1064c1414c8SBarry Smith     break;
1074c1414c8SBarry Smith   }
1084c1414c8SBarry Smith   PetscFunctionReturn(0);
1094c1414c8SBarry Smith }
110