14c1414c8SBarry Smith #define PETSCMAT_DLL 2*7c4f633dSBarry Smith #include "../src/mat/impls/aij/seq/aij.h" 34c1414c8SBarry Smith 44c1414c8SBarry Smith EXTERN PetscErrorCode Mat_CheckInode(Mat,PetscTruth); 54c1414c8SBarry Smith EXTERN_C_BEGIN 64c1414c8SBarry Smith EXTERN PetscErrorCode PETSCMAT_DLLEXPORT MatInodeAdjustForInodes_Inode(Mat,IS*,IS*); 74c1414c8SBarry Smith EXTERN PetscErrorCode PETSCMAT_DLLEXPORT MatInodeGetInodeSizes_Inode(Mat,PetscInt*,PetscInt*[],PetscInt*); 84c1414c8SBarry Smith EXTERN_C_END 94c1414c8SBarry Smith 104c1414c8SBarry Smith #undef __FUNCT__ 114c1414c8SBarry Smith #define __FUNCT__ "MatView_Inode" 124c1414c8SBarry Smith PetscErrorCode MatView_Inode(Mat A,PetscViewer viewer) 134c1414c8SBarry Smith { 144c1414c8SBarry Smith Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data; 154c1414c8SBarry Smith PetscErrorCode ierr; 164c1414c8SBarry Smith PetscTruth iascii; 174c1414c8SBarry Smith PetscViewerFormat format; 184c1414c8SBarry Smith 194c1414c8SBarry Smith PetscFunctionBegin; 204c1414c8SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&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__ 364c1414c8SBarry Smith #define __FUNCT__ "MatAssemblyEnd_Inode" 374c1414c8SBarry Smith PetscErrorCode MatAssemblyEnd_Inode(Mat A, MatAssemblyType mode) 384c1414c8SBarry Smith { 3971f1c65dSBarry Smith Mat_SeqAIJ *a = (Mat_SeqAIJ*)A->data; 404c1414c8SBarry Smith PetscErrorCode ierr; 414c1414c8SBarry Smith PetscTruth samestructure; 424c1414c8SBarry Smith 434c1414c8SBarry Smith PetscFunctionBegin; 444c1414c8SBarry Smith /* info.nz_unneeded of zero denotes no structural change was made to the matrix during Assembly */ 454c1414c8SBarry Smith samestructure = (PetscTruth)(!A->info.nz_unneeded); 464c1414c8SBarry Smith /* check for identical nodes. If found, use inode functions */ 474c1414c8SBarry Smith ierr = Mat_CheckInode(A,samestructure);CHKERRQ(ierr); 4871f1c65dSBarry Smith a->inode.ibdiagvalid = PETSC_FALSE; 494c1414c8SBarry Smith PetscFunctionReturn(0); 504c1414c8SBarry Smith } 514c1414c8SBarry Smith 524c1414c8SBarry Smith #undef __FUNCT__ 534c1414c8SBarry Smith #define __FUNCT__ "MatDestroy_Inode" 544c1414c8SBarry Smith PetscErrorCode MatDestroy_Inode(Mat A) 554c1414c8SBarry Smith { 564c1414c8SBarry Smith PetscErrorCode ierr; 574c1414c8SBarry Smith Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data; 584c1414c8SBarry Smith 594c1414c8SBarry Smith PetscFunctionBegin; 604c1414c8SBarry Smith ierr = PetscFree(a->inode.size);CHKERRQ(ierr); 6171f1c65dSBarry Smith ierr = PetscFree2(a->inode.ibdiag,a->inode.bdiag);CHKERRQ(ierr); 624c1414c8SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatInodeAdjustForInodes_C","",PETSC_NULL);CHKERRQ(ierr); 634c1414c8SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)A,"MatInodeGetInodeSizes_C","",PETSC_NULL);CHKERRQ(ierr); 644c1414c8SBarry Smith PetscFunctionReturn(0); 654c1414c8SBarry Smith } 664c1414c8SBarry Smith 674c1414c8SBarry Smith /* MatCreate_Inode is not DLLEXPORTed because it is not a constructor for a complete type. */ 684c1414c8SBarry Smith /* It is also not registered as a type for use within MatSetType. */ 694c1414c8SBarry Smith /* It is intended as a helper for the MATSEQAIJ class, so classes which desire Inodes should */ 704c1414c8SBarry Smith /* inherit off of MATSEQAIJ instead by calling MatSetType(MATSEQAIJ) in their constructor. */ 714c1414c8SBarry Smith /* Maybe this is a bad idea. (?) */ 724c1414c8SBarry Smith #undef __FUNCT__ 734c1414c8SBarry Smith #define __FUNCT__ "MatCreate_Inode" 744c1414c8SBarry Smith PetscErrorCode MatCreate_Inode(Mat B) 754c1414c8SBarry Smith { 764c1414c8SBarry Smith Mat_SeqAIJ *b=(Mat_SeqAIJ*)B->data; 774c1414c8SBarry Smith PetscErrorCode ierr; 78da9f3051SSatish Balay PetscTruth no_inode,no_unroll; 794c1414c8SBarry Smith 804c1414c8SBarry Smith PetscFunctionBegin; 81da9f3051SSatish Balay no_inode = PETSC_FALSE; 82da9f3051SSatish Balay no_unroll = PETSC_FALSE; 834c1414c8SBarry Smith b->inode.node_count = 0; 844c1414c8SBarry Smith b->inode.size = 0; 854c1414c8SBarry Smith b->inode.limit = 5; 864c1414c8SBarry Smith b->inode.max_limit = 5; 8771f1c65dSBarry Smith b->inode.ibdiagvalid = PETSC_FALSE; 8871f1c65dSBarry Smith b->inode.ibdiag = 0; 8971f1c65dSBarry Smith b->inode.bdiag = 0; 904c1414c8SBarry Smith 917adad957SLisandro Dalcin ierr = PetscOptionsBegin(((PetscObject)B)->comm,((PetscObject)B)->prefix,"Options for SEQAIJ matrix","Mat");CHKERRQ(ierr); 92da9f3051SSatish Balay ierr = PetscOptionsTruth("-mat_no_unroll","Do not optimize for inodes (slower)",PETSC_NULL,no_unroll,&no_unroll,PETSC_NULL);CHKERRQ(ierr); 93da9f3051SSatish Balay if (no_unroll) {ierr = PetscInfo(B,"Not using Inode routines due to -mat_no_unroll\n");CHKERRQ(ierr);} 94da9f3051SSatish Balay ierr = PetscOptionsTruth("-mat_no_inode","Do not optimize for inodes (slower)",PETSC_NULL,no_inode,&no_inode,PETSC_NULL);CHKERRQ(ierr); 95da9f3051SSatish Balay if (no_inode) {ierr = PetscInfo(B,"Not using Inode routines due to -mat_no_inode\n");CHKERRQ(ierr);} 96d74fe821SBarry 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); 97d74fe821SBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 9888692965SHong Zhang b->inode.use = (PetscTruth)(!(no_unroll || no_inode)); 99d74fe821SBarry Smith if (b->inode.limit > b->inode.max_limit) b->inode.limit = b->inode.max_limit; 100d74fe821SBarry Smith 1014c1414c8SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatInodeAdjustForInodes_C", 1024c1414c8SBarry Smith "MatInodeAdjustForInodes_Inode", 1034c1414c8SBarry Smith MatInodeAdjustForInodes_Inode);CHKERRQ(ierr); 1044c1414c8SBarry Smith ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatInodeGetInodeSizes_C", 1054c1414c8SBarry Smith "MatInodeGetInodeSizes_Inode", 1064c1414c8SBarry Smith MatInodeGetInodeSizes_Inode);CHKERRQ(ierr); 1074c1414c8SBarry Smith PetscFunctionReturn(0); 1084c1414c8SBarry Smith } 1094c1414c8SBarry Smith 1104c1414c8SBarry Smith #undef __FUNCT__ 1114c1414c8SBarry Smith #define __FUNCT__ "MatSetOption_Inode" 1124e0d8c25SBarry Smith PetscErrorCode MatSetOption_Inode(Mat A,MatOption op,PetscTruth flg) 1134c1414c8SBarry Smith { 1144c1414c8SBarry Smith Mat_SeqAIJ *a=(Mat_SeqAIJ*)A->data; 115d74fe821SBarry Smith 1164c1414c8SBarry Smith PetscFunctionBegin; 1174c1414c8SBarry Smith switch(op) { 1184c1414c8SBarry Smith case MAT_USE_INODES: 1194e0d8c25SBarry Smith a->inode.use = flg; 1204c1414c8SBarry Smith break; 1214c1414c8SBarry Smith default: 1224c1414c8SBarry Smith break; 1234c1414c8SBarry Smith } 1244c1414c8SBarry Smith PetscFunctionReturn(0); 1254c1414c8SBarry Smith } 1264c1414c8SBarry Smith 1274c1414c8SBarry Smith #undef __FUNCT__ 1284c1414c8SBarry Smith #define __FUNCT__ "MatDuplicate_Inode" 1294c1414c8SBarry Smith PetscErrorCode MatDuplicate_Inode(Mat A,MatDuplicateOption cpvalues,Mat *C) 1304c1414c8SBarry Smith { 1314c1414c8SBarry Smith Mat B=*C; 1324c1414c8SBarry Smith Mat_SeqAIJ *c=(Mat_SeqAIJ*)B->data,*a=(Mat_SeqAIJ*)A->data; 1334c1414c8SBarry Smith PetscErrorCode ierr; 134d0f46423SBarry Smith PetscInt m=A->rmap->n; 1354c1414c8SBarry Smith 1364c1414c8SBarry Smith PetscFunctionBegin; 1374c1414c8SBarry Smith 1384c1414c8SBarry Smith c->inode.use = a->inode.use; 1394c1414c8SBarry Smith c->inode.limit = a->inode.limit; 1404c1414c8SBarry Smith c->inode.max_limit = a->inode.max_limit; 1414c1414c8SBarry Smith if (a->inode.size){ 1424c1414c8SBarry Smith ierr = PetscMalloc((m+1)*sizeof(PetscInt),&c->inode.size);CHKERRQ(ierr); 1434c1414c8SBarry Smith c->inode.node_count = a->inode.node_count; 1444c1414c8SBarry Smith ierr = PetscMemcpy(c->inode.size,a->inode.size,(m+1)*sizeof(PetscInt));CHKERRQ(ierr); 1454c1414c8SBarry Smith } else { 1464c1414c8SBarry Smith c->inode.size = 0; 1474c1414c8SBarry Smith c->inode.node_count = 0; 1484c1414c8SBarry Smith } 14971f1c65dSBarry Smith c->inode.ibdiagvalid = PETSC_FALSE; 15071f1c65dSBarry Smith c->inode.ibdiag = 0; 15171f1c65dSBarry Smith c->inode.bdiag = 0; 1524c1414c8SBarry Smith PetscFunctionReturn(0); 1534c1414c8SBarry Smith } 1544c1414c8SBarry Smith 1554c1414c8SBarry Smith #undef __FUNCT__ 1564c1414c8SBarry Smith #define __FUNCT__ "MatILUDTFactor_Inode" 1570481f469SBarry Smith PetscErrorCode MatILUDTFactor_Inode(Mat A,IS isrow,IS iscol,const MatFactorInfo *info,Mat *fact) 1584c1414c8SBarry Smith { 1594c1414c8SBarry Smith PetscErrorCode ierr; 1604c1414c8SBarry Smith 1614c1414c8SBarry Smith PetscFunctionBegin; 1624c1414c8SBarry Smith /* check for identical nodes. If found, use inode functions */ 1634c1414c8SBarry Smith ierr = Mat_CheckInode(*fact,PETSC_FALSE);CHKERRQ(ierr); 1644c1414c8SBarry Smith PetscFunctionReturn(0); 1654c1414c8SBarry Smith } 1664c1414c8SBarry Smith 167db4efbfdSBarry Smith extern PetscErrorCode MatSolve_Inode(Mat,Vec,Vec); 1680481f469SBarry Smith extern PetscErrorCode MatLUFactorNumeric_Inode(Mat,Mat,const MatFactorInfo*); 169db4efbfdSBarry Smith 1704c1414c8SBarry Smith #undef __FUNCT__ 1714c1414c8SBarry Smith #define __FUNCT__ "MatLUFactorSymbolic_Inode" 1720481f469SBarry Smith PetscErrorCode MatLUFactorSymbolic_Inode(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info) 1734c1414c8SBarry Smith { 1744c1414c8SBarry Smith PetscErrorCode ierr; 175db4efbfdSBarry Smith Mat_SeqAIJ *f = (Mat_SeqAIJ*)A->data; 1764c1414c8SBarry Smith 1774c1414c8SBarry Smith PetscFunctionBegin; 1784c1414c8SBarry Smith /* check for identical nodes. If found, use inode functions */ 179719d5645SBarry Smith ierr = Mat_CheckInode(fact,PETSC_FALSE);CHKERRQ(ierr); 180db4efbfdSBarry Smith if (f->inode.use) { 181719d5645SBarry Smith (fact)->ops->lufactornumeric = MatLUFactorNumeric_Inode; 182db4efbfdSBarry Smith } 1834c1414c8SBarry Smith PetscFunctionReturn(0); 1844c1414c8SBarry Smith } 1854c1414c8SBarry Smith 1864c1414c8SBarry Smith #undef __FUNCT__ 1874c1414c8SBarry Smith #define __FUNCT__ "MatILUFactorSymbolic_Inode" 1880481f469SBarry Smith PetscErrorCode MatILUFactorSymbolic_Inode(Mat fact,Mat A,IS isrow,IS iscol,const MatFactorInfo *info) 1894c1414c8SBarry Smith { 1904c1414c8SBarry Smith PetscErrorCode ierr; 191db4efbfdSBarry Smith Mat_SeqAIJ *f = (Mat_SeqAIJ*)A->data; 1924c1414c8SBarry Smith 1934c1414c8SBarry Smith PetscFunctionBegin; 1944c1414c8SBarry Smith /* check for identical nodes. If found, use inode functions */ 195719d5645SBarry Smith ierr = Mat_CheckInode(fact,PETSC_FALSE);CHKERRQ(ierr); 196db4efbfdSBarry Smith if (f->inode.use) { 197719d5645SBarry Smith (fact)->ops->lufactornumeric = MatLUFactorNumeric_Inode; 198db4efbfdSBarry Smith } 1994c1414c8SBarry Smith PetscFunctionReturn(0); 2004c1414c8SBarry Smith } 2014c1414c8SBarry Smith 2024c1414c8SBarry Smith 203