173f4d377SMatthew Knepley /* $Id: petscmat.h,v 1.228 2001/09/07 20:09:08 bsmith Exp $ */ 22eac72dbSBarry Smith /* 32eac72dbSBarry Smith Include file for the matrix component of PETSc 42eac72dbSBarry Smith */ 50a835dfdSSatish Balay #ifndef __PETSCMAT_H 60a835dfdSSatish Balay #define __PETSCMAT_H 70a835dfdSSatish Balay #include "petscvec.h" 8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN 92eac72dbSBarry Smith 10d9274352SBarry Smith /*S 11d9274352SBarry Smith Mat - Abstract PETSc matrix object 122eac72dbSBarry Smith 13d91e6319SBarry Smith Level: beginner 14d91e6319SBarry Smith 15d9274352SBarry Smith Concepts: matrix; linear operator 16d9274352SBarry Smith 17d9274352SBarry Smith .seealso: MatCreate(), MatType, MatSetType() 18d9274352SBarry Smith S*/ 19d9274352SBarry Smith typedef struct _p_Mat* Mat; 20d9274352SBarry Smith 21d9274352SBarry Smith /*E 22d9274352SBarry Smith MatType - String with the name of a PETSc matrix or the creation function 23d9274352SBarry Smith with an optional dynamic library name, for example 24d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:mymatcreate() 25d9274352SBarry Smith 26d9274352SBarry Smith Level: beginner 27d9274352SBarry Smith 28d9274352SBarry Smith .seealso: MatSetType(), Mat 29d91e6319SBarry Smith E*/ 30273d9f13SBarry Smith #define MATSAME "same" 31273d9f13SBarry Smith #define MATSEQMAIJ "seqmaij" 32273d9f13SBarry Smith #define MATMPIMAIJ "mpimaij" 33209238afSKris Buschelman #define MATMAIJ "maij" 34273d9f13SBarry Smith #define MATIS "is" 35273d9f13SBarry Smith #define MATMPIROWBS "mpirowbs" 36273d9f13SBarry Smith #define MATSEQAIJ "seqaij" 37273d9f13SBarry Smith #define MATMPIAIJ "mpiaij" 38209238afSKris Buschelman #define MATAIJ "aij" 39273d9f13SBarry Smith #define MATSHELL "shell" 40273d9f13SBarry Smith #define MATSEQBDIAG "seqbdiag" 41273d9f13SBarry Smith #define MATMPIBDIAG "mpibdiag" 42209238afSKris Buschelman #define MATBDIAG "bdiag" 43209238afSKris Buschelman #define MATSEQDENSE "seqdense" 44273d9f13SBarry Smith #define MATMPIDENSE "mpidense" 45209238afSKris Buschelman #define MATDENSE "dense" 46273d9f13SBarry Smith #define MATSEQBAIJ "seqbaij" 47273d9f13SBarry Smith #define MATMPIBAIJ "mpibaij" 48209238afSKris Buschelman #define MATBAIJ "baij" 49273d9f13SBarry Smith #define MATMPIADJ "mpiadj" 50273d9f13SBarry Smith #define MATSEQSBAIJ "seqsbaij" 51273d9f13SBarry Smith #define MATMPISBAIJ "mpisbaij" 52209238afSKris Buschelman #define MATSBAIJ "sbaij" 53cebc7f6cSBarry Smith #define MATDAAD "daad" 54cebc7f6cSBarry Smith #define MATMFFD "mffd" 556d88219bSBarry Smith #define MATESI "esi" 566d88219bSBarry Smith #define MATPETSCESI "petscesi" 57c8a8475eSBarry Smith #define MATNORMAL "normal" 58b3a1e11cSKris Buschelman #define MATSEQAIJSPOOLES "seqaijspooles" 59d10c748bSKris Buschelman #define MATMPIAIJSPOOLES "mpiaijspooles" 609abb65ffSKris Buschelman #define MATSEQSBAIJSPOOLES "seqsbaijspooles" 6122191285SKris Buschelman #define MATMPISBAIJSPOOLES "mpisbaijspooles" 6214b396bbSKris Buschelman #define MATSUPERLU "superlu" 631d96aa28SKris Buschelman #define MATSUPERLU_DIST "superlu_dist" 641677d0b8SKris Buschelman #define MATUMFPACK "umfpack" 65e8aa55a4SKris Buschelman #define MATESSL "essl" 664eb8e494SKris Buschelman #define MATLUSOL "lusol" 67397b6df1SKris Buschelman #define MATAIJMUMPS "aijmumps" 68397b6df1SKris Buschelman #define MATSBAIJMUMPS "sbaijmumps" 698da957c5SKris Buschelman #define MATDSCPACK "dscpack" 7049773a63SBarry Smith #define MatType char* 71d91e6319SBarry Smith 72c06d978dSMatthew Knepley /* Logging support */ 73552e946dSBarry Smith #define MAT_FILE_COOKIE 1211216 /* used to indicate matrices in binary files */ 74c06d978dSMatthew Knepley extern int MAT_COOKIE; 7571d41ebeSBarry Smith extern int MATSNESMFCTX_COOKIE; 76c06d978dSMatthew Knepley extern int MAT_FDCOLORING_COOKIE; 778ba1e511SMatthew Knepley extern int MAT_PARTITIONING_COOKIE; 788ba1e511SMatthew Knepley extern int MAT_NULLSPACE_COOKIE; 79d59c15a7SBarry Smith extern int MAT_Mult, MAT_MultMatrixFree, MAT_Mults, MAT_MultConstrained, MAT_MultAdd, MAT_MultTranspose; 80d59c15a7SBarry Smith extern int MAT_MultTransposeConstrained, MAT_MultTransposeAdd, MAT_Solve, MAT_Solves, MAT_SolveAdd, MAT_SolveTranspose; 81d5ba7fb7SMatthew Knepley extern int MAT_SolveTransposeAdd, MAT_Relax, MAT_ForwardSolve, MAT_BackwardSolve, MAT_LUFactor, MAT_LUFactorSymbolic; 82d5ba7fb7SMatthew Knepley extern int MAT_LUFactorNumeric, MAT_CholeskyFactor, MAT_CholeskyFactorSymbolic, MAT_CholeskyFactorNumeric, MAT_ILUFactor; 83d5ba7fb7SMatthew Knepley extern int MAT_ILUFactorSymbolic, MAT_ICCFactorSymbolic, MAT_Copy, MAT_Convert, MAT_Scale, MAT_AssemblyBegin; 84d5ba7fb7SMatthew Knepley extern int MAT_AssemblyEnd, MAT_SetValues, MAT_GetValues, MAT_GetRow, MAT_GetSubMatrices, MAT_GetColoring, MAT_GetOrdering; 85d5ba7fb7SMatthew Knepley extern int MAT_IncreaseOverlap, MAT_Partitioning, MAT_ZeroEntries, MAT_Load, MAT_View, MAT_AXPY, MAT_FDColoringCreate; 8666f9b7ceSBarry Smith extern int MAT_FDColoringApply, MAT_Transpose, MAT_FDColoringFunction; 87c06d978dSMatthew Knepley 888ba1e511SMatthew Knepley EXTERN int MatInitializePackage(char *); 89c06d978dSMatthew Knepley 90273d9f13SBarry Smith EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*); 910e33f6ddSBarry Smith EXTERN int MatSetType(Mat,const MatType); 92273d9f13SBarry Smith EXTERN int MatSetFromOptions(Mat); 93273d9f13SBarry Smith EXTERN int MatSetUpPreallocation(Mat); 940e33f6ddSBarry Smith EXTERN int MatRegisterAll(const char[]); 950e33f6ddSBarry Smith EXTERN int MatRegister(const char[],const char[],const char[],int(*)(Mat)); 9630de9b25SBarry Smith 9730de9b25SBarry Smith /*MC 9830de9b25SBarry Smith MatRegisterDynamic - Adds a new matrix type 9930de9b25SBarry Smith 10030de9b25SBarry Smith Synopsis: 10130de9b25SBarry Smith int MatRegisterDynamic(char *name,char *path,char *name_create,int (*routine_create)(Mat)) 10230de9b25SBarry Smith 10330de9b25SBarry Smith Not Collective 10430de9b25SBarry Smith 10530de9b25SBarry Smith Input Parameters: 10630de9b25SBarry Smith + name - name of a new user-defined matrix type 10730de9b25SBarry Smith . path - path (either absolute or relative) the library containing this solver 10830de9b25SBarry Smith . name_create - name of routine to create method context 10930de9b25SBarry Smith - routine_create - routine to create method context 11030de9b25SBarry Smith 11130de9b25SBarry Smith Notes: 11230de9b25SBarry Smith MatRegisterDynamic() may be called multiple times to add several user-defined solvers. 11330de9b25SBarry Smith 11430de9b25SBarry Smith If dynamic libraries are used, then the fourth input argument (routine_create) 11530de9b25SBarry Smith is ignored. 11630de9b25SBarry Smith 11730de9b25SBarry Smith Sample usage: 11830de9b25SBarry Smith .vb 11930de9b25SBarry Smith MatRegisterDynamic("my_mat",/home/username/my_lib/lib/libO/solaris/mylib.a, 12030de9b25SBarry Smith "MyMatCreate",MyMatCreate); 12130de9b25SBarry Smith .ve 12230de9b25SBarry Smith 12330de9b25SBarry Smith Then, your solver can be chosen with the procedural interface via 12430de9b25SBarry Smith $ MatSetType(Mat,"my_mat") 12530de9b25SBarry Smith or at runtime via the option 12630de9b25SBarry Smith $ -mat_type my_mat 12730de9b25SBarry Smith 12830de9b25SBarry Smith Level: advanced 12930de9b25SBarry Smith 13030de9b25SBarry Smith Notes: ${PETSC_ARCH} and ${BOPT} occuring in pathname will be replaced with appropriate values. 13130de9b25SBarry Smith If your function is not being put into a shared library then use VecRegister() instead 13230de9b25SBarry Smith 13330de9b25SBarry Smith .keywords: Mat, register 13430de9b25SBarry Smith 13530de9b25SBarry Smith .seealso: MatRegisterAll(), MatRegisterDestroy() 13630de9b25SBarry Smith 13730de9b25SBarry Smith M*/ 138273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 139273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,0) 140273d9f13SBarry Smith #else 141273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,d) 14230de9b25SBarry Smith #endif 14330de9b25SBarry Smith 144273d9f13SBarry Smith extern PetscTruth MatRegisterAllCalled; 145b0a32e0cSBarry Smith extern PetscFList MatList; 14628988994SBarry Smith 147ca01db9bSBarry Smith EXTERN int MatCreateSeqDense(MPI_Comm,int,int,PetscScalar[],Mat*); 148ca01db9bSBarry Smith EXTERN int MatCreateMPIDense(MPI_Comm,int,int,int,int,PetscScalar[],Mat*); 149ca01db9bSBarry Smith EXTERN int MatCreateSeqAIJ(MPI_Comm,int,int,int,const int[],Mat*); 150ca01db9bSBarry Smith EXTERN int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,const int[],int,const int[],Mat*); 151ca01db9bSBarry Smith EXTERN int MatCreateMPIRowbs(MPI_Comm,int,int,int,const int[],Mat*); 152ca01db9bSBarry Smith EXTERN int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,const int[],PetscScalar*[],Mat*); 153ca01db9bSBarry Smith EXTERN int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,const int[],PetscScalar*[],Mat*); 154ca01db9bSBarry Smith EXTERN int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,const int[],Mat*); 155ca01db9bSBarry Smith EXTERN int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,const int[],int,const int[],Mat*); 156ca01db9bSBarry Smith EXTERN int MatCreateMPIAdj(MPI_Comm,int,int,int[],int[],int[],Mat*); 157ca01db9bSBarry Smith EXTERN int MatCreateSeqSBAIJ(MPI_Comm,int,int,int,int,const int[],Mat*); 158ca01db9bSBarry Smith EXTERN int MatCreateMPISBAIJ(MPI_Comm,int,int,int,int,int,int,const int[],int,const int[],Mat*); 159ca44d042SBarry Smith EXTERN int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*); 1603a7fca6bSBarry Smith EXTERN int MatCreateAdic(MPI_Comm,int,int,int,int,int,void (*)(void),Mat*); 161c8a8475eSBarry Smith EXTERN int MatCreateNormal(Mat,Mat*); 162435da068SBarry Smith EXTERN int MatDestroy(Mat); 16321c89e3eSBarry Smith 164ca44d042SBarry Smith EXTERN int MatPrintHelp(Mat); 1658a124369SBarry Smith EXTERN int MatGetPetscMaps(Mat,PetscMap*,PetscMap*); 166ec0117caSBarry Smith 1678ed539a5SBarry Smith /* ------------------------------------------------------------*/ 168f15d580aSBarry Smith EXTERN int MatSetValues(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode); 169f15d580aSBarry Smith EXTERN int MatSetValuesBlocked(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode); 17084cb2905SBarry Smith 1712ef4de8bSBarry Smith /*S 1722ef4de8bSBarry Smith MatStencil - Data structure (C struct) for storing information about a single row or 1732ef4de8bSBarry Smith column of a matrix as index on an associated grid. 1742ef4de8bSBarry Smith 1752ef4de8bSBarry Smith Level: beginner 1762ef4de8bSBarry Smith 1772ef4de8bSBarry Smith Concepts: matrix; linear operator 1782ef4de8bSBarry Smith 179d7bd93baSBarry Smith .seealso: MatSetValuesStencil(), MatSetStencil(), MatSetValuesBlockStencil() 1802ef4de8bSBarry Smith S*/ 181435da068SBarry Smith typedef struct { 182435da068SBarry Smith int k,j,i,c; 183435da068SBarry Smith } MatStencil; 1842ef4de8bSBarry Smith 185f15d580aSBarry Smith EXTERN int MatSetValuesStencil(Mat,int,const MatStencil[],int,const MatStencil[],const PetscScalar[],InsertMode); 186f15d580aSBarry Smith EXTERN int MatSetValuesBlockedStencil(Mat,int,const MatStencil[],int,const MatStencil[],const PetscScalar[],InsertMode); 187f15d580aSBarry Smith EXTERN int MatSetStencil(Mat,int,const int[],const int[],int); 188435da068SBarry Smith 1893a7fca6bSBarry Smith EXTERN int MatSetColoring(Mat,ISColoring); 1903a7fca6bSBarry Smith EXTERN int MatSetValuesAdic(Mat,void*); 1913a7fca6bSBarry Smith EXTERN int MatSetValuesAdifor(Mat,int,void*); 1923a7fca6bSBarry Smith 193d91e6319SBarry Smith /*E 194d91e6319SBarry Smith MatAssemblyType - Indicates if the matrix is now to be used, or if you plan 195d91e6319SBarry Smith to continue to add values to it 196d91e6319SBarry Smith 197d91e6319SBarry Smith Level: beginner 198d91e6319SBarry Smith 199d91e6319SBarry Smith .seealso: MatAssemblyBegin(), MatAssemblyEnd() 200d91e6319SBarry Smith E*/ 2016d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType; 202ca44d042SBarry Smith EXTERN int MatAssemblyBegin(Mat,MatAssemblyType); 203ca44d042SBarry Smith EXTERN int MatAssemblyEnd(Mat,MatAssemblyType); 204ca44d042SBarry Smith EXTERN int MatAssembled(Mat,PetscTruth*); 2054f9c727eSBarry Smith 20630de9b25SBarry Smith /*MC 20730de9b25SBarry Smith MatSetValue - Set a single entry into a matrix. 20830de9b25SBarry Smith 20930de9b25SBarry Smith Synopsis: 21030de9b25SBarry Smith int MatSetValue(Mat m,int row,int col,PetscScalar value,InsertMode mode); 21130de9b25SBarry Smith 21230de9b25SBarry Smith Not collective 21330de9b25SBarry Smith 21430de9b25SBarry Smith Input Parameters: 21530de9b25SBarry Smith + m - the matrix 21630de9b25SBarry Smith . row - the row location of the entry 21730de9b25SBarry Smith . col - the column location of the entry 21830de9b25SBarry Smith . value - the value to insert 21930de9b25SBarry Smith - mode - either INSERT_VALUES or ADD_VALUES 22030de9b25SBarry Smith 22130de9b25SBarry Smith Notes: 22230de9b25SBarry Smith For efficiency one should use MatSetValues() and set several or many 22330de9b25SBarry Smith values simultaneously if possible. 22430de9b25SBarry Smith 22530de9b25SBarry Smith Note that MatSetValue() does NOT return an error code (since this 22630de9b25SBarry Smith is checked internally). 22730de9b25SBarry Smith 22830de9b25SBarry Smith Level: beginner 22930de9b25SBarry Smith 23030de9b25SBarry Smith .seealso: MatSetValues(), MatSetValueLocal() 23130de9b25SBarry Smith M*/ 232b951964fSBarry Smith #define MatSetValue(v,i,j,va,mode) \ 233ea709b57SSatish Balay 0; {int _ierr,_row = i,_col = j; PetscScalar _va = va; \ 234b951964fSBarry Smith _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \ 235b951964fSBarry Smith } 23630de9b25SBarry Smith 237ea06a074SBarry Smith #define MatGetValue(v,i,j,va) \ 238d91e6319SBarry Smith 0; {int _ierr,_row = i,_col = j; \ 239ea06a074SBarry Smith _ierr = MatGetValues(v,1,&_row,1,&_col,&va);CHKERRQ(_ierr); \ 240ea06a074SBarry Smith } 24130de9b25SBarry Smith 242d91e6319SBarry Smith #define MatSetValueLocal(v,i,j,va,mode) \ 243ea709b57SSatish Balay 0; {int _ierr,_row = i,_col = j; PetscScalar _va = va; \ 244d91e6319SBarry Smith _ierr = MatSetValuesLocal(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \ 245d91e6319SBarry Smith } 24630de9b25SBarry Smith 247d91e6319SBarry Smith /*E 248d91e6319SBarry Smith MatOption - Options that may be set for a matrix and its behavior or storage 249d91e6319SBarry Smith 250d91e6319SBarry Smith Level: beginner 251d91e6319SBarry Smith 2520a835dfdSSatish Balay Any additions/changes here MUST also be made in include/finclude/petscmat.h 253d91e6319SBarry Smith 254d91e6319SBarry Smith .seealso: MatSetOption() 255d91e6319SBarry Smith E*/ 2566d4a8577SBarry Smith typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4, 2576d4a8577SBarry Smith MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16, 2586d4a8577SBarry Smith MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64, 2596ca9ecd3SBarry Smith MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66, 2606ca9ecd3SBarry Smith MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69, 2616ca9ecd3SBarry Smith MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72, 2626ca9ecd3SBarry Smith MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74, 2634787f768SSatish Balay MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76, 2647c922b88SBarry Smith MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78, 2652bad1931SBarry Smith MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81, 266efcf0fc3SBarry Smith MAT_DO_NOT_USE_INODES=82,MAT_NOT_SYMMETRIC=83,MAT_HERMITIAN=84, 2679a4540c5SBarry Smith MAT_NOT_STRUCTURALLY_SYMMETRIC=85,MAT_NOT_HERMITIAN=86, 2689a4540c5SBarry Smith MAT_SYMMETRY_ETERNAL=87,MAT_NOT_SYMMETRY_ETERNAL=88} MatOption; 269ca44d042SBarry Smith EXTERN int MatSetOption(Mat,MatOption); 270273d9f13SBarry Smith EXTERN int MatGetType(Mat,MatType*); 27184cb2905SBarry Smith 272f15d580aSBarry Smith EXTERN int MatGetValues(Mat,int,const int[],int,const int[],PetscScalar[]); 273f15d580aSBarry Smith EXTERN int MatGetRow(Mat,int,int *,int *[],PetscScalar*[]); 274f15d580aSBarry Smith EXTERN int MatRestoreRow(Mat,int,int *,int *[],PetscScalar*[]); 2754e7234bfSBarry Smith EXTERN int MatGetColumn(Mat,int,int *,int *[],PetscScalar*[]); 2764e7234bfSBarry Smith EXTERN int MatRestoreColumn(Mat,int,int *,int *[],PetscScalar*[]); 277ca44d042SBarry Smith EXTERN int MatGetColumnVector(Mat,Vec,int); 2784e7234bfSBarry Smith EXTERN int MatGetArray(Mat,PetscScalar *[]); 2794e7234bfSBarry Smith EXTERN int MatRestoreArray(Mat,PetscScalar *[]); 280ca44d042SBarry Smith EXTERN int MatGetBlockSize(Mat,int *); 2817b80b807SBarry Smith 282ca44d042SBarry Smith EXTERN int MatMult(Mat,Vec,Vec); 283ca44d042SBarry Smith EXTERN int MatMultAdd(Mat,Vec,Vec,Vec); 284ca44d042SBarry Smith EXTERN int MatMultTranspose(Mat,Vec,Vec); 2855fbd3699SBarry Smith EXTERN int MatIsTranspose(Mat,Mat,PetscTruth*); 286ca44d042SBarry Smith EXTERN int MatMultTransposeAdd(Mat,Vec,Vec,Vec); 287c06d978dSMatthew Knepley EXTERN int MatMultConstrained(Mat,Vec,Vec); 2886d0dc95fSMatthew Knepley EXTERN int MatMultTransposeConstrained(Mat,Vec,Vec); 2892eac72dbSBarry Smith 290d91e6319SBarry Smith /*E 291d91e6319SBarry Smith MatDuplicateOption - Indicates if a duplicated sparse matrix should have 292d91e6319SBarry Smith its numerical values copied over or just its nonzero structure. 293d91e6319SBarry Smith 294d91e6319SBarry Smith Level: beginner 295d91e6319SBarry Smith 296d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 297d91e6319SBarry Smith 298d91e6319SBarry Smith .seealso: MatDuplicate() 299d91e6319SBarry Smith E*/ 3002e8a6d31SBarry Smith typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption; 3012e8a6d31SBarry Smith 3020e33f6ddSBarry Smith EXTERN int MatConvertRegister(const char[],const char[],const char[],int (*)(Mat,MatType,Mat*)); 303273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 304273d9f13SBarry Smith #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,0) 305273d9f13SBarry Smith #else 306273d9f13SBarry Smith #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,d) 307273d9f13SBarry Smith #endif 3080e33f6ddSBarry Smith EXTERN int MatConvertRegisterAll(const char[]); 309273d9f13SBarry Smith EXTERN int MatConvertRegisterDestroy(void); 310273d9f13SBarry Smith extern PetscTruth MatConvertRegisterAllCalled; 311b0a32e0cSBarry Smith extern PetscFList MatConvertList; 3128e9aea5cSBarry Smith EXTERN int MatConvert(Mat,const MatType,Mat*); 313ca44d042SBarry Smith EXTERN int MatDuplicate(Mat,MatDuplicateOption,Mat*); 31494a9d846SBarry Smith 315d91e6319SBarry Smith /*E 316d91e6319SBarry Smith MatStructure - Indicates if the matrix has the same nonzero structure 317d91e6319SBarry Smith 318d91e6319SBarry Smith Level: beginner 319d91e6319SBarry Smith 320d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 321d91e6319SBarry Smith 32294b7f48cSBarry Smith .seealso: MatCopy(), KSPSetOperators(), PCSetOperators() 323d91e6319SBarry Smith E*/ 324c537a176SHong Zhang typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER,SUBSET_NONZERO_PATTERN} MatStructure; 325cb5b572fSBarry Smith 326ca44d042SBarry Smith EXTERN int MatCopy(Mat,Mat,MatStructure); 327b0a32e0cSBarry Smith EXTERN int MatView(Mat,PetscViewer); 328*1b8f9509SBarry Smith EXTERN int MatIsSymmetric(Mat,PetscTruth*); 3298e9aea5cSBarry Smith EXTERN int MatLoad(PetscViewer,const MatType,Mat*); 33051dd7536SBarry Smith EXTERN int MatMerge(MPI_Comm,Mat,Mat*); 3317b80b807SBarry Smith 3324e7234bfSBarry Smith EXTERN int MatGetRowIJ(Mat,int,PetscTruth,int*,int *[],int *[],PetscTruth *); 3334e7234bfSBarry Smith EXTERN int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int *[],int *[],PetscTruth *); 3344e7234bfSBarry Smith EXTERN int MatGetColumnIJ(Mat,int,PetscTruth,int*,int *[],int *[],PetscTruth *); 3354e7234bfSBarry Smith EXTERN int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int *[],int *[],PetscTruth *); 336d4fbbf0eSBarry Smith 337d91e6319SBarry Smith /*S 338d91e6319SBarry Smith MatInfo - Context of matrix information, used with MatGetInfo() 339d91e6319SBarry Smith 340d91e6319SBarry Smith In Fortran this is simply a double precision array of dimension MAT_INFO_SIZE 341d91e6319SBarry Smith 342d91e6319SBarry Smith Level: intermediate 343d91e6319SBarry Smith 344d91e6319SBarry Smith Concepts: matrix^nonzero information 345d91e6319SBarry Smith 346d9274352SBarry Smith .seealso: MatGetInfo(), MatInfoType 347d91e6319SBarry Smith S*/ 3484e220ebcSLois Curfman McInnes typedef struct { 349b0a32e0cSBarry Smith PetscLogDouble rows_global,columns_global; /* number of global rows and columns */ 350b0a32e0cSBarry Smith PetscLogDouble rows_local,columns_local; /* number of local rows and columns */ 351b0a32e0cSBarry Smith PetscLogDouble block_size; /* block size */ 352b0a32e0cSBarry Smith PetscLogDouble nz_allocated,nz_used,nz_unneeded; /* number of nonzeros */ 353b0a32e0cSBarry Smith PetscLogDouble memory; /* memory allocated */ 354b0a32e0cSBarry Smith PetscLogDouble assemblies; /* number of matrix assemblies called */ 355b0a32e0cSBarry Smith PetscLogDouble mallocs; /* number of mallocs during MatSetValues() */ 356b0a32e0cSBarry Smith PetscLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */ 357b0a32e0cSBarry Smith PetscLogDouble factor_mallocs; /* number of mallocs during factorization */ 3584e220ebcSLois Curfman McInnes } MatInfo; 3594e220ebcSLois Curfman McInnes 360d9274352SBarry Smith /*E 361d9274352SBarry Smith MatInfoType - Indicates if you want information about the local part of the matrix, 362d9274352SBarry Smith the entire parallel matrix or the maximum over all the local parts. 363d9274352SBarry Smith 364d9274352SBarry Smith Level: beginner 365d9274352SBarry Smith 366d9274352SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 367d9274352SBarry Smith 368d9274352SBarry Smith .seealso: MatGetInfo(), MatInfo 369d9274352SBarry Smith E*/ 3707b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType; 371ca44d042SBarry Smith EXTERN int MatGetInfo(Mat,MatInfoType,MatInfo*); 372ca44d042SBarry Smith EXTERN int MatValid(Mat,PetscTruth*); 373ca44d042SBarry Smith EXTERN int MatGetDiagonal(Mat,Vec); 374273d9f13SBarry Smith EXTERN int MatGetRowMax(Mat,Vec); 375ca44d042SBarry Smith EXTERN int MatTranspose(Mat,Mat*); 376ca44d042SBarry Smith EXTERN int MatPermute(Mat,IS,IS,Mat *); 377bf1d55d4SSatish Balay EXTERN int MatPermuteSparsify(Mat,int,PetscReal,PetscReal,IS,IS,Mat *); 378ca44d042SBarry Smith EXTERN int MatDiagonalScale(Mat,Vec,Vec); 37906ef90c2SBarry Smith EXTERN int MatDiagonalSet(Mat,Vec,InsertMode); 380ca44d042SBarry Smith EXTERN int MatEqual(Mat,Mat,PetscTruth*); 3817b80b807SBarry Smith 38287828ca2SBarry Smith EXTERN int MatNorm(Mat,NormType,PetscReal *); 383ca44d042SBarry Smith EXTERN int MatZeroEntries(Mat); 384268466fbSBarry Smith EXTERN int MatZeroRows(Mat,IS,const PetscScalar*); 385268466fbSBarry Smith EXTERN int MatZeroColumns(Mat,IS,const PetscScalar*); 3867b80b807SBarry Smith 387ca44d042SBarry Smith EXTERN int MatUseScaledForm(Mat,PetscTruth); 388ca44d042SBarry Smith EXTERN int MatScaleSystem(Mat,Vec,Vec); 389ca44d042SBarry Smith EXTERN int MatUnScaleSystem(Mat,Vec,Vec); 3905ef9f2a5SBarry Smith 391ca44d042SBarry Smith EXTERN int MatGetSize(Mat,int*,int*); 392ca44d042SBarry Smith EXTERN int MatGetLocalSize(Mat,int*,int*); 393ca44d042SBarry Smith EXTERN int MatGetOwnershipRange(Mat,int*,int*); 3947b80b807SBarry Smith 395d91e6319SBarry Smith /*E 396d91e6319SBarry Smith MatReuse - Indicates if matrices obtained from a previous call to MatGetSubMatrices() 397d91e6319SBarry Smith or MatGetSubMatrix() are to be reused to store the new matrix values. 398d91e6319SBarry Smith 399d91e6319SBarry Smith Level: beginner 400d91e6319SBarry Smith 401d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 402d91e6319SBarry Smith 403d91e6319SBarry Smith .seealso: MatGetSubMatrices(), MatGetSubMatrix(), MatDestroyMatrices() 404d91e6319SBarry Smith E*/ 4057b2a1423SBarry Smith typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse; 406268466fbSBarry Smith EXTERN int MatGetSubMatrices(Mat,int,const IS[],const IS[],MatReuse,Mat *[]); 407268466fbSBarry Smith EXTERN int MatDestroyMatrices(int,Mat *[]); 408ca44d042SBarry Smith EXTERN int MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *); 4098efafbd8SBarry Smith 410268466fbSBarry Smith EXTERN int MatIncreaseOverlap(Mat,int,IS[],int); 4117b80b807SBarry Smith 412268466fbSBarry Smith EXTERN int MatAXPY(const PetscScalar *,Mat,Mat,MatStructure); 413268466fbSBarry Smith EXTERN int MatAYPX(const PetscScalar *,Mat,Mat); 414ca44d042SBarry Smith EXTERN int MatCompress(Mat); 4157b80b807SBarry Smith 416268466fbSBarry Smith EXTERN int MatScale(const PetscScalar *,Mat); 417268466fbSBarry Smith EXTERN int MatShift(const PetscScalar *,Mat); 418052efed2SBarry Smith 419ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping); 420ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping); 421268466fbSBarry Smith EXTERN int MatZeroRowsLocal(Mat,IS,const PetscScalar*); 422f15d580aSBarry Smith EXTERN int MatSetValuesLocal(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode); 423f15d580aSBarry Smith EXTERN int MatSetValuesBlockedLocal(Mat,int,const int[],int,const int[],const PetscScalar[],InsertMode); 42490f02eecSBarry Smith 425ca44d042SBarry Smith EXTERN int MatSetStashInitialSize(Mat,int,int); 426649db694SBarry Smith 427ca44d042SBarry Smith EXTERN int MatInterpolateAdd(Mat,Vec,Vec,Vec); 428ca44d042SBarry Smith EXTERN int MatInterpolate(Mat,Vec,Vec); 429ca44d042SBarry Smith EXTERN int MatRestrict(Mat,Vec,Vec); 4307c922b88SBarry Smith 431bd481603SBarry Smith 432bd481603SBarry Smith /*MC 433bd481603SBarry Smith MatPreallocInitialize - Begins the block of code that will count the number of nonzeros per 434bd481603SBarry Smith row in a matrix providing the data that one can use to correctly preallocate the matrix. 435bd481603SBarry Smith 436bd481603SBarry Smith Synopsis: 437bd481603SBarry Smith int MatPreallocateInitialize(MPI_Comm comm, int nrows, int ncols, int *dnz, int *onz) 438bd481603SBarry Smith 439bd481603SBarry Smith Collective on MPI_Comm 440bd481603SBarry Smith 441bd481603SBarry Smith Input Parameters: 442bd481603SBarry Smith + comm - the communicator that will share the eventually allocated matrix 443bd481603SBarry Smith . nrows - the number of rows in the matrix 444bd481603SBarry Smith - ncols - the number of columns in the matrix 445bd481603SBarry Smith 446bd481603SBarry Smith Output Parameters: 447bd481603SBarry Smith + dnz - the array that will be passed to the matrix preallocation routines 448bd481603SBarry Smith - ozn - the other array passed to the matrix preallocation routines 449bd481603SBarry Smith 450bd481603SBarry Smith 451bd481603SBarry Smith Level: intermediate 452bd481603SBarry Smith 453bd481603SBarry Smith Notes: 454bd481603SBarry Smith See the chapter in the users manual on performance for more details 455bd481603SBarry Smith 456bd481603SBarry Smith Do not malloc or free dnz and onz that is handled internally by these routines 457bd481603SBarry Smith 458bd481603SBarry Smith Use MatPreallocateInitializeSymmetric() for symmetric matrices (MPISBAIJ matrices) 459bd481603SBarry Smith 460bd481603SBarry Smith Concepts: preallocation^Matrix 461bd481603SBarry Smith 462bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(), 463bd481603SBarry Smith MatPreallocateInitializeSymmetric(), MatPreallocateSymmetricSetLocal() 464bd481603SBarry Smith M*/ 465c4f061fbSSatish Balay #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \ 4667c922b88SBarry Smith { \ 467ef66eb69SBarry Smith int _4_ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \ 468ef66eb69SBarry Smith _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\ 469ef66eb69SBarry Smith _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\ 470ef66eb69SBarry Smith _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __start = __end - __ctmp;\ 471ef66eb69SBarry Smith _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp; 4727c922b88SBarry Smith 473bd481603SBarry Smith /*MC 474bd481603SBarry Smith MatPreallocSymmetricInitialize - Begins the block of code that will count the number of nonzeros per 475bd481603SBarry Smith row in a matrix providing the data that one can use to correctly preallocate the matrix. 476bd481603SBarry Smith 477bd481603SBarry Smith Synopsis: 478bd481603SBarry Smith int MatPreallocateSymmetricInitialize(MPI_Comm comm, int nrows, int ncols, int *dnz, int *onz) 479bd481603SBarry Smith 480bd481603SBarry Smith Collective on MPI_Comm 481bd481603SBarry Smith 482bd481603SBarry Smith Input Parameters: 483bd481603SBarry Smith + comm - the communicator that will share the eventually allocated matrix 484bd481603SBarry Smith . nrows - the number of rows in the matrix 485bd481603SBarry Smith - ncols - the number of columns in the matrix 486bd481603SBarry Smith 487bd481603SBarry Smith Output Parameters: 488bd481603SBarry Smith + dnz - the array that will be passed to the matrix preallocation routines 489bd481603SBarry Smith - ozn - the other array passed to the matrix preallocation routines 490bd481603SBarry Smith 491bd481603SBarry Smith 492bd481603SBarry Smith Level: intermediate 493bd481603SBarry Smith 494bd481603SBarry Smith Notes: 495bd481603SBarry Smith See the chapter in the users manual on performance for more details 496bd481603SBarry Smith 497bd481603SBarry Smith Do not malloc or free dnz and onz that is handled internally by these routines 498bd481603SBarry Smith 499bd481603SBarry Smith Concepts: preallocation^Matrix 500bd481603SBarry Smith 501bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(), 502bd481603SBarry Smith MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal() 503bd481603SBarry Smith M*/ 504222b16d4SBarry Smith #define MatPreallocateSymmetricInitialize(comm,nrows,ncols,dnz,onz) 0; \ 505222b16d4SBarry Smith { \ 506222b16d4SBarry Smith int _4_ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__end; \ 507222b16d4SBarry Smith _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\ 508222b16d4SBarry Smith _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\ 509222b16d4SBarry Smith _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr);\ 510222b16d4SBarry Smith _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp; 511222b16d4SBarry Smith 512bd481603SBarry Smith /*MC 513bd481603SBarry Smith MatPreallocateSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be 514bd481603SBarry Smith inserted using a local number of the rows and columns 515bd481603SBarry Smith 516bd481603SBarry Smith Synopsis: 517bd481603SBarry Smith int MatPreallocateSetLocal(ISLocalToGlobalMappping map,int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 518bd481603SBarry Smith 519bd481603SBarry Smith Not Collective 520bd481603SBarry Smith 521bd481603SBarry Smith Input Parameters: 522bd481603SBarry Smith + map - the mapping between local numbering and global numbering 523bd481603SBarry Smith . nrows - the number of rows indicated 524bd481603SBarry Smith . rows - the indices of the rows (these will be mapped in the 525bd481603SBarry Smith . ncols - the number of columns in the matrix 526bd481603SBarry Smith . cols - the columns indicated 527bd481603SBarry Smith . dnz - the array that will be passed to the matrix preallocation routines 528bd481603SBarry Smith - ozn - the other array passed to the matrix preallocation routines 529bd481603SBarry Smith 530bd481603SBarry Smith 531bd481603SBarry Smith Level: intermediate 532bd481603SBarry Smith 533bd481603SBarry Smith Notes: 534bd481603SBarry Smith See the chapter in the users manual on performance for more details 535bd481603SBarry Smith 536bd481603SBarry Smith Do not malloc or free dnz and onz that is handled internally by these routines 537bd481603SBarry Smith 538bd481603SBarry Smith Concepts: preallocation^Matrix 539bd481603SBarry Smith 540bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 541bd481603SBarry Smith MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal() 542bd481603SBarry Smith M*/ 543c4f061fbSSatish Balay #define MatPreallocateSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\ 544c4f061fbSSatish Balay {\ 545c4f061fbSSatish Balay int __l;\ 546ef66eb69SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\ 547ef66eb69SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\ 548c4f061fbSSatish Balay for (__l=0;__l<nrows;__l++) {\ 549ef66eb69SBarry Smith _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\ 550c4f061fbSSatish Balay }\ 551c4f061fbSSatish Balay } 552c4f061fbSSatish Balay 553bd481603SBarry Smith /*MC 554bd481603SBarry Smith MatPreallocateSymmetricSetLocal - Indicates the locations (rows and columns) in the matrix where nonzeros will be 555bd481603SBarry Smith inserted using a local number of the rows and columns 556bd481603SBarry Smith 557bd481603SBarry Smith Synopsis: 558bd481603SBarry Smith int MatPreallocateSymmetricSetLocal(ISLocalToGlobalMappping map,int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 559bd481603SBarry Smith 560bd481603SBarry Smith Not Collective 561bd481603SBarry Smith 562bd481603SBarry Smith Input Parameters: 563bd481603SBarry Smith + map - the mapping between local numbering and global numbering 564bd481603SBarry Smith . nrows - the number of rows indicated 565bd481603SBarry Smith . rows - the indices of the rows (these will be mapped in the 566bd481603SBarry Smith . ncols - the number of columns in the matrix 567bd481603SBarry Smith . cols - the columns indicated 568bd481603SBarry Smith . dnz - the array that will be passed to the matrix preallocation routines 569bd481603SBarry Smith - ozn - the other array passed to the matrix preallocation routines 570bd481603SBarry Smith 571bd481603SBarry Smith 572bd481603SBarry Smith Level: intermediate 573bd481603SBarry Smith 574bd481603SBarry Smith Notes: 575bd481603SBarry Smith See the chapter in the users manual on performance for more details 576bd481603SBarry Smith 577bd481603SBarry Smith Do not malloc or free dnz and onz that is handled internally by these routines 578bd481603SBarry Smith 579bd481603SBarry Smith Concepts: preallocation^Matrix 580bd481603SBarry Smith 581bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 582bd481603SBarry Smith MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal() 583bd481603SBarry Smith M*/ 584d3d32019SBarry Smith #define MatPreallocateSymmetricSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\ 585d3d32019SBarry Smith {\ 586d3d32019SBarry Smith int __l;\ 587d3d32019SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\ 588d3d32019SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\ 589d3d32019SBarry Smith for (__l=0;__l<nrows;__l++) {\ 590d3d32019SBarry Smith _4_ierr = MatPreallocateSymmetricSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\ 591d3d32019SBarry Smith }\ 592d3d32019SBarry Smith } 593d3d32019SBarry Smith 594bd481603SBarry Smith /*MC 595bd481603SBarry Smith MatPreallocateSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be 596bd481603SBarry Smith inserted using a local number of the rows and columns 597bd481603SBarry Smith 598bd481603SBarry Smith Synopsis: 599bd481603SBarry Smith int MatPreallocateSet(int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 600bd481603SBarry Smith 601bd481603SBarry Smith Not Collective 602bd481603SBarry Smith 603bd481603SBarry Smith Input Parameters: 604bd481603SBarry Smith + nrows - the number of rows indicated 605bd481603SBarry Smith . rows - the indices of the rows (these will be mapped in the 606bd481603SBarry Smith . ncols - the number of columns in the matrix 607bd481603SBarry Smith . cols - the columns indicated 608bd481603SBarry Smith . dnz - the array that will be passed to the matrix preallocation routines 609bd481603SBarry Smith - ozn - the other array passed to the matrix preallocation routines 610bd481603SBarry Smith 611bd481603SBarry Smith 612bd481603SBarry Smith Level: intermediate 613bd481603SBarry Smith 614bd481603SBarry Smith Notes: 615bd481603SBarry Smith See the chapter in the users manual on performance for more details 616bd481603SBarry Smith 617bd481603SBarry Smith Do not malloc or free dnz and onz that is handled internally by these routines 618bd481603SBarry Smith 619bd481603SBarry Smith Concepts: preallocation^Matrix 620bd481603SBarry Smith 621bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 622bd481603SBarry Smith MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal() 623bd481603SBarry Smith M*/ 624c4f061fbSSatish Balay #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\ 6257c922b88SBarry Smith { int __i; \ 6267c922b88SBarry Smith for (__i=0; __i<nc; __i++) {\ 6277c922b88SBarry Smith if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \ 6287c922b88SBarry Smith }\ 6297c922b88SBarry Smith dnz[row - __rstart] = nc - onz[row - __rstart];\ 6307c922b88SBarry Smith } 6317c922b88SBarry Smith 632bd481603SBarry Smith /*MC 633bd481603SBarry Smith MatPreallocateSymmetricSet - Indicates the locations (rows and columns) in the matrix where nonzeros will be 634bd481603SBarry Smith inserted using a local number of the rows and columns 635bd481603SBarry Smith 636bd481603SBarry Smith Synopsis: 637bd481603SBarry Smith int MatPreallocateSymmetricSet(int nrows, int *rows,int ncols, int *cols,int *dnz, int *onz) 638bd481603SBarry Smith 639bd481603SBarry Smith Not Collective 640bd481603SBarry Smith 641bd481603SBarry Smith Input Parameters: 642bd481603SBarry Smith + nrows - the number of rows indicated 643bd481603SBarry Smith . rows - the indices of the rows (these will be mapped in the 644bd481603SBarry Smith . ncols - the number of columns in the matrix 645bd481603SBarry Smith . cols - the columns indicated 646bd481603SBarry Smith . dnz - the array that will be passed to the matrix preallocation routines 647bd481603SBarry Smith - ozn - the other array passed to the matrix preallocation routines 648bd481603SBarry Smith 649bd481603SBarry Smith 650bd481603SBarry Smith Level: intermediate 651bd481603SBarry Smith 652bd481603SBarry Smith Notes: 653bd481603SBarry Smith See the chapter in the users manual on performance for more details 654bd481603SBarry Smith 655bd481603SBarry Smith Do not malloc or free dnz and onz that is handled internally by these routines 656bd481603SBarry Smith 657bd481603SBarry Smith Concepts: preallocation^Matrix 658bd481603SBarry Smith 659bd481603SBarry Smith .seealso: MatPreallocateFinalize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateInitialize(), 660bd481603SBarry Smith MatPreallocateInitialize(), MatPreallocateSymmetricSetLocal(), MatPreallocateSetLocal() 661bd481603SBarry Smith M*/ 662d3d32019SBarry Smith #define MatPreallocateSymmetricSet(row,nc,cols,dnz,onz) 0;\ 663d3d32019SBarry Smith { int __i; \ 664d3d32019SBarry Smith for (__i=0; __i<nc; __i++) {\ 665d3d32019SBarry Smith if (cols[__i] >= __end) onz[row - __rstart]++; \ 666d3d32019SBarry Smith else if (cols[__i] >= row) dnz[row - __rstart]++;\ 667d3d32019SBarry Smith }\ 668d3d32019SBarry Smith } 669d3d32019SBarry Smith 670bd481603SBarry Smith /*MC 671bd481603SBarry Smith MatPreallocFinalize - Ends the block of code that will count the number of nonzeros per 672bd481603SBarry Smith row in a matrix providing the data that one can use to correctly preallocate the matrix. 673bd481603SBarry Smith 674bd481603SBarry Smith Synopsis: 675bd481603SBarry Smith int MatPreallocateFinalize(int *dnz, int *onz) 676bd481603SBarry Smith 677bd481603SBarry Smith Collective on MPI_Comm 678bd481603SBarry Smith 679bd481603SBarry Smith Input Parameters: 680bd481603SBarry Smith + dnz - the array that will be passed to the matrix preallocation routines 681bd481603SBarry Smith - ozn - the other array passed to the matrix preallocation routines 682bd481603SBarry Smith 683bd481603SBarry Smith 684bd481603SBarry Smith Level: intermediate 685bd481603SBarry Smith 686bd481603SBarry Smith Notes: 687bd481603SBarry Smith See the chapter in the users manual on performance for more details 688bd481603SBarry Smith 689bd481603SBarry Smith Do not malloc or free dnz and onz that is handled internally by these routines 690bd481603SBarry Smith 691bd481603SBarry Smith Concepts: preallocation^Matrix 692bd481603SBarry Smith 693bd481603SBarry Smith .seealso: MatPreallocateInitialize(), MatPreallocateSet(), MatPreallocateSymmetricSet(), MatPreallocateSetLocal(), 694bd481603SBarry Smith MatPreallocateSymmetricInitialize(), MatPreallocateSymmetricSetLocal() 695bd481603SBarry Smith M*/ 696ef66eb69SBarry Smith #define MatPreallocateFinalize(dnz,onz) 0;_4_ierr = PetscFree(dnz);CHKERRQ(_4_ierr);} 6977c922b88SBarry Smith 698bd481603SBarry Smith 699bd481603SBarry Smith 7007b80b807SBarry Smith /* Routines unique to particular data structures */ 701435da068SBarry Smith EXTERN int MatShellGetContext(Mat,void **); 702435da068SBarry Smith 703268466fbSBarry Smith EXTERN int MatBDiagGetData(Mat,int*,int*,int*[],int*[],PetscScalar***); 704ca01db9bSBarry Smith EXTERN int MatSeqAIJSetColumnIndices(Mat,int[]); 705ca01db9bSBarry Smith EXTERN int MatSeqBAIJSetColumnIndices(Mat,int[]); 706ca01db9bSBarry Smith EXTERN int MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int[],int[],PetscScalar[],Mat*); 7077b80b807SBarry Smith 708ca01db9bSBarry Smith EXTERN int MatSeqBAIJSetPreallocation(Mat,int,int,const int[]); 709ca01db9bSBarry Smith EXTERN int MatSeqSBAIJSetPreallocation(Mat,int,int,const int[]); 710ca01db9bSBarry Smith EXTERN int MatSeqAIJSetPreallocation(Mat,int,const int[]); 711ca01db9bSBarry Smith EXTERN int MatSeqDensePreallocation(Mat,PetscScalar[]); 712ca01db9bSBarry Smith EXTERN int MatSeqBDiagSetPreallocation(Mat,int,int,const int[],PetscScalar*[]); 713ca01db9bSBarry Smith EXTERN int MatSeqDenseSetPreallocation(Mat,PetscScalar[]); 714273d9f13SBarry Smith 715ca01db9bSBarry Smith EXTERN int MatMPIBAIJSetPreallocation(Mat,int,int,const int[],int,const int[]); 716ca01db9bSBarry Smith EXTERN int MatMPISBAIJSetPreallocation(Mat,int,int,const int[],int,const int[]); 717ca01db9bSBarry Smith EXTERN int MatMPIAIJSetPreallocation(Mat,int,const int[],int,const int[]); 718ca01db9bSBarry Smith EXTERN int MatMPIDensePreallocation(Mat,PetscScalar[]); 719ca01db9bSBarry Smith EXTERN int MatMPIBDiagSetPreallocation(Mat,int,int,const int[],PetscScalar*[]); 720ca01db9bSBarry Smith EXTERN int MatMPIAdjSetPreallocation(Mat,int[],int[],int[]); 721ca01db9bSBarry Smith EXTERN int MatMPIDenseSetPreallocation(Mat,PetscScalar[]); 722ca01db9bSBarry Smith EXTERN int MatMPIRowbsSetPreallocation(Mat,int,const int[]); 723268466fbSBarry Smith EXTERN int MatMPIAIJGetSeqAIJ(Mat,Mat*,Mat*,int*[]); 724268466fbSBarry Smith EXTERN int MatMPIBAIJGetSeqBAIJ(Mat,Mat*,Mat*,int*[]); 7253a7fca6bSBarry Smith EXTERN int MatAdicSetLocalFunction(Mat,void (*)(void)); 726273d9f13SBarry Smith 7271b807ce4Svictorle EXTERN int MatSeqDenseSetLDA(Mat,int); 7281b807ce4Svictorle 729ca44d042SBarry Smith EXTERN int MatStoreValues(Mat); 730ca44d042SBarry Smith EXTERN int MatRetrieveValues(Mat); 7312e8a6d31SBarry Smith 7323a7fca6bSBarry Smith EXTERN int MatDAADSetCtx(Mat,void*); 7333a7fca6bSBarry Smith 7347b80b807SBarry Smith /* 7357b80b807SBarry Smith These routines are not usually accessed directly, rather solving is 73694b7f48cSBarry Smith done through the KSP and PC interfaces. 7377b80b807SBarry Smith */ 7387b80b807SBarry Smith 739d9274352SBarry Smith /*E 740d9274352SBarry Smith MatOrderingType - String with the name of a PETSc matrix ordering or the creation function 741d9274352SBarry Smith with an optional dynamic library name, for example 742d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:orderingcreate() 743d9274352SBarry Smith 744d9274352SBarry Smith Level: beginner 745d9274352SBarry Smith 746d9274352SBarry Smith .seealso: MatGetOrdering() 747d9274352SBarry Smith E*/ 74849773a63SBarry Smith #define MatOrderingType char* 749b12f92e5SBarry Smith #define MATORDERING_NATURAL "natural" 750b12f92e5SBarry Smith #define MATORDERING_ND "nd" 751b12f92e5SBarry Smith #define MATORDERING_1WD "1wd" 752b12f92e5SBarry Smith #define MATORDERING_RCM "rcm" 753b12f92e5SBarry Smith #define MATORDERING_QMD "qmd" 754b12f92e5SBarry Smith #define MATORDERING_ROWLENGTH "rowlength" 75562152c8bSBarry Smith #define MATORDERING_DSC_ND "dsc_nd" 75662152c8bSBarry Smith #define MATORDERING_DSC_MMD "dsc_mmd" 75762152c8bSBarry Smith #define MATORDERING_DSC_MDF "dsc_mdf" 758c06d978dSMatthew Knepley #define MATORDERING_CONSTRAINED "constrained" 759c06d978dSMatthew Knepley #define MATORDERING_IDENTITY "identity" 760c06d978dSMatthew Knepley #define MATORDERING_REVERSE "reverse" 761b12f92e5SBarry Smith 762ca44d042SBarry Smith EXTERN int MatGetOrdering(Mat,MatOrderingType,IS*,IS*); 7630e33f6ddSBarry Smith EXTERN int MatOrderingRegister(const char[],const char[],const char[],int(*)(Mat,MatOrderingType,IS*,IS*)); 76430de9b25SBarry Smith 76530de9b25SBarry Smith /*MC 76630de9b25SBarry Smith MatOrderingRegisterDynamic - Adds a new sparse matrix ordering to the 76730de9b25SBarry Smith matrix package. 76830de9b25SBarry Smith 76930de9b25SBarry Smith Synopsis: 77030de9b25SBarry Smith int MatOrderingRegisterDynamic(char *name_ordering,char *path,char *name_create,int (*routine_create)(MatOrdering)) 77130de9b25SBarry Smith 77230de9b25SBarry Smith Not Collective 77330de9b25SBarry Smith 77430de9b25SBarry Smith Input Parameters: 77530de9b25SBarry Smith + sname - name of ordering (for example MATORDERING_ND) 77630de9b25SBarry Smith . path - location of library where creation routine is 77730de9b25SBarry Smith . name - name of function that creates the ordering type,a string 77830de9b25SBarry Smith - function - function pointer that creates the ordering 77930de9b25SBarry Smith 78030de9b25SBarry Smith Level: developer 78130de9b25SBarry Smith 78230de9b25SBarry Smith If dynamic libraries are used, then the fourth input argument (function) 78330de9b25SBarry Smith is ignored. 78430de9b25SBarry Smith 78530de9b25SBarry Smith Sample usage: 78630de9b25SBarry Smith .vb 78730de9b25SBarry Smith MatOrderingRegisterDynamic("my_order",/home/username/my_lib/lib/libO/solaris/mylib.a, 78830de9b25SBarry Smith "MyOrder",MyOrder); 78930de9b25SBarry Smith .ve 79030de9b25SBarry Smith 79130de9b25SBarry Smith Then, your partitioner can be chosen with the procedural interface via 79230de9b25SBarry Smith $ MatOrderingSetType(part,"my_order) 79330de9b25SBarry Smith or at runtime via the option 79430de9b25SBarry Smith $ -pc_ilu_mat_ordering_type my_order 79530de9b25SBarry Smith $ -pc_lu_mat_ordering_type my_order 79630de9b25SBarry Smith 79730de9b25SBarry Smith ${PETSC_ARCH} and ${BOPT} occuring in pathname will be replaced with appropriate values. 79830de9b25SBarry Smith 79930de9b25SBarry Smith .keywords: matrix, ordering, register 80030de9b25SBarry Smith 80130de9b25SBarry Smith .seealso: MatOrderingRegisterDestroy(), MatOrderingRegisterAll() 80230de9b25SBarry Smith M*/ 803aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 804f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0) 805b12f92e5SBarry Smith #else 806f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d) 807b12f92e5SBarry Smith #endif 80830de9b25SBarry Smith 809ca44d042SBarry Smith EXTERN int MatOrderingRegisterDestroy(void); 8100e33f6ddSBarry Smith EXTERN int MatOrderingRegisterAll(const char[]); 8112bad1931SBarry Smith extern PetscTruth MatOrderingRegisterAllCalled; 812b0a32e0cSBarry Smith extern PetscFList MatOrderingList; 813d4fbbf0eSBarry Smith 81487828ca2SBarry Smith EXTERN int MatReorderForNonzeroDiagonal(Mat,PetscReal,IS,IS); 815a2ce50c7SBarry Smith 816d91e6319SBarry Smith /*S 81715e8a5b3SHong Zhang MatFactorInfo - Data based into the matrix factorization routines 818b00f7748SHong Zhang 81915e8a5b3SHong Zhang In Fortran these are simply double precision arrays of size MAT_FACTORINFO_SIZE 820b00f7748SHong Zhang 82115e8a5b3SHong Zhang Notes: These are not usually directly used by users, instead use PC type of LU, ILU, CHOLESKY or ICC. 822b00f7748SHong Zhang 823b00f7748SHong Zhang Level: developer 824b00f7748SHong Zhang 825b380c88cSHong Zhang .seealso: MatLUFactorSymbolic(), MatILUFactorSymbolic(), MatCholeskyFactorSymbolic(), MatICCFactorSymbolic(), MatICCFactor() 826b00f7748SHong Zhang 827b00f7748SHong Zhang S*/ 828b00f7748SHong Zhang typedef struct { 82915e8a5b3SHong Zhang PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 8302cea7109SBarry Smith PetscReal shift; /* if true, shift until positive pivots */ 8312cea7109SBarry Smith PetscReal shift_fraction; /* record shift fraction taken */ 83215e8a5b3SHong Zhang PetscReal diagonal_fill; /* force diagonal to fill in if initially not filled */ 83315e8a5b3SHong Zhang PetscReal dt; /* drop tolerance */ 834b00f7748SHong Zhang PetscReal dtcol; /* tolerance for pivoting */ 83515e8a5b3SHong Zhang PetscReal dtcount; /* maximum nonzeros to be allowed per row */ 836f6275e2eSBarry Smith PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/ 837348344bbSBarry Smith PetscReal levels; /* ICC/ILU(levels) */ 838bcd9e38bSBarry Smith PetscReal pivotinblocks; /* for BAIJ and SBAIJ matrices pivot in factorization on blocks, default 1.0 839bcd9e38bSBarry Smith factorization may be faster if do not pivot */ 84015e8a5b3SHong Zhang PetscReal zeropivot; /* pivot is called zero if less than this */ 84115e8a5b3SHong Zhang } MatFactorInfo; 842ffa6d0a5SLois Curfman McInnes 84315e8a5b3SHong Zhang EXTERN int MatCholeskyFactor(Mat,IS,MatFactorInfo*); 84415e8a5b3SHong Zhang EXTERN int MatCholeskyFactorSymbolic(Mat,IS,MatFactorInfo*,Mat*); 84515e8a5b3SHong Zhang EXTERN int MatCholeskyFactorNumeric(Mat,Mat*); 846b380c88cSHong Zhang EXTERN int MatLUFactor(Mat,IS,IS,MatFactorInfo*); 847b380c88cSHong Zhang EXTERN int MatILUFactor(Mat,IS,IS,MatFactorInfo*); 848b380c88cSHong Zhang EXTERN int MatLUFactorSymbolic(Mat,IS,IS,MatFactorInfo*,Mat*); 849b380c88cSHong Zhang EXTERN int MatILUFactorSymbolic(Mat,IS,IS,MatFactorInfo*,Mat*); 85015e8a5b3SHong Zhang EXTERN int MatICCFactorSymbolic(Mat,IS,MatFactorInfo*,Mat*); 85115e8a5b3SHong Zhang EXTERN int MatICCFactor(Mat,IS,MatFactorInfo*); 852ca44d042SBarry Smith EXTERN int MatLUFactorNumeric(Mat,Mat*); 853b380c88cSHong Zhang EXTERN int MatILUDTFactor(Mat,MatFactorInfo*,IS,IS,Mat *); 8543e0d88b5SBarry Smith EXTERN int MatGetInertia(Mat,int*,int*,int*); 855ca44d042SBarry Smith EXTERN int MatSolve(Mat,Vec,Vec); 856ca44d042SBarry Smith EXTERN int MatForwardSolve(Mat,Vec,Vec); 857ca44d042SBarry Smith EXTERN int MatBackwardSolve(Mat,Vec,Vec); 858ca44d042SBarry Smith EXTERN int MatSolveAdd(Mat,Vec,Vec,Vec); 859ca44d042SBarry Smith EXTERN int MatSolveTranspose(Mat,Vec,Vec); 860ca44d042SBarry Smith EXTERN int MatSolveTransposeAdd(Mat,Vec,Vec,Vec); 861d59c15a7SBarry Smith EXTERN int MatSolves(Mat,Vecs,Vecs); 8628ed539a5SBarry Smith 863ca44d042SBarry Smith EXTERN int MatSetUnfactored(Mat); 864bb5a7306SBarry Smith 865d91e6319SBarry Smith /*E 866d91e6319SBarry Smith MatSORType - What type of (S)SOR to perform 867bb1eb677SSatish Balay 868d91e6319SBarry Smith Level: beginner 869d91e6319SBarry Smith 870d9274352SBarry Smith May be bitwise ORd together 871d9274352SBarry Smith 872d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 873d91e6319SBarry Smith 8744e7234bfSBarry Smith MatSORType may be bitwise ORd together, so do not change the numbers 8754e7234bfSBarry Smith 876d91e6319SBarry Smith .seealso: MatRelax() 877d91e6319SBarry Smith E*/ 878ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3, 879ee50ffe9SBarry Smith SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8, 880ee50ffe9SBarry Smith SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16, 88184cb2905SBarry Smith SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType; 882c14dc6b6SHong Zhang EXTERN int MatRelax(Mat,Vec,PetscReal,MatSORType,PetscReal,int,int,Vec); 8838ed539a5SBarry Smith 884d4fbbf0eSBarry Smith /* 885639f9d9dSBarry Smith These routines are for efficiently computing Jacobians via finite differences. 886639f9d9dSBarry Smith */ 887b12f92e5SBarry Smith 888d9274352SBarry Smith /*E 889d9274352SBarry Smith MatColoringType - String with the name of a PETSc matrix coloring or the creation function 890d9274352SBarry Smith with an optional dynamic library name, for example 891d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:coloringcreate() 892d9274352SBarry Smith 893d9274352SBarry Smith Level: beginner 894d9274352SBarry Smith 895d9274352SBarry Smith .seealso: MatGetColoring() 896d9274352SBarry Smith E*/ 89749773a63SBarry Smith #define MatColoringType char* 898b12f92e5SBarry Smith #define MATCOLORING_NATURAL "natural" 899b12f92e5SBarry Smith #define MATCOLORING_SL "sl" 900b12f92e5SBarry Smith #define MATCOLORING_LF "lf" 901b12f92e5SBarry Smith #define MATCOLORING_ID "id" 902b12f92e5SBarry Smith 903ca44d042SBarry Smith EXTERN int MatGetColoring(Mat,MatColoringType,ISColoring*); 9040e33f6ddSBarry Smith EXTERN int MatColoringRegister(const char[],const char[],const char[],int(*)(Mat,MatColoringType,ISColoring *)); 90530de9b25SBarry Smith 90630de9b25SBarry Smith /*MC 90730de9b25SBarry Smith MatColoringRegisterDynamic - Adds a new sparse matrix coloring to the 90830de9b25SBarry Smith matrix package. 90930de9b25SBarry Smith 91030de9b25SBarry Smith Synopsis: 91130de9b25SBarry Smith int MatColoringRegisterDynamic(char *name_coloring,char *path,char *name_create,int (*routine_create)(MatColoring)) 91230de9b25SBarry Smith 91330de9b25SBarry Smith Not Collective 91430de9b25SBarry Smith 91530de9b25SBarry Smith Input Parameters: 91630de9b25SBarry Smith + sname - name of Coloring (for example MATCOLORING_SL) 91730de9b25SBarry Smith . path - location of library where creation routine is 91830de9b25SBarry Smith . name - name of function that creates the Coloring type, a string 91930de9b25SBarry Smith - function - function pointer that creates the coloring 92030de9b25SBarry Smith 92130de9b25SBarry Smith Level: developer 92230de9b25SBarry Smith 92330de9b25SBarry Smith If dynamic libraries are used, then the fourth input argument (function) 92430de9b25SBarry Smith is ignored. 92530de9b25SBarry Smith 92630de9b25SBarry Smith Sample usage: 92730de9b25SBarry Smith .vb 92830de9b25SBarry Smith MatColoringRegisterDynamic("my_color",/home/username/my_lib/lib/libO/solaris/mylib.a, 92930de9b25SBarry Smith "MyColor",MyColor); 93030de9b25SBarry Smith .ve 93130de9b25SBarry Smith 93230de9b25SBarry Smith Then, your partitioner can be chosen with the procedural interface via 93330de9b25SBarry Smith $ MatColoringSetType(part,"my_color") 93430de9b25SBarry Smith or at runtime via the option 93530de9b25SBarry Smith $ -mat_coloring_type my_color 93630de9b25SBarry Smith 93730de9b25SBarry Smith $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values. 93830de9b25SBarry Smith 93930de9b25SBarry Smith .keywords: matrix, Coloring, register 94030de9b25SBarry Smith 94130de9b25SBarry Smith .seealso: MatColoringRegisterDestroy(), MatColoringRegisterAll() 94230de9b25SBarry Smith M*/ 943aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 944f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0) 945b12f92e5SBarry Smith #else 946f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d) 947b12f92e5SBarry Smith #endif 94830de9b25SBarry Smith 9490e33f6ddSBarry Smith EXTERN int MatColoringRegisterAll(const char[]); 9502bad1931SBarry Smith extern PetscTruth MatColoringRegisterAllCalled; 951ca44d042SBarry Smith EXTERN int MatColoringRegisterDestroy(void); 9524e7234bfSBarry Smith EXTERN int MatColoringPatch(Mat,int,int,const ISColoringValue[],ISColoring*); 953639f9d9dSBarry Smith 954d9274352SBarry Smith /*S 955d9274352SBarry Smith MatFDColoring - Object for computing a sparse Jacobian via finite differences 956d9274352SBarry Smith and coloring 957639f9d9dSBarry Smith 958d9274352SBarry Smith Level: beginner 959d9274352SBarry Smith 960d9274352SBarry Smith Concepts: coloring, sparse Jacobian, finite differences 961d9274352SBarry Smith 962d9274352SBarry Smith .seealso: MatFDColoringCreate() 963d9274352SBarry Smith S*/ 964e2a1c21fSSatish Balay typedef struct _p_MatFDColoring *MatFDColoring; 965639f9d9dSBarry Smith 966ca44d042SBarry Smith EXTERN int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *); 967ca44d042SBarry Smith EXTERN int MatFDColoringDestroy(MatFDColoring); 968b0a32e0cSBarry Smith EXTERN int MatFDColoringView(MatFDColoring,PetscViewer); 969ca44d042SBarry Smith EXTERN int MatFDColoringSetFunction(MatFDColoring,int (*)(void),void*); 97087828ca2SBarry Smith EXTERN int MatFDColoringSetParameters(MatFDColoring,PetscReal,PetscReal); 971ca44d042SBarry Smith EXTERN int MatFDColoringSetFrequency(MatFDColoring,int); 972ca44d042SBarry Smith EXTERN int MatFDColoringGetFrequency(MatFDColoring,int*); 973ca44d042SBarry Smith EXTERN int MatFDColoringSetFromOptions(MatFDColoring); 974ca44d042SBarry Smith EXTERN int MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *); 97587828ca2SBarry Smith EXTERN int MatFDColoringApplyTS(Mat,MatFDColoring,PetscReal,Vec,MatStructure*,void *); 97662152c8bSBarry Smith EXTERN int MatFDColoringSetRecompute(MatFDColoring); 9773a7fca6bSBarry Smith EXTERN int MatFDColoringSetF(MatFDColoring,Vec); 9784e7234bfSBarry Smith EXTERN int MatFDColoringGetPerturbedColumns(MatFDColoring,int*,int*[]); 979639f9d9dSBarry Smith /* 9800752156aSBarry Smith These routines are for partitioning matrices: currently used only 9813eda8832SBarry Smith for adjacency matrix, MatCreateMPIAdj(). 9820752156aSBarry Smith */ 983ca161407SBarry Smith 984d9274352SBarry Smith /*S 985d9274352SBarry Smith MatPartitioning - Object for managing the partitioning of a matrix or graph 986d9274352SBarry Smith 987d9274352SBarry Smith Level: beginner 988d9274352SBarry Smith 989d9274352SBarry Smith Concepts: partitioning 990d9274352SBarry Smith 991743a1026Svictorle .seealso: MatPartitioningCreate(), MatPartitioningType 992d9274352SBarry Smith S*/ 99391e9ee9fSBarry Smith typedef struct _p_MatPartitioning *MatPartitioning; 994d9274352SBarry Smith 995d9274352SBarry Smith /*E 9965bc6e7ccSvictorle MatPartitioningType - String with the name of a PETSc matrix partitioning or the creation function 997d9274352SBarry Smith with an optional dynamic library name, for example 998d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:partitioningcreate() 999d9274352SBarry Smith 1000d9274352SBarry Smith Level: beginner 1001d9274352SBarry Smith 1002b547a13bSvictorle .seealso: MatPartitioningCreate(), MatPartitioning 1003d9274352SBarry Smith E*/ 100449773a63SBarry Smith #define MatPartitioningType char* 10058ba1e511SMatthew Knepley #define MAT_PARTITIONING_CURRENT "current" 10068ba1e511SMatthew Knepley #define MAT_PARTITIONING_PARMETIS "parmetis" 1007ca161407SBarry Smith 1008ca44d042SBarry Smith EXTERN int MatPartitioningCreate(MPI_Comm,MatPartitioning*); 10090e33f6ddSBarry Smith EXTERN int MatPartitioningSetType(MatPartitioning,const MatPartitioningType); 10105bc6e7ccSvictorle EXTERN int MatPartitioningSetNParts(MatPartitioning,int); 1011ca44d042SBarry Smith EXTERN int MatPartitioningSetAdjacency(MatPartitioning,Mat); 10124e7234bfSBarry Smith EXTERN int MatPartitioningSetVertexWeights(MatPartitioning,const int[]); 10134e7234bfSBarry Smith EXTERN int MatPartitioningSetPartitionWeights(MatPartitioning,const PetscReal []); 1014ca44d042SBarry Smith EXTERN int MatPartitioningApply(MatPartitioning,IS*); 1015ca44d042SBarry Smith EXTERN int MatPartitioningDestroy(MatPartitioning); 10162aabb6bbSBarry Smith 10170e33f6ddSBarry Smith EXTERN int MatPartitioningRegister(const char[],const char[],const char[],int(*)(MatPartitioning)); 101830de9b25SBarry Smith 101930de9b25SBarry Smith /*MC 102030de9b25SBarry Smith MatPartitioningRegisterDynamic - Adds a new sparse matrix partitioning to the 102130de9b25SBarry Smith matrix package. 102230de9b25SBarry Smith 102330de9b25SBarry Smith Synopsis: 102430de9b25SBarry Smith int MatPartitioningRegisterDynamic(char *name_partitioning,char *path,char *name_create,int (*routine_create)(MatPartitioning)) 102530de9b25SBarry Smith 102630de9b25SBarry Smith Not Collective 102730de9b25SBarry Smith 102830de9b25SBarry Smith Input Parameters: 102930de9b25SBarry Smith + sname - name of partitioning (for example MAT_PARTITIONING_CURRENT) or parmetis 103030de9b25SBarry Smith . path - location of library where creation routine is 103130de9b25SBarry Smith . name - name of function that creates the partitioning type, a string 103230de9b25SBarry Smith - function - function pointer that creates the partitioning type 103330de9b25SBarry Smith 103430de9b25SBarry Smith Level: developer 103530de9b25SBarry Smith 103630de9b25SBarry Smith If dynamic libraries are used, then the fourth input argument (function) 103730de9b25SBarry Smith is ignored. 103830de9b25SBarry Smith 103930de9b25SBarry Smith Sample usage: 104030de9b25SBarry Smith .vb 104130de9b25SBarry Smith MatPartitioningRegisterDynamic("my_part",/home/username/my_lib/lib/libO/solaris/mylib.a, 104230de9b25SBarry Smith "MyPartCreate",MyPartCreate); 104330de9b25SBarry Smith .ve 104430de9b25SBarry Smith 104530de9b25SBarry Smith Then, your partitioner can be chosen with the procedural interface via 104630de9b25SBarry Smith $ MatPartitioningSetType(part,"my_part") 104730de9b25SBarry Smith or at runtime via the option 104830de9b25SBarry Smith $ -mat_partitioning_type my_part 104930de9b25SBarry Smith 105030de9b25SBarry Smith $PETSC_ARCH and $BOPT occuring in pathname will be replaced with appropriate values. 105130de9b25SBarry Smith 105230de9b25SBarry Smith .keywords: matrix, partitioning, register 105330de9b25SBarry Smith 105430de9b25SBarry Smith .seealso: MatPartitioningRegisterDestroy(), MatPartitioningRegisterAll() 105530de9b25SBarry Smith M*/ 1056aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1057f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0) 10582aabb6bbSBarry Smith #else 1059f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d) 10602aabb6bbSBarry Smith #endif 10612aabb6bbSBarry Smith 10620e33f6ddSBarry Smith EXTERN int MatPartitioningRegisterAll(const char[]); 10632bad1931SBarry Smith extern PetscTruth MatPartitioningRegisterAllCalled; 1064ca44d042SBarry Smith EXTERN int MatPartitioningRegisterDestroy(void); 10652bad1931SBarry Smith 1066b0a32e0cSBarry Smith EXTERN int MatPartitioningView(MatPartitioning,PetscViewer); 1067ca44d042SBarry Smith EXTERN int MatPartitioningSetFromOptions(MatPartitioning); 1068ca44d042SBarry Smith EXTERN int MatPartitioningGetType(MatPartitioning,MatPartitioningType*); 1069ca161407SBarry Smith 1070ca44d042SBarry Smith EXTERN int MatPartitioningParmetisSetCoarseSequential(MatPartitioning); 10710752156aSBarry Smith 10720752156aSBarry Smith /* 10730a835dfdSSatish Balay If you add entries here you must also add them to finclude/petscmat.h 1074d4fbbf0eSBarry Smith */ 10751c1c02c0SLois Curfman McInnes typedef enum { MATOP_SET_VALUES=0, 10761c1c02c0SLois Curfman McInnes MATOP_GET_ROW=1, 10771c1c02c0SLois Curfman McInnes MATOP_RESTORE_ROW=2, 10781c1c02c0SLois Curfman McInnes MATOP_MULT=3, 10791c1c02c0SLois Curfman McInnes MATOP_MULT_ADD=4, 10807c922b88SBarry Smith MATOP_MULT_TRANSPOSE=5, 10817c922b88SBarry Smith MATOP_MULT_TRANSPOSE_ADD=6, 10821c1c02c0SLois Curfman McInnes MATOP_SOLVE=7, 10831c1c02c0SLois Curfman McInnes MATOP_SOLVE_ADD=8, 10847c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE=9, 10857c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE_ADD=10, 10861c1c02c0SLois Curfman McInnes MATOP_LUFACTOR=11, 10871c1c02c0SLois Curfman McInnes MATOP_CHOLESKYFACTOR=12, 10881c1c02c0SLois Curfman McInnes MATOP_RELAX=13, 10891c1c02c0SLois Curfman McInnes MATOP_TRANSPOSE=14, 10901c1c02c0SLois Curfman McInnes MATOP_GETINFO=15, 10911c1c02c0SLois Curfman McInnes MATOP_EQUAL=16, 10921c1c02c0SLois Curfman McInnes MATOP_GET_DIAGONAL=17, 10931c1c02c0SLois Curfman McInnes MATOP_DIAGONAL_SCALE=18, 10941c1c02c0SLois Curfman McInnes MATOP_NORM=19, 10951c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_BEGIN=20, 10961c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_END=21, 10971c1c02c0SLois Curfman McInnes MATOP_COMPRESS=22, 10981c1c02c0SLois Curfman McInnes MATOP_SET_OPTION=23, 10991c1c02c0SLois Curfman McInnes MATOP_ZERO_ENTRIES=24, 11001c1c02c0SLois Curfman McInnes MATOP_ZERO_ROWS=25, 11011c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_SYMBOLIC=26, 11021c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_NUMERIC=27, 11031c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_SYMBOLIC=28, 11041c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_NUMERIC=29, 1105d643ce63SMatthew Knepley MATOP_SETUP_PREALLOCATION=30, 1106d643ce63SMatthew Knepley MATOP_ILUFACTOR_SYMBOLIC=31, 1107d643ce63SMatthew Knepley MATOP_ICCFACTOR_SYMBOLIC=32, 1108d643ce63SMatthew Knepley MATOP_GET_ARRAY=33, 1109d643ce63SMatthew Knepley MATOP_RESTORE_ARRAY=34, 1110d643ce63SMatthew Knepley MATOP_DUPLCIATE=35, 1111d643ce63SMatthew Knepley MATOP_FORWARD_SOLVE=36, 1112d643ce63SMatthew Knepley MATOP_BACKWARD_SOLVE=37, 1113d643ce63SMatthew Knepley MATOP_ILUFACTOR=38, 1114d643ce63SMatthew Knepley MATOP_ICCFACTOR=39, 1115d643ce63SMatthew Knepley MATOP_AXPY=40, 1116d643ce63SMatthew Knepley MATOP_GET_SUBMATRICES=41, 1117d643ce63SMatthew Knepley MATOP_INCREASE_OVERLAP=42, 1118d643ce63SMatthew Knepley MATOP_GET_VALUES=43, 1119d643ce63SMatthew Knepley MATOP_COPY=44, 1120d643ce63SMatthew Knepley MATOP_PRINT_HELP=45, 1121d643ce63SMatthew Knepley MATOP_SCALE=46, 1122d643ce63SMatthew Knepley MATOP_SHIFT=47, 1123d643ce63SMatthew Knepley MATOP_DIAGONAL_SHIFT=48, 1124d643ce63SMatthew Knepley MATOP_ILUDT_FACTOR=49, 1125d643ce63SMatthew Knepley MATOP_GET_BLOCK_SIZE=50, 1126d643ce63SMatthew Knepley MATOP_GET_ROW_IJ=51, 1127d643ce63SMatthew Knepley MATOP_RESTORE_ROW_IJ=52, 1128d643ce63SMatthew Knepley MATOP_GET_COLUMN_IJ=53, 1129d643ce63SMatthew Knepley MATOP_RESTORE_COLUMN_IJ=54, 1130d643ce63SMatthew Knepley MATOP_FDCOLORING_CREATE=55, 1131d643ce63SMatthew Knepley MATOP_COLORING_PATCH=56, 1132d643ce63SMatthew Knepley MATOP_SET_UNFACTORED=57, 1133d643ce63SMatthew Knepley MATOP_PERMUTE=58, 1134d643ce63SMatthew Knepley MATOP_SET_VALUES_BLOCKED=59, 1135d643ce63SMatthew Knepley MATOP_GET_SUBMATRIX=60, 1136d643ce63SMatthew Knepley MATOP_DESTROY=61, 1137d643ce63SMatthew Knepley MATOP_VIEW=62, 1138d643ce63SMatthew Knepley MATOP_GET_MAPS=63, 1139d643ce63SMatthew Knepley MATOP_USE_SCALED_FORM=64, 1140d643ce63SMatthew Knepley MATOP_SCALE_SYSTEM=65, 1141d643ce63SMatthew Knepley MATOP_UNSCALE_SYSTEM=66, 1142d643ce63SMatthew Knepley MATOP_SET_LOCAL_TO_GLOBAL_MAPPING=67, 1143d643ce63SMatthew Knepley MATOP_SET_VALUES_LOCAL=68, 1144d643ce63SMatthew Knepley MATOP_ZERO_ROWS_LOCAL=69, 1145d643ce63SMatthew Knepley MATOP_GET_ROW_MAX=70, 1146d643ce63SMatthew Knepley MATOP_CONVERT=71, 1147d643ce63SMatthew Knepley MATOP_SET_COLORING=72, 1148d643ce63SMatthew Knepley MATOP_SET_VALUES_ADIC=73, 1149d643ce63SMatthew Knepley MATOP_SET_VALUES_ADIFOR=74, 1150d643ce63SMatthew Knepley MATOP_FD_COLORING_APPLY=75, 1151d643ce63SMatthew Knepley MATOP_SET_FROM_OPTIONS=76, 1152d643ce63SMatthew Knepley MATOP_MULT_CONSTRAINED=77, 1153d643ce63SMatthew Knepley MATOP_MULT_TRANSPOSE_CONSTRAINED=78, 1154d643ce63SMatthew Knepley MATOP_ILU_FACTOR_SYMBOLIC_CONSTRAINED=79, 1155d643ce63SMatthew Knepley MATOP_PERMUTE_SPARSIFY=80, 1156d643ce63SMatthew Knepley MATOP_MULT_MULTIPLE=81, 1157d643ce63SMatthew Knepley MATOP_SOLVE_MULTIPLE=82 1158fae171e0SBarry Smith } MatOperation; 1159ca44d042SBarry Smith EXTERN int MatHasOperation(Mat,MatOperation,PetscTruth*); 1160ff8b7a98SSatish Balay EXTERN int MatShellSetOperation(Mat,MatOperation,void(*)(void)); 1161ff8b7a98SSatish Balay EXTERN int MatShellGetOperation(Mat,MatOperation,void(**)(void)); 1162273d9f13SBarry Smith EXTERN int MatShellSetContext(Mat,void*); 1163112a2221SBarry Smith 116490ace30eSBarry Smith /* 116590ace30eSBarry Smith Codes for matrices stored on disk. By default they are 116690ace30eSBarry Smith stored in a universal format. By changing the format with 1167fb9695e5SSatish Balay PetscViewerSetFormat(viewer,PETSC_VIEWER_BINARY_NATIVE); the matrices will 116890ace30eSBarry Smith be stored in a way natural for the matrix, for example dense matrices 116990ace30eSBarry Smith would be stored as dense. Matrices stored this way may only be 117090ace30eSBarry Smith read into matrices of the same time. 117190ace30eSBarry Smith */ 117290ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1 117390ace30eSBarry Smith 11746d053be9SSatish Balay EXTERN int MatMPIBAIJSetHashTableFactor(Mat,PetscReal); 1175ca44d042SBarry Smith EXTERN int MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *); 117608918a0eSSatish Balay EXTERN int MatMPIRowbsGetColor(Mat,ISColoring *); 1177860d1616SSatish Balay 1178d9274352SBarry Smith /*S 1179d9274352SBarry Smith MatNullSpace - Object that removes a null space from a vector, i.e. 1180d9274352SBarry Smith orthogonalizes the vector to a subsapce 1181d9274352SBarry Smith 1182f7a9e4ceSBarry Smith Level: advanced 1183d9274352SBarry Smith 1184d9274352SBarry Smith Concepts: matrix; linear operator, null space 1185d9274352SBarry Smith 11866e1639daSBarry Smith Users manual sections: 11876e1639daSBarry Smith . sec_singular 11886e1639daSBarry Smith 1189d9274352SBarry Smith .seealso: MatNullSpaceCreate() 1190d9274352SBarry Smith S*/ 119174637425SBarry Smith typedef struct _p_MatNullSpace* MatNullSpace; 1192d9274352SBarry Smith 11934e7234bfSBarry Smith EXTERN int MatNullSpaceCreate(MPI_Comm,int,int,const Vec[],MatNullSpace*); 119474637425SBarry Smith EXTERN int MatNullSpaceDestroy(MatNullSpace); 119574637425SBarry Smith EXTERN int MatNullSpaceRemove(MatNullSpace,Vec,Vec*); 119674637425SBarry Smith EXTERN int MatNullSpaceAttach(Mat,MatNullSpace); 119774637425SBarry Smith EXTERN int MatNullSpaceTest(MatNullSpace,Mat); 119874637425SBarry Smith 1199273d9f13SBarry Smith EXTERN int MatReorderingSeqSBAIJ(Mat A,IS isp); 1200273d9f13SBarry Smith EXTERN int MatMPISBAIJSetHashTableFactor(Mat,PetscReal); 1201273d9f13SBarry Smith EXTERN int MatSeqSBAIJSetColumnIndices(Mat,int *); 1202273d9f13SBarry Smith 12035c66b693SKris Buschelman EXTERN int MatMatMult(Mat A,Mat B, Mat *C); 12045c66b693SKris Buschelman EXTERN int MatMatMultSymbolic(Mat A,Mat B,Mat *C); 12055c66b693SKris Buschelman EXTERN int MatMatMultNumeric(Mat A,Mat B,Mat C); 12063f1d51d7SBarry Smith 1207f069c275SSatish Balay EXTERN int MatCreateMAIJ(Mat,int,Mat*); 1208c4f061fbSSatish Balay EXTERN int MatMAIJRedimension(Mat,int,Mat*); 1209c4f061fbSSatish Balay EXTERN int MatMAIJGetAIJ(Mat,Mat*); 1210c4f061fbSSatish Balay 1211b0a32e0cSBarry Smith EXTERN int MatComputeExplicitOperator(Mat,Mat*); 1212b0a32e0cSBarry Smith 12130e33f6ddSBarry Smith EXTERN int MatESISetType(Mat,const char*); 121424a595ddSBarry Smith EXTERN int MatESISetFromOptions(Mat); 121524a595ddSBarry Smith 12162cd6534aSBarry Smith EXTERN int MatDiagonalScaleLocal(Mat,Vec); 121704f1ad80SBarry Smith 12187dbadf16SMatthew Knepley EXTERN int PetscViewerMathematicaPutMatrix(PetscViewer, int, int, PetscReal *); 12197dbadf16SMatthew Knepley EXTERN int PetscViewerMathematicaPutCSRMatrix(PetscViewer, int, int, int *, int *, PetscReal *); 12207dbadf16SMatthew Knepley 1221e82a3eeeSBarry Smith EXTERN int MatUseSpooles_SeqAIJ(Mat); 1222e82a3eeeSBarry Smith EXTERN int MatUseUMFPACK_SeqAIJ(Mat); 1223e82a3eeeSBarry Smith EXTERN int MatUseSuperLU_SeqAIJ(Mat); 1224e82a3eeeSBarry Smith EXTERN int MatUseEssl_SeqAIJ(Mat); 1225e82a3eeeSBarry Smith EXTERN int MatUseLUSOL_SeqAIJ(Mat); 1226e82a3eeeSBarry Smith EXTERN int MatUseMatlab_SeqAIJ(Mat); 1227e82a3eeeSBarry Smith EXTERN int MatUseDXML_SeqAIJ(Mat); 12280889b5dcSvictorle EXTERN int MatUsePETSc_SeqAIJ(Mat); 1229e82a3eeeSBarry Smith EXTERN int MatUseSuperLU_DIST_MPIAIJ(Mat); 1230e82a3eeeSBarry Smith EXTERN int MatUseSpooles_MPIAIJ(Mat); 1231e82a3eeeSBarry Smith EXTERN int MatUseSpooles_SeqSBAIJ(Mat); 1232eee76cafSHong Zhang EXTERN int MatUseSpooles_MPISBAIJ(Mat); 1233eee76cafSHong Zhang EXTERN int MatUseMUMPS_MPIAIJ(Mat); 1234e82a3eeeSBarry Smith 1235e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 12362eac72dbSBarry Smith #endif 1237