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" 82eac72dbSBarry Smith 9d9274352SBarry Smith /*S 10d9274352SBarry Smith Mat - Abstract PETSc matrix object 112eac72dbSBarry Smith 12d91e6319SBarry Smith Level: beginner 13d91e6319SBarry Smith 14d9274352SBarry Smith Concepts: matrix; linear operator 15d9274352SBarry Smith 16d9274352SBarry Smith .seealso: MatCreate(), MatType, MatSetType() 17d9274352SBarry Smith S*/ 18d9274352SBarry Smith typedef struct _p_Mat* Mat; 19d9274352SBarry Smith 20d9274352SBarry Smith /*E 21d9274352SBarry Smith MatType - String with the name of a PETSc matrix or the creation function 22d9274352SBarry Smith with an optional dynamic library name, for example 23d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:mymatcreate() 24d9274352SBarry Smith 25d9274352SBarry Smith Level: beginner 26d9274352SBarry Smith 27d9274352SBarry Smith .seealso: MatSetType(), Mat 28d91e6319SBarry Smith E*/ 29273d9f13SBarry Smith #define MATSAME "same" 30273d9f13SBarry Smith #define MATSEQMAIJ "seqmaij" 31273d9f13SBarry Smith #define MATMPIMAIJ "mpimaij" 32273d9f13SBarry Smith #define MATIS "is" 33273d9f13SBarry Smith #define MATMPIROWBS "mpirowbs" 34273d9f13SBarry Smith #define MATSEQDENSE "seqdense" 35273d9f13SBarry Smith #define MATSEQAIJ "seqaij" 36273d9f13SBarry Smith #define MATMPIAIJ "mpiaij" 37273d9f13SBarry Smith #define MATSHELL "shell" 38273d9f13SBarry Smith #define MATSEQBDIAG "seqbdiag" 39273d9f13SBarry Smith #define MATMPIBDIAG "mpibdiag" 40273d9f13SBarry Smith #define MATMPIDENSE "mpidense" 41273d9f13SBarry Smith #define MATSEQBAIJ "seqbaij" 42273d9f13SBarry Smith #define MATMPIBAIJ "mpibaij" 43273d9f13SBarry Smith #define MATMPIADJ "mpiadj" 44273d9f13SBarry Smith #define MATSEQSBAIJ "seqsbaij" 45273d9f13SBarry Smith #define MATMPISBAIJ "mpisbaij" 46cebc7f6cSBarry Smith #define MATDAAD "daad" 47cebc7f6cSBarry Smith #define MATMFFD "mffd" 486d88219bSBarry Smith #define MATESI "esi" 496d88219bSBarry Smith #define MATPETSCESI "petscesi" 50273d9f13SBarry Smith typedef char* MatType; 51d91e6319SBarry Smith 52c06d978dSMatthew Knepley #define MAT_SER_SEQAIJ_BINARY "seqaij_binary" 53c06d978dSMatthew Knepley #define MAT_SER_MPIAIJ_BINARY "mpiaij_binary" 54c06d978dSMatthew Knepley typedef char *MatSerializeType; 55c06d978dSMatthew Knepley 56c06d978dSMatthew Knepley /* Logging support */ 57552e946dSBarry Smith #define MAT_FILE_COOKIE 1211216 /* used to indicate matrices in binary files */ 58c06d978dSMatthew Knepley extern int MAT_COOKIE; 59c06d978dSMatthew Knepley extern int MAT_FDCOLORING_COOKIE; 608ba1e511SMatthew Knepley extern int MAT_PARTITIONING_COOKIE; 618ba1e511SMatthew Knepley extern int MAT_NULLSPACE_COOKIE; 62d5ba7fb7SMatthew Knepley extern int MAT_Mult, MAT_MultMatrixFree, MAT_MultMultiple, MAT_MultConstrained, MAT_MultAdd, MAT_MultTranspose; 63d5ba7fb7SMatthew Knepley extern int MAT_MultTransposeConstrained, MAT_MultTransposeAdd, MAT_Solve, MAT_SolveMultiple, MAT_SolveAdd, MAT_SolveTranspose; 64d5ba7fb7SMatthew Knepley extern int MAT_SolveTransposeAdd, MAT_Relax, MAT_ForwardSolve, MAT_BackwardSolve, MAT_LUFactor, MAT_LUFactorSymbolic; 65d5ba7fb7SMatthew Knepley extern int MAT_LUFactorNumeric, MAT_CholeskyFactor, MAT_CholeskyFactorSymbolic, MAT_CholeskyFactorNumeric, MAT_ILUFactor; 66d5ba7fb7SMatthew Knepley extern int MAT_ILUFactorSymbolic, MAT_ICCFactorSymbolic, MAT_Copy, MAT_Convert, MAT_Scale, MAT_AssemblyBegin; 67d5ba7fb7SMatthew Knepley extern int MAT_AssemblyEnd, MAT_SetValues, MAT_GetValues, MAT_GetRow, MAT_GetSubMatrices, MAT_GetColoring, MAT_GetOrdering; 68d5ba7fb7SMatthew Knepley extern int MAT_IncreaseOverlap, MAT_Partitioning, MAT_ZeroEntries, MAT_Load, MAT_View, MAT_AXPY, MAT_FDColoringCreate; 69d5ba7fb7SMatthew Knepley extern int MAT_FDColoringApply; 70c06d978dSMatthew Knepley 718ba1e511SMatthew Knepley EXTERN int MatInitializePackage(char *); 72c06d978dSMatthew Knepley 73273d9f13SBarry Smith EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*); 74273d9f13SBarry Smith EXTERN int MatSetType(Mat,MatType); 75273d9f13SBarry Smith EXTERN int MatSetFromOptions(Mat); 76273d9f13SBarry Smith EXTERN int MatSetUpPreallocation(Mat); 77273d9f13SBarry Smith EXTERN int MatRegisterAll(char*); 78273d9f13SBarry Smith EXTERN int MatRegister(char*,char*,char*,int(*)(Mat)); 79c06d978dSMatthew Knepley EXTERN int MatSerializeRegister(const char [], const char [], const char [], int (*)(MPI_Comm, Mat *, PetscViewer, PetscTruth)); 80273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 81273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,0) 82c06d978dSMatthew Knepley #define MatSerializeRegisterDynamic(a,b,c,d) MatSerializeRegister(a,b,c,0) 83273d9f13SBarry Smith #else 84273d9f13SBarry Smith #define MatRegisterDynamic(a,b,c,d) MatRegister(a,b,c,d) 85c06d978dSMatthew Knepley #define MatSerializeRegisterDynamic(a,b,c,d) MatSerializeRegister(a,b,c,d) 86273d9f13SBarry Smith #endif 87273d9f13SBarry Smith extern PetscTruth MatRegisterAllCalled; 88b0a32e0cSBarry Smith extern PetscFList MatList; 8928988994SBarry Smith 90c06d978dSMatthew Knepley EXTERN PetscFList MatSerializeList; 91c06d978dSMatthew Knepley EXTERN int MatSerializeRegisterAll(const char []); 92*65804fbbSSatish Balay EXTERN int MatSerializeRegisterDestroy(void); 93c06d978dSMatthew Knepley EXTERN int MatSerializeRegisterAllCalled; 94c06d978dSMatthew Knepley EXTERN int MatSerialize(MPI_Comm, Mat *, PetscViewer, PetscTruth); 95c06d978dSMatthew Knepley EXTERN int MatSetSerializeType(Mat, MatSerializeType); 96c06d978dSMatthew Knepley 97ca44d042SBarry Smith EXTERN int MatCreate(MPI_Comm,int,int,int,int,Mat*); 9887828ca2SBarry Smith EXTERN int MatCreateSeqDense(MPI_Comm,int,int,PetscScalar*,Mat*); 9987828ca2SBarry Smith EXTERN int MatCreateMPIDense(MPI_Comm,int,int,int,int,PetscScalar*,Mat*); 100ca44d042SBarry Smith EXTERN int MatCreateSeqAIJ(MPI_Comm,int,int,int,int*,Mat*); 101ca44d042SBarry Smith EXTERN int MatCreateMPIAIJ(MPI_Comm,int,int,int,int,int,int*,int,int*,Mat*); 102c4f061fbSSatish Balay EXTERN int MatCreateMPIRowbs(MPI_Comm,int,int,int,int*,Mat*); 10387828ca2SBarry Smith EXTERN int MatCreateSeqBDiag(MPI_Comm,int,int,int,int,int*,PetscScalar**,Mat*); 10487828ca2SBarry Smith EXTERN int MatCreateMPIBDiag(MPI_Comm,int,int,int,int,int,int*,PetscScalar**,Mat*); 105ca44d042SBarry Smith EXTERN int MatCreateSeqBAIJ(MPI_Comm,int,int,int,int,int*,Mat*); 106ca44d042SBarry Smith EXTERN int MatCreateMPIBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*); 107ca44d042SBarry Smith EXTERN int MatCreateMPIAdj(MPI_Comm,int,int,int*,int*,int *,Mat*); 108ca44d042SBarry Smith EXTERN int MatCreateSeqSBAIJ(MPI_Comm,int,int,int,int,int*,Mat*); 109ca44d042SBarry Smith EXTERN int MatCreateMPISBAIJ(MPI_Comm,int,int,int,int,int,int,int*,int,int*,Mat*); 110ca44d042SBarry Smith EXTERN int MatCreateShell(MPI_Comm,int,int,int,int,void *,Mat*); 1113a7fca6bSBarry Smith EXTERN int MatCreateAdic(MPI_Comm,int,int,int,int,int,void (*)(void),Mat*); 112435da068SBarry Smith EXTERN int MatDestroy(Mat); 11321c89e3eSBarry Smith 114ca44d042SBarry Smith EXTERN int MatPrintHelp(Mat); 1158a124369SBarry Smith EXTERN int MatGetPetscMaps(Mat,PetscMap*,PetscMap*); 116ec0117caSBarry Smith 1178ed539a5SBarry Smith /* ------------------------------------------------------------*/ 11887828ca2SBarry Smith EXTERN int MatSetValues(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 11987828ca2SBarry Smith EXTERN int MatSetValuesBlocked(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 12084cb2905SBarry Smith 1212ef4de8bSBarry Smith /*S 1222ef4de8bSBarry Smith MatStencil - Data structure (C struct) for storing information about a single row or 1232ef4de8bSBarry Smith column of a matrix as index on an associated grid. 1242ef4de8bSBarry Smith 1252ef4de8bSBarry Smith Level: beginner 1262ef4de8bSBarry Smith 1272ef4de8bSBarry Smith Concepts: matrix; linear operator 1282ef4de8bSBarry Smith 1292ef4de8bSBarry Smith .seealso: MatSetValuesStencil(), MatSetStencil() 1302ef4de8bSBarry Smith S*/ 131435da068SBarry Smith typedef struct { 132435da068SBarry Smith int k,j,i,c; 133435da068SBarry Smith } MatStencil; 1342ef4de8bSBarry Smith 13587828ca2SBarry Smith EXTERN int MatSetValuesStencil(Mat,int,MatStencil*,int,MatStencil*,PetscScalar*,InsertMode); 13687828ca2SBarry Smith EXTERN int MatSetValuesBlockedStencil(Mat,int,MatStencil*,int,MatStencil*,PetscScalar*,InsertMode); 137435da068SBarry Smith EXTERN int MatSetStencil(Mat,int,int*,int*,int); 138435da068SBarry Smith 1393a7fca6bSBarry Smith EXTERN int MatSetColoring(Mat,ISColoring); 1403a7fca6bSBarry Smith EXTERN int MatSetValuesAdic(Mat,void*); 1413a7fca6bSBarry Smith EXTERN int MatSetValuesAdifor(Mat,int,void*); 1423a7fca6bSBarry Smith 143d91e6319SBarry Smith /*E 144d91e6319SBarry Smith MatAssemblyType - Indicates if the matrix is now to be used, or if you plan 145d91e6319SBarry Smith to continue to add values to it 146d91e6319SBarry Smith 147d91e6319SBarry Smith Level: beginner 148d91e6319SBarry Smith 149d91e6319SBarry Smith .seealso: MatAssemblyBegin(), MatAssemblyEnd() 150d91e6319SBarry Smith E*/ 1516d4a8577SBarry Smith typedef enum {MAT_FLUSH_ASSEMBLY=1,MAT_FINAL_ASSEMBLY=0} MatAssemblyType; 152ca44d042SBarry Smith EXTERN int MatAssemblyBegin(Mat,MatAssemblyType); 153ca44d042SBarry Smith EXTERN int MatAssemblyEnd(Mat,MatAssemblyType); 154ca44d042SBarry Smith EXTERN int MatAssembled(Mat,PetscTruth*); 1554f9c727eSBarry Smith 156b951964fSBarry Smith #define MatSetValue(v,i,j,va,mode) \ 157ea709b57SSatish Balay 0; {int _ierr,_row = i,_col = j; PetscScalar _va = va; \ 158b951964fSBarry Smith _ierr = MatSetValues(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \ 159b951964fSBarry Smith } 160ea06a074SBarry Smith #define MatGetValue(v,i,j,va) \ 161d91e6319SBarry Smith 0; {int _ierr,_row = i,_col = j; \ 162ea06a074SBarry Smith _ierr = MatGetValues(v,1,&_row,1,&_col,&va);CHKERRQ(_ierr); \ 163ea06a074SBarry Smith } 164d91e6319SBarry Smith #define MatSetValueLocal(v,i,j,va,mode) \ 165ea709b57SSatish Balay 0; {int _ierr,_row = i,_col = j; PetscScalar _va = va; \ 166d91e6319SBarry Smith _ierr = MatSetValuesLocal(v,1,&_row,1,&_col,&_va,mode);CHKERRQ(_ierr); \ 167d91e6319SBarry Smith } 168d91e6319SBarry Smith /*E 169d91e6319SBarry Smith MatOption - Options that may be set for a matrix and its behavior or storage 170d91e6319SBarry Smith 171d91e6319SBarry Smith Level: beginner 172d91e6319SBarry Smith 1730a835dfdSSatish Balay Any additions/changes here MUST also be made in include/finclude/petscmat.h 174d91e6319SBarry Smith 175d91e6319SBarry Smith .seealso: MatSetOption() 176d91e6319SBarry Smith E*/ 1776d4a8577SBarry Smith typedef enum {MAT_ROW_ORIENTED=1,MAT_COLUMN_ORIENTED=2,MAT_ROWS_SORTED=4, 1786d4a8577SBarry Smith MAT_COLUMNS_SORTED=8,MAT_NO_NEW_NONZERO_LOCATIONS=16, 1796d4a8577SBarry Smith MAT_YES_NEW_NONZERO_LOCATIONS=32,MAT_SYMMETRIC=64, 1806ca9ecd3SBarry Smith MAT_STRUCTURALLY_SYMMETRIC=65,MAT_NO_NEW_DIAGONALS=66, 1816ca9ecd3SBarry Smith MAT_YES_NEW_DIAGONALS=67,MAT_INODE_LIMIT_1=68,MAT_INODE_LIMIT_2=69, 1826ca9ecd3SBarry Smith MAT_INODE_LIMIT_3=70,MAT_INODE_LIMIT_4=71,MAT_INODE_LIMIT_5=72, 1836ca9ecd3SBarry Smith MAT_IGNORE_OFF_PROC_ENTRIES=73,MAT_ROWS_UNSORTED=74, 1844787f768SSatish Balay MAT_COLUMNS_UNSORTED=75,MAT_NEW_NONZERO_LOCATION_ERR=76, 1857c922b88SBarry Smith MAT_NEW_NONZERO_ALLOCATION_ERR=77,MAT_USE_HASH_TABLE=78, 1862bad1931SBarry Smith MAT_KEEP_ZEROED_ROWS=79,MAT_IGNORE_ZERO_ENTRIES=80,MAT_USE_INODES=81, 1878b43beb6SKris Buschelman MAT_DO_NOT_USE_INODES=82,MAT_USE_SINGLE_PRECISION_SOLVES=83} MatOption; 188ca44d042SBarry Smith EXTERN int MatSetOption(Mat,MatOption); 189273d9f13SBarry Smith EXTERN int MatGetType(Mat,MatType*); 19084cb2905SBarry Smith 19187828ca2SBarry Smith EXTERN int MatGetValues(Mat,int,int*,int,int*,PetscScalar*); 19287828ca2SBarry Smith EXTERN int MatGetRow(Mat,int,int *,int **,PetscScalar**); 19387828ca2SBarry Smith EXTERN int MatRestoreRow(Mat,int,int *,int **,PetscScalar**); 19487828ca2SBarry Smith EXTERN int MatGetColumn(Mat,int,int *,int **,PetscScalar**); 19587828ca2SBarry Smith EXTERN int MatRestoreColumn(Mat,int,int *,int **,PetscScalar**); 196ca44d042SBarry Smith EXTERN int MatGetColumnVector(Mat,Vec,int); 19787828ca2SBarry Smith EXTERN int MatGetArray(Mat,PetscScalar **); 19887828ca2SBarry Smith EXTERN int MatRestoreArray(Mat,PetscScalar **); 199ca44d042SBarry Smith EXTERN int MatGetBlockSize(Mat,int *); 2007b80b807SBarry Smith 201ca44d042SBarry Smith EXTERN int MatMult(Mat,Vec,Vec); 202ca44d042SBarry Smith EXTERN int MatMultAdd(Mat,Vec,Vec,Vec); 203ca44d042SBarry Smith EXTERN int MatMultTranspose(Mat,Vec,Vec); 204ca44d042SBarry Smith EXTERN int MatMultTransposeAdd(Mat,Vec,Vec,Vec); 205c06d978dSMatthew Knepley EXTERN int MatMultConstrained(Mat,Vec,Vec); 2066d0dc95fSMatthew Knepley EXTERN int MatMultTransposeConstrained(Mat,Vec,Vec); 2072eac72dbSBarry Smith 208d91e6319SBarry Smith /*E 209d91e6319SBarry Smith MatDuplicateOption - Indicates if a duplicated sparse matrix should have 210d91e6319SBarry Smith its numerical values copied over or just its nonzero structure. 211d91e6319SBarry Smith 212d91e6319SBarry Smith Level: beginner 213d91e6319SBarry Smith 214d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 215d91e6319SBarry Smith 216d91e6319SBarry Smith .seealso: MatDuplicate() 217d91e6319SBarry Smith E*/ 2182e8a6d31SBarry Smith typedef enum {MAT_DO_NOT_COPY_VALUES,MAT_COPY_VALUES} MatDuplicateOption; 2192e8a6d31SBarry Smith 220273d9f13SBarry Smith EXTERN int MatConvertRegister(char*,char*,char*,int (*)(Mat,MatType,Mat*)); 221273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 222273d9f13SBarry Smith #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,0) 223273d9f13SBarry Smith #else 224273d9f13SBarry Smith #define MatConvertRegisterDynamic(a,b,c,d) MatConvertRegister(a,b,c,d) 225273d9f13SBarry Smith #endif 226273d9f13SBarry Smith EXTERN int MatConvertRegisterAll(char*); 227273d9f13SBarry Smith EXTERN int MatConvertRegisterDestroy(void); 228273d9f13SBarry Smith extern PetscTruth MatConvertRegisterAllCalled; 229b0a32e0cSBarry Smith extern PetscFList MatConvertList; 230ca44d042SBarry Smith EXTERN int MatConvert(Mat,MatType,Mat*); 231ca44d042SBarry Smith EXTERN int MatDuplicate(Mat,MatDuplicateOption,Mat*); 23294a9d846SBarry Smith 233d91e6319SBarry Smith /*E 234d91e6319SBarry Smith MatStructure - Indicates if the matrix has the same nonzero structure 235d91e6319SBarry Smith 236d91e6319SBarry Smith Level: beginner 237d91e6319SBarry Smith 238d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 239d91e6319SBarry Smith 240d91e6319SBarry Smith .seealso: MatCopy(), SLESSetOperators(), PCSetOperators() 241d91e6319SBarry Smith E*/ 242cb5b572fSBarry Smith typedef enum {SAME_NONZERO_PATTERN,DIFFERENT_NONZERO_PATTERN,SAME_PRECONDITIONER} MatStructure; 243cb5b572fSBarry Smith 244ca44d042SBarry Smith EXTERN int MatCopy(Mat,Mat,MatStructure); 245b0a32e0cSBarry Smith EXTERN int MatView(Mat,PetscViewer); 246273d9f13SBarry Smith 247b0a32e0cSBarry Smith EXTERN int MatLoadRegister(char*,char*,char*,int (*)(PetscViewer,MatType,Mat*)); 248273d9f13SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 249273d9f13SBarry Smith #define MatLoadRegisterDynamic(a,b,c,d) MatLoadRegister(a,b,c,0) 250273d9f13SBarry Smith #else 251273d9f13SBarry Smith #define MatLoadRegisterDynamic(a,b,c,d) MatLoadRegister(a,b,c,d) 252273d9f13SBarry Smith #endif 253273d9f13SBarry Smith EXTERN int MatLoadRegisterAll(char*); 254273d9f13SBarry Smith EXTERN int MatLoadRegisterDestroy(void); 255273d9f13SBarry Smith extern PetscTruth MatLoadRegisterAllCalled; 256b0a32e0cSBarry Smith extern PetscFList MatLoadList; 257b0a32e0cSBarry Smith EXTERN int MatLoad(PetscViewer,MatType,Mat*); 2587b80b807SBarry Smith 259ca44d042SBarry Smith EXTERN int MatGetRowIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *); 260ca44d042SBarry Smith EXTERN int MatRestoreRowIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *); 261ca44d042SBarry Smith EXTERN int MatGetColumnIJ(Mat,int,PetscTruth,int*,int **,int **,PetscTruth *); 262ca44d042SBarry Smith EXTERN int MatRestoreColumnIJ(Mat,int,PetscTruth,int *,int **,int **,PetscTruth *); 263d4fbbf0eSBarry Smith 264d91e6319SBarry Smith /*S 265d91e6319SBarry Smith MatInfo - Context of matrix information, used with MatGetInfo() 266d91e6319SBarry Smith 267d91e6319SBarry Smith In Fortran this is simply a double precision array of dimension MAT_INFO_SIZE 268d91e6319SBarry Smith 269d91e6319SBarry Smith Level: intermediate 270d91e6319SBarry Smith 271d91e6319SBarry Smith Concepts: matrix^nonzero information 272d91e6319SBarry Smith 273d9274352SBarry Smith .seealso: MatGetInfo(), MatInfoType 274d91e6319SBarry Smith S*/ 2754e220ebcSLois Curfman McInnes typedef struct { 276b0a32e0cSBarry Smith PetscLogDouble rows_global,columns_global; /* number of global rows and columns */ 277b0a32e0cSBarry Smith PetscLogDouble rows_local,columns_local; /* number of local rows and columns */ 278b0a32e0cSBarry Smith PetscLogDouble block_size; /* block size */ 279b0a32e0cSBarry Smith PetscLogDouble nz_allocated,nz_used,nz_unneeded; /* number of nonzeros */ 280b0a32e0cSBarry Smith PetscLogDouble memory; /* memory allocated */ 281b0a32e0cSBarry Smith PetscLogDouble assemblies; /* number of matrix assemblies called */ 282b0a32e0cSBarry Smith PetscLogDouble mallocs; /* number of mallocs during MatSetValues() */ 283b0a32e0cSBarry Smith PetscLogDouble fill_ratio_given,fill_ratio_needed; /* fill ratio for LU/ILU */ 284b0a32e0cSBarry Smith PetscLogDouble factor_mallocs; /* number of mallocs during factorization */ 2854e220ebcSLois Curfman McInnes } MatInfo; 2864e220ebcSLois Curfman McInnes 287d9274352SBarry Smith /*E 288d9274352SBarry Smith MatInfoType - Indicates if you want information about the local part of the matrix, 289d9274352SBarry Smith the entire parallel matrix or the maximum over all the local parts. 290d9274352SBarry Smith 291d9274352SBarry Smith Level: beginner 292d9274352SBarry Smith 293d9274352SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 294d9274352SBarry Smith 295d9274352SBarry Smith .seealso: MatGetInfo(), MatInfo 296d9274352SBarry Smith E*/ 2977b80b807SBarry Smith typedef enum {MAT_LOCAL=1,MAT_GLOBAL_MAX=2,MAT_GLOBAL_SUM=3} MatInfoType; 298ca44d042SBarry Smith EXTERN int MatGetInfo(Mat,MatInfoType,MatInfo*); 299ca44d042SBarry Smith EXTERN int MatValid(Mat,PetscTruth*); 300ca44d042SBarry Smith EXTERN int MatGetDiagonal(Mat,Vec); 301273d9f13SBarry Smith EXTERN int MatGetRowMax(Mat,Vec); 302ca44d042SBarry Smith EXTERN int MatTranspose(Mat,Mat*); 303ca44d042SBarry Smith EXTERN int MatPermute(Mat,IS,IS,Mat *); 304bf1d55d4SSatish Balay EXTERN int MatPermuteSparsify(Mat,int,PetscReal,PetscReal,IS,IS,Mat *); 305ca44d042SBarry Smith EXTERN int MatDiagonalScale(Mat,Vec,Vec); 30606ef90c2SBarry Smith EXTERN int MatDiagonalSet(Mat,Vec,InsertMode); 307ca44d042SBarry Smith EXTERN int MatEqual(Mat,Mat,PetscTruth*); 3087b80b807SBarry Smith 30987828ca2SBarry Smith EXTERN int MatNorm(Mat,NormType,PetscReal *); 310ca44d042SBarry Smith EXTERN int MatZeroEntries(Mat); 31187828ca2SBarry Smith EXTERN int MatZeroRows(Mat,IS,PetscScalar*); 31287828ca2SBarry Smith EXTERN int MatZeroColumns(Mat,IS,PetscScalar*); 3137b80b807SBarry Smith 314ca44d042SBarry Smith EXTERN int MatUseScaledForm(Mat,PetscTruth); 315ca44d042SBarry Smith EXTERN int MatScaleSystem(Mat,Vec,Vec); 316ca44d042SBarry Smith EXTERN int MatUnScaleSystem(Mat,Vec,Vec); 3175ef9f2a5SBarry Smith 318ca44d042SBarry Smith EXTERN int MatGetSize(Mat,int*,int*); 319ca44d042SBarry Smith EXTERN int MatGetLocalSize(Mat,int*,int*); 320ca44d042SBarry Smith EXTERN int MatGetOwnershipRange(Mat,int*,int*); 3217b80b807SBarry Smith 322d91e6319SBarry Smith /*E 323d91e6319SBarry Smith MatReuse - Indicates if matrices obtained from a previous call to MatGetSubMatrices() 324d91e6319SBarry Smith or MatGetSubMatrix() are to be reused to store the new matrix values. 325d91e6319SBarry Smith 326d91e6319SBarry Smith Level: beginner 327d91e6319SBarry Smith 328d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 329d91e6319SBarry Smith 330d91e6319SBarry Smith .seealso: MatGetSubMatrices(), MatGetSubMatrix(), MatDestroyMatrices() 331d91e6319SBarry Smith E*/ 3327b2a1423SBarry Smith typedef enum {MAT_INITIAL_MATRIX,MAT_REUSE_MATRIX} MatReuse; 333ca44d042SBarry Smith EXTERN int MatGetSubMatrices(Mat,int,IS *,IS *,MatReuse,Mat **); 334ca44d042SBarry Smith EXTERN int MatDestroyMatrices(int,Mat **); 335ca44d042SBarry Smith EXTERN int MatGetSubMatrix(Mat,IS,IS,int,MatReuse,Mat *); 3368efafbd8SBarry Smith 337ca44d042SBarry Smith EXTERN int MatIncreaseOverlap(Mat,int,IS *,int); 3387b80b807SBarry Smith 339607cd303SBarry Smith EXTERN int MatAXPY(PetscScalar *,Mat,Mat,MatStructure); 34087828ca2SBarry Smith EXTERN int MatAYPX(PetscScalar *,Mat,Mat); 341ca44d042SBarry Smith EXTERN int MatCompress(Mat); 3427b80b807SBarry Smith 34387828ca2SBarry Smith EXTERN int MatScale(PetscScalar *,Mat); 34487828ca2SBarry Smith EXTERN int MatShift(PetscScalar *,Mat); 345052efed2SBarry Smith 346ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMapping(Mat,ISLocalToGlobalMapping); 347ca44d042SBarry Smith EXTERN int MatSetLocalToGlobalMappingBlock(Mat,ISLocalToGlobalMapping); 34887828ca2SBarry Smith EXTERN int MatZeroRowsLocal(Mat,IS,PetscScalar*); 34987828ca2SBarry Smith EXTERN int MatSetValuesLocal(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 35087828ca2SBarry Smith EXTERN int MatSetValuesBlockedLocal(Mat,int,int*,int,int*,PetscScalar*,InsertMode); 35190f02eecSBarry Smith 352ca44d042SBarry Smith EXTERN int MatSetStashInitialSize(Mat,int,int); 353649db694SBarry Smith 354ca44d042SBarry Smith EXTERN int MatInterpolateAdd(Mat,Vec,Vec,Vec); 355ca44d042SBarry Smith EXTERN int MatInterpolate(Mat,Vec,Vec); 356ca44d042SBarry Smith EXTERN int MatRestrict(Mat,Vec,Vec); 3577c922b88SBarry Smith 3587c922b88SBarry Smith /* 359c4f061fbSSatish Balay These three (or four) macros MUST be used together. The third one closes the open { of the first one 3607c922b88SBarry Smith */ 361c4f061fbSSatish Balay #define MatPreallocateInitialize(comm,nrows,ncols,dnz,onz) 0; \ 3627c922b88SBarry Smith { \ 363ef66eb69SBarry Smith int _4_ierr,__tmp = (nrows),__ctmp = (ncols),__rstart,__start,__end; \ 364ef66eb69SBarry Smith _4_ierr = PetscMalloc(2*__tmp*sizeof(int),&dnz);CHKERRQ(_4_ierr);onz = dnz + __tmp;\ 365ef66eb69SBarry Smith _4_ierr = PetscMemzero(dnz,2*__tmp*sizeof(int));CHKERRQ(_4_ierr);\ 366ef66eb69SBarry Smith _4_ierr = MPI_Scan(&__ctmp,&__end,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __start = __end - __ctmp;\ 367ef66eb69SBarry Smith _4_ierr = MPI_Scan(&__tmp,&__rstart,1,MPI_INT,MPI_SUM,comm);CHKERRQ(_4_ierr); __rstart = __rstart - __tmp; 3687c922b88SBarry Smith 369c4f061fbSSatish Balay #define MatPreallocateSetLocal(map,nrows,rows,ncols,cols,dnz,onz) 0;\ 370c4f061fbSSatish Balay {\ 371c4f061fbSSatish Balay int __l;\ 372ef66eb69SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,nrows,rows,rows);CHKERRQ(_4_ierr);\ 373ef66eb69SBarry Smith _4_ierr = ISLocalToGlobalMappingApply(map,ncols,cols,cols);CHKERRQ(_4_ierr);\ 374c4f061fbSSatish Balay for (__l=0;__l<nrows;__l++) {\ 375ef66eb69SBarry Smith _4_ierr = MatPreallocateSet((rows)[__l],ncols,cols,dnz,onz);CHKERRQ(_4_ierr);\ 376c4f061fbSSatish Balay }\ 377c4f061fbSSatish Balay } 378c4f061fbSSatish Balay 379c4f061fbSSatish Balay #define MatPreallocateSet(row,nc,cols,dnz,onz) 0;\ 3807c922b88SBarry Smith { int __i; \ 3817c922b88SBarry Smith for (__i=0; __i<nc; __i++) {\ 3827c922b88SBarry Smith if (cols[__i] < __start || cols[__i] >= __end) onz[row - __rstart]++; \ 3837c922b88SBarry Smith }\ 3847c922b88SBarry Smith dnz[row - __rstart] = nc - onz[row - __rstart];\ 3857c922b88SBarry Smith } 3867c922b88SBarry Smith 387ef66eb69SBarry Smith #define MatPreallocateFinalize(dnz,onz) 0;_4_ierr = PetscFree(dnz);CHKERRQ(_4_ierr);} 3887c922b88SBarry Smith 3897b80b807SBarry Smith /* Routines unique to particular data structures */ 390435da068SBarry Smith EXTERN int MatShellGetContext(Mat,void **); 391435da068SBarry Smith 39287828ca2SBarry Smith EXTERN int MatBDiagGetData(Mat,int*,int*,int**,int**,PetscScalar***); 393ca44d042SBarry Smith EXTERN int MatSeqAIJSetColumnIndices(Mat,int *); 394ca44d042SBarry Smith EXTERN int MatSeqBAIJSetColumnIndices(Mat,int *); 39587828ca2SBarry Smith EXTERN int MatCreateSeqAIJWithArrays(MPI_Comm,int,int,int*,int*,PetscScalar *,Mat*); 3967b80b807SBarry Smith 397273d9f13SBarry Smith EXTERN int MatSeqBAIJSetPreallocation(Mat,int,int,int*); 398273d9f13SBarry Smith EXTERN int MatSeqSBAIJSetPreallocation(Mat,int,int,int*); 399273d9f13SBarry Smith EXTERN int MatSeqAIJSetPreallocation(Mat,int,int*); 40087828ca2SBarry Smith EXTERN int MatSeqDensePreallocation(Mat,PetscScalar*); 40187828ca2SBarry Smith EXTERN int MatSeqBDiagSetPreallocation(Mat,int,int,int*,PetscScalar**); 40287828ca2SBarry Smith EXTERN int MatSeqDenseSetPreallocation(Mat,PetscScalar*); 403273d9f13SBarry Smith 404273d9f13SBarry Smith EXTERN int MatMPIBAIJSetPreallocation(Mat,int,int,int*,int,int*); 405273d9f13SBarry Smith EXTERN int MatMPISBAIJSetPreallocation(Mat,int,int,int*,int,int*); 406273d9f13SBarry Smith EXTERN int MatMPIAIJSetPreallocation(Mat,int,int*,int,int*); 40787828ca2SBarry Smith EXTERN int MatMPIDensePreallocation(Mat,PetscScalar*); 40887828ca2SBarry Smith EXTERN int MatMPIBDiagSetPreallocation(Mat,int,int,int*,PetscScalar**); 409273d9f13SBarry Smith EXTERN int MatMPIAdjSetPreallocation(Mat,int*,int*,int*); 41087828ca2SBarry Smith EXTERN int MatMPIDenseSetPreallocation(Mat,PetscScalar*); 411273d9f13SBarry Smith EXTERN int MatMPIRowbsSetPreallocation(Mat,int,int*); 412435da068SBarry Smith EXTERN int MatMPIAIJGetSeqAIJ(Mat,Mat*,Mat*,int**); 413435da068SBarry Smith EXTERN int MatMPIBAIJGetSeqBAIJ(Mat,Mat*,Mat*,int**); 4143a7fca6bSBarry Smith EXTERN int MatAdicSetLocalFunction(Mat,void (*)(void)); 415273d9f13SBarry Smith 416ca44d042SBarry Smith EXTERN int MatStoreValues(Mat); 417ca44d042SBarry Smith EXTERN int MatRetrieveValues(Mat); 4182e8a6d31SBarry Smith 4193a7fca6bSBarry Smith EXTERN int MatDAADSetCtx(Mat,void*); 4203a7fca6bSBarry Smith 4217b80b807SBarry Smith /* 4227b80b807SBarry Smith These routines are not usually accessed directly, rather solving is 4237b80b807SBarry Smith done through the SLES, KSP and PC interfaces. 4247b80b807SBarry Smith */ 4257b80b807SBarry Smith 426d9274352SBarry Smith /*E 427d9274352SBarry Smith MatOrderingType - String with the name of a PETSc matrix ordering or the creation function 428d9274352SBarry Smith with an optional dynamic library name, for example 429d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:orderingcreate() 430d9274352SBarry Smith 431d9274352SBarry Smith Level: beginner 432d9274352SBarry Smith 433d9274352SBarry Smith .seealso: MatGetOrdering() 434d9274352SBarry Smith E*/ 435b12f92e5SBarry Smith typedef char* MatOrderingType; 436b12f92e5SBarry Smith #define MATORDERING_NATURAL "natural" 437b12f92e5SBarry Smith #define MATORDERING_ND "nd" 438b12f92e5SBarry Smith #define MATORDERING_1WD "1wd" 439b12f92e5SBarry Smith #define MATORDERING_RCM "rcm" 440b12f92e5SBarry Smith #define MATORDERING_QMD "qmd" 441b12f92e5SBarry Smith #define MATORDERING_ROWLENGTH "rowlength" 44262152c8bSBarry Smith #define MATORDERING_DSC_ND "dsc_nd" 44362152c8bSBarry Smith #define MATORDERING_DSC_MMD "dsc_mmd" 44462152c8bSBarry Smith #define MATORDERING_DSC_MDF "dsc_mdf" 445c06d978dSMatthew Knepley #define MATORDERING_CONSTRAINED "constrained" 446c06d978dSMatthew Knepley #define MATORDERING_IDENTITY "identity" 447c06d978dSMatthew Knepley #define MATORDERING_REVERSE "reverse" 448b12f92e5SBarry Smith 449ca44d042SBarry Smith EXTERN int MatGetOrdering(Mat,MatOrderingType,IS*,IS*); 450ca44d042SBarry Smith EXTERN int MatOrderingRegister(char*,char*,char*,int(*)(Mat,MatOrderingType,IS*,IS*)); 451aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 452f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,0) 453b12f92e5SBarry Smith #else 454f1af5d2fSBarry Smith #define MatOrderingRegisterDynamic(a,b,c,d) MatOrderingRegister(a,b,c,d) 455b12f92e5SBarry Smith #endif 456ca44d042SBarry Smith EXTERN int MatOrderingRegisterDestroy(void); 457ca44d042SBarry Smith EXTERN int MatOrderingRegisterAll(char*); 4582bad1931SBarry Smith extern PetscTruth MatOrderingRegisterAllCalled; 459b0a32e0cSBarry Smith extern PetscFList MatOrderingList; 460d4fbbf0eSBarry Smith 46187828ca2SBarry Smith EXTERN int MatReorderForNonzeroDiagonal(Mat,PetscReal,IS,IS); 462a2ce50c7SBarry Smith 46387828ca2SBarry Smith EXTERN int MatCholeskyFactor(Mat,IS,PetscReal); 46487828ca2SBarry Smith EXTERN int MatCholeskyFactorSymbolic(Mat,IS,PetscReal,Mat*); 465ca44d042SBarry Smith EXTERN int MatCholeskyFactorNumeric(Mat,Mat*); 466a2ce50c7SBarry Smith 467d91e6319SBarry Smith /*S 468d91e6319SBarry Smith MatILUInfo - Data based into the matrix ILU factorization routines 4695ef9f2a5SBarry Smith 470d91e6319SBarry Smith In Fortran these are simply double precision arrays of size MAT_ILUINFO_SIZE 47114822f30SBarry Smith 472d91e6319SBarry Smith Notes: These are not usually directly used by users, instead use the PC type of ILU 473d91e6319SBarry Smith All entries are double precision. 474d91e6319SBarry Smith 475d91e6319SBarry Smith Level: developer 476d91e6319SBarry Smith 477d91e6319SBarry Smith .seealso: MatILUFactorSymbolic(), MatILUFactor(), MatLUInfo, MatCholeskyInfo 478d91e6319SBarry Smith 479d91e6319SBarry Smith S*/ 4805ef9f2a5SBarry Smith typedef struct { 481f6275e2eSBarry Smith PetscReal levels; /* ILU(levels) */ 482f6275e2eSBarry Smith PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix*/ 483f6275e2eSBarry Smith PetscReal diagonal_fill; /* force diagonal to fill in if initially not filled */ 484f6275e2eSBarry Smith PetscReal dt; /* drop tolerance */ 485f6275e2eSBarry Smith PetscReal dtcol; /* tolerance for pivoting */ 486f6275e2eSBarry Smith PetscReal dtcount; /* maximum nonzeros to be allowed per row */ 487f6275e2eSBarry Smith PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 488f6275e2eSBarry Smith PetscReal damp; /* if is 1.0 and factorization fails, damp until successful */ 489f6275e2eSBarry Smith PetscReal zeropivot; /* pivot is called zero if less than this */ 4905ef9f2a5SBarry Smith } MatILUInfo; 4915ef9f2a5SBarry Smith 492d91e6319SBarry Smith /*S 493d91e6319SBarry Smith MatLUInfo - Data based into the matrix LU factorization routines 494d91e6319SBarry Smith 495d91e6319SBarry Smith In Fortran these are simply double precision arrays of size MAT_LUINFO_SIZE 496d91e6319SBarry Smith 497d91e6319SBarry Smith Notes: These are not usually directly used by users, instead use the PC type of LU 498d91e6319SBarry Smith All entries are double precision. 499d91e6319SBarry Smith 500d91e6319SBarry Smith Level: developer 501d91e6319SBarry Smith 502d91e6319SBarry Smith .seealso: MatLUFactorSymbolic(), MatILUInfo, MatCholeskyInfo 503d91e6319SBarry Smith 504d91e6319SBarry Smith S*/ 50514822f30SBarry Smith typedef struct { 506f6275e2eSBarry Smith PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix */ 507f6275e2eSBarry Smith PetscReal dtcol; /* tolerance for pivoting; pivot if off_diagonal*dtcol > diagonal */ 508f6275e2eSBarry Smith PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 509f6275e2eSBarry Smith PetscReal damp; /* if this is 1.0 and factorization fails, damp until successful */ 510f6275e2eSBarry Smith PetscReal zeropivot; /* pivot is called zero if less than this */ 51114822f30SBarry Smith } MatLUInfo; 51214822f30SBarry Smith 513d91e6319SBarry Smith /*S 514d91e6319SBarry Smith MatCholeskyInfo - Data based into the matrix Cholesky factorization routines 515d91e6319SBarry Smith 516d91e6319SBarry Smith In Fortran these are simply double precision arrays of size MAT_CHOLESKYINFO_SIZE 517d91e6319SBarry Smith 518d91e6319SBarry Smith Notes: These are not usually directly used by users, instead use the PC type of Cholesky 519d91e6319SBarry Smith All entries are double precision. 520d91e6319SBarry Smith 521d91e6319SBarry Smith Level: developer 522d91e6319SBarry Smith 523d91e6319SBarry Smith .seealso: MatCholeskyFactorSymbolic(), MatLUInfo, MatILUInfo 524d91e6319SBarry Smith 525d91e6319SBarry Smith S*/ 526ffa6d0a5SLois Curfman McInnes typedef struct { 527f6275e2eSBarry Smith PetscReal fill; /* expected fill; nonzeros in factored matrix/nonzeros in original matrix */ 528f6275e2eSBarry Smith PetscReal damping; /* scaling of identity added to matrix to prevent zero pivots */ 529f6275e2eSBarry Smith PetscReal damp; /* if this is 1.0 and factorization fails, damp until successful */ 530ffa6d0a5SLois Curfman McInnes } MatCholeskyInfo; 531ffa6d0a5SLois Curfman McInnes 53214822f30SBarry Smith EXTERN int MatLUFactor(Mat,IS,IS,MatLUInfo*); 533ca44d042SBarry Smith EXTERN int MatILUFactor(Mat,IS,IS,MatILUInfo*); 53414822f30SBarry Smith EXTERN int MatLUFactorSymbolic(Mat,IS,IS,MatLUInfo*,Mat*); 535ca44d042SBarry Smith EXTERN int MatILUFactorSymbolic(Mat,IS,IS,MatILUInfo*,Mat*); 53687828ca2SBarry Smith EXTERN int MatICCFactorSymbolic(Mat,IS,PetscReal,int,Mat*); 53787828ca2SBarry Smith EXTERN int MatICCFactor(Mat,IS,PetscReal,int); 538ca44d042SBarry Smith EXTERN int MatLUFactorNumeric(Mat,Mat*); 539ca44d042SBarry Smith EXTERN int MatILUDTFactor(Mat,MatILUInfo*,IS,IS,Mat *); 540a2ce50c7SBarry Smith 541ca44d042SBarry Smith EXTERN int MatSolve(Mat,Vec,Vec); 542ca44d042SBarry Smith EXTERN int MatForwardSolve(Mat,Vec,Vec); 543ca44d042SBarry Smith EXTERN int MatBackwardSolve(Mat,Vec,Vec); 544ca44d042SBarry Smith EXTERN int MatSolveAdd(Mat,Vec,Vec,Vec); 545ca44d042SBarry Smith EXTERN int MatSolveTranspose(Mat,Vec,Vec); 546ca44d042SBarry Smith EXTERN int MatSolveTransposeAdd(Mat,Vec,Vec,Vec); 5478ed539a5SBarry Smith 548ca44d042SBarry Smith EXTERN int MatSetUnfactored(Mat); 549bb5a7306SBarry Smith 550bb1eb677SSatish Balay /* MatSORType may be bitwise ORd together, so do not change the numbers */ 551d91e6319SBarry Smith /*E 552d91e6319SBarry Smith MatSORType - What type of (S)SOR to perform 553bb1eb677SSatish Balay 554d91e6319SBarry Smith Level: beginner 555d91e6319SBarry Smith 556d9274352SBarry Smith May be bitwise ORd together 557d9274352SBarry Smith 558d91e6319SBarry Smith Any additions/changes here MUST also be made in include/finclude/petscmat.h 559d91e6319SBarry Smith 560d91e6319SBarry Smith .seealso: MatRelax() 561d91e6319SBarry Smith E*/ 562ee50ffe9SBarry Smith typedef enum {SOR_FORWARD_SWEEP=1,SOR_BACKWARD_SWEEP=2,SOR_SYMMETRIC_SWEEP=3, 563ee50ffe9SBarry Smith SOR_LOCAL_FORWARD_SWEEP=4,SOR_LOCAL_BACKWARD_SWEEP=8, 564ee50ffe9SBarry Smith SOR_LOCAL_SYMMETRIC_SWEEP=12,SOR_ZERO_INITIAL_GUESS=16, 56584cb2905SBarry Smith SOR_EISENSTAT=32,SOR_APPLY_UPPER=64,SOR_APPLY_LOWER=128} MatSORType; 566c14dc6b6SHong Zhang EXTERN int MatRelax(Mat,Vec,PetscReal,MatSORType,PetscReal,int,int,Vec); 5678ed539a5SBarry Smith 568d4fbbf0eSBarry Smith /* 569639f9d9dSBarry Smith These routines are for efficiently computing Jacobians via finite differences. 570639f9d9dSBarry Smith */ 571b12f92e5SBarry Smith 572d9274352SBarry Smith /*E 573d9274352SBarry Smith MatColoringType - String with the name of a PETSc matrix coloring or the creation function 574d9274352SBarry Smith with an optional dynamic library name, for example 575d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:coloringcreate() 576d9274352SBarry Smith 577d9274352SBarry Smith Level: beginner 578d9274352SBarry Smith 579d9274352SBarry Smith .seealso: MatGetColoring() 580d9274352SBarry Smith E*/ 581b12f92e5SBarry Smith typedef char* MatColoringType; 582b12f92e5SBarry Smith #define MATCOLORING_NATURAL "natural" 583b12f92e5SBarry Smith #define MATCOLORING_SL "sl" 584b12f92e5SBarry Smith #define MATCOLORING_LF "lf" 585b12f92e5SBarry Smith #define MATCOLORING_ID "id" 586b12f92e5SBarry Smith 587ca44d042SBarry Smith EXTERN int MatGetColoring(Mat,MatColoringType,ISColoring*); 588ca44d042SBarry Smith EXTERN int MatColoringRegister(char*,char*,char*,int(*)(Mat,MatColoringType,ISColoring *)); 589aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 590f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,0) 591b12f92e5SBarry Smith #else 592f1af5d2fSBarry Smith #define MatColoringRegisterDynamic(a,b,c,d) MatColoringRegister(a,b,c,d) 593b12f92e5SBarry Smith #endif 594ca44d042SBarry Smith EXTERN int MatColoringRegisterAll(char *); 5952bad1931SBarry Smith extern PetscTruth MatColoringRegisterAllCalled; 596ca44d042SBarry Smith EXTERN int MatColoringRegisterDestroy(void); 597b9617806SBarry Smith EXTERN int MatColoringPatch(Mat,int,int,int *,ISColoring*); 598639f9d9dSBarry Smith 599d9274352SBarry Smith /*S 600d9274352SBarry Smith MatFDColoring - Object for computing a sparse Jacobian via finite differences 601d9274352SBarry Smith and coloring 602639f9d9dSBarry Smith 603d9274352SBarry Smith Level: beginner 604d9274352SBarry Smith 605d9274352SBarry Smith Concepts: coloring, sparse Jacobian, finite differences 606d9274352SBarry Smith 607d9274352SBarry Smith .seealso: MatFDColoringCreate() 608d9274352SBarry Smith S*/ 609e2a1c21fSSatish Balay typedef struct _p_MatFDColoring *MatFDColoring; 610639f9d9dSBarry Smith 611ca44d042SBarry Smith EXTERN int MatFDColoringCreate(Mat,ISColoring,MatFDColoring *); 612ca44d042SBarry Smith EXTERN int MatFDColoringDestroy(MatFDColoring); 613b0a32e0cSBarry Smith EXTERN int MatFDColoringView(MatFDColoring,PetscViewer); 614ca44d042SBarry Smith EXTERN int MatFDColoringSetFunction(MatFDColoring,int (*)(void),void*); 61587828ca2SBarry Smith EXTERN int MatFDColoringSetParameters(MatFDColoring,PetscReal,PetscReal); 616ca44d042SBarry Smith EXTERN int MatFDColoringSetFrequency(MatFDColoring,int); 617ca44d042SBarry Smith EXTERN int MatFDColoringGetFrequency(MatFDColoring,int*); 618ca44d042SBarry Smith EXTERN int MatFDColoringSetFromOptions(MatFDColoring); 619ca44d042SBarry Smith EXTERN int MatFDColoringApply(Mat,MatFDColoring,Vec,MatStructure*,void *); 62087828ca2SBarry Smith EXTERN int MatFDColoringApplyTS(Mat,MatFDColoring,PetscReal,Vec,MatStructure*,void *); 62162152c8bSBarry Smith EXTERN int MatFDColoringSetRecompute(MatFDColoring); 6223a7fca6bSBarry Smith EXTERN int MatFDColoringSetF(MatFDColoring,Vec); 623639f9d9dSBarry Smith 624639f9d9dSBarry Smith /* 6250752156aSBarry Smith These routines are for partitioning matrices: currently used only 6263eda8832SBarry Smith for adjacency matrix, MatCreateMPIAdj(). 6270752156aSBarry Smith */ 628ca161407SBarry Smith 629d9274352SBarry Smith /*S 630d9274352SBarry Smith MatPartitioning - Object for managing the partitioning of a matrix or graph 631d9274352SBarry Smith 632d9274352SBarry Smith Level: beginner 633d9274352SBarry Smith 634d9274352SBarry Smith Concepts: partitioning 635d9274352SBarry Smith 636d9274352SBarry Smith .seealso: MatParitioningCreate(), MatPartitioningType 637d9274352SBarry Smith S*/ 63891e9ee9fSBarry Smith typedef struct _p_MatPartitioning *MatPartitioning; 639d9274352SBarry Smith 640d9274352SBarry Smith /*E 641d9274352SBarry Smith MatPartitioningType - String with the name of a PETSc matrix partitioing or the creation function 642d9274352SBarry Smith with an optional dynamic library name, for example 643d9274352SBarry Smith http://www.mcs.anl.gov/petsc/lib.a:partitioningcreate() 644d9274352SBarry Smith 645d9274352SBarry Smith Level: beginner 646d9274352SBarry Smith 647d9274352SBarry Smith .seealso: MatPartitioingCreate(), MatPartitioning 648d9274352SBarry Smith E*/ 6492aabb6bbSBarry Smith typedef char* MatPartitioningType; 6508ba1e511SMatthew Knepley #define MAT_PARTITIONING_CURRENT "current" 6518ba1e511SMatthew Knepley #define MAT_PARTITIONING_PARMETIS "parmetis" 652ca161407SBarry Smith 653ca44d042SBarry Smith EXTERN int MatPartitioningCreate(MPI_Comm,MatPartitioning*); 654ca44d042SBarry Smith EXTERN int MatPartitioningSetType(MatPartitioning,MatPartitioningType); 655ca44d042SBarry Smith EXTERN int MatPartitioningSetAdjacency(MatPartitioning,Mat); 656ca44d042SBarry Smith EXTERN int MatPartitioningSetVertexWeights(MatPartitioning,int*); 657ca44d042SBarry Smith EXTERN int MatPartitioningApply(MatPartitioning,IS*); 658ca44d042SBarry Smith EXTERN int MatPartitioningDestroy(MatPartitioning); 6592aabb6bbSBarry Smith 660ca44d042SBarry Smith EXTERN int MatPartitioningRegister(char*,char*,char*,int(*)(MatPartitioning)); 661aa482453SBarry Smith #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 662f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,0) 6632aabb6bbSBarry Smith #else 664f1af5d2fSBarry Smith #define MatPartitioningRegisterDynamic(a,b,c,d) MatPartitioningRegister(a,b,c,d) 6652aabb6bbSBarry Smith #endif 6662aabb6bbSBarry Smith 667ca44d042SBarry Smith EXTERN int MatPartitioningRegisterAll(char *); 6682bad1931SBarry Smith extern PetscTruth MatPartitioningRegisterAllCalled; 669ca44d042SBarry Smith EXTERN int MatPartitioningRegisterDestroy(void); 6702bad1931SBarry Smith 671b0a32e0cSBarry Smith EXTERN int MatPartitioningView(MatPartitioning,PetscViewer); 672ca44d042SBarry Smith EXTERN int MatPartitioningSetFromOptions(MatPartitioning); 673ca44d042SBarry Smith EXTERN int MatPartitioningGetType(MatPartitioning,MatPartitioningType*); 674ca161407SBarry Smith 675ca44d042SBarry Smith EXTERN int MatPartitioningParmetisSetCoarseSequential(MatPartitioning); 6760752156aSBarry Smith 6770752156aSBarry Smith /* 6780a835dfdSSatish Balay If you add entries here you must also add them to finclude/petscmat.h 679d4fbbf0eSBarry Smith */ 6801c1c02c0SLois Curfman McInnes typedef enum { MATOP_SET_VALUES=0, 6811c1c02c0SLois Curfman McInnes MATOP_GET_ROW=1, 6821c1c02c0SLois Curfman McInnes MATOP_RESTORE_ROW=2, 6831c1c02c0SLois Curfman McInnes MATOP_MULT=3, 6841c1c02c0SLois Curfman McInnes MATOP_MULT_ADD=4, 6857c922b88SBarry Smith MATOP_MULT_TRANSPOSE=5, 6867c922b88SBarry Smith MATOP_MULT_TRANSPOSE_ADD=6, 6871c1c02c0SLois Curfman McInnes MATOP_SOLVE=7, 6881c1c02c0SLois Curfman McInnes MATOP_SOLVE_ADD=8, 6897c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE=9, 6907c922b88SBarry Smith MATOP_SOLVE_TRANSPOSE_ADD=10, 6911c1c02c0SLois Curfman McInnes MATOP_LUFACTOR=11, 6921c1c02c0SLois Curfman McInnes MATOP_CHOLESKYFACTOR=12, 6931c1c02c0SLois Curfman McInnes MATOP_RELAX=13, 6941c1c02c0SLois Curfman McInnes MATOP_TRANSPOSE=14, 6951c1c02c0SLois Curfman McInnes MATOP_GETINFO=15, 6961c1c02c0SLois Curfman McInnes MATOP_EQUAL=16, 6971c1c02c0SLois Curfman McInnes MATOP_GET_DIAGONAL=17, 6981c1c02c0SLois Curfman McInnes MATOP_DIAGONAL_SCALE=18, 6991c1c02c0SLois Curfman McInnes MATOP_NORM=19, 7001c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_BEGIN=20, 7011c1c02c0SLois Curfman McInnes MATOP_ASSEMBLY_END=21, 7021c1c02c0SLois Curfman McInnes MATOP_COMPRESS=22, 7031c1c02c0SLois Curfman McInnes MATOP_SET_OPTION=23, 7041c1c02c0SLois Curfman McInnes MATOP_ZERO_ENTRIES=24, 7051c1c02c0SLois Curfman McInnes MATOP_ZERO_ROWS=25, 7061c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_SYMBOLIC=26, 7071c1c02c0SLois Curfman McInnes MATOP_LUFACTOR_NUMERIC=27, 7081c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_SYMBOLIC=28, 7091c1c02c0SLois Curfman McInnes MATOP_CHOLESKY_FACTOR_NUMERIC=29, 710d643ce63SMatthew Knepley MATOP_SETUP_PREALLOCATION=30, 711d643ce63SMatthew Knepley MATOP_ILUFACTOR_SYMBOLIC=31, 712d643ce63SMatthew Knepley MATOP_ICCFACTOR_SYMBOLIC=32, 713d643ce63SMatthew Knepley MATOP_GET_ARRAY=33, 714d643ce63SMatthew Knepley MATOP_RESTORE_ARRAY=34, 715d643ce63SMatthew Knepley MATOP_DUPLCIATE=35, 716d643ce63SMatthew Knepley MATOP_FORWARD_SOLVE=36, 717d643ce63SMatthew Knepley MATOP_BACKWARD_SOLVE=37, 718d643ce63SMatthew Knepley MATOP_ILUFACTOR=38, 719d643ce63SMatthew Knepley MATOP_ICCFACTOR=39, 720d643ce63SMatthew Knepley MATOP_AXPY=40, 721d643ce63SMatthew Knepley MATOP_GET_SUBMATRICES=41, 722d643ce63SMatthew Knepley MATOP_INCREASE_OVERLAP=42, 723d643ce63SMatthew Knepley MATOP_GET_VALUES=43, 724d643ce63SMatthew Knepley MATOP_COPY=44, 725d643ce63SMatthew Knepley MATOP_PRINT_HELP=45, 726d643ce63SMatthew Knepley MATOP_SCALE=46, 727d643ce63SMatthew Knepley MATOP_SHIFT=47, 728d643ce63SMatthew Knepley MATOP_DIAGONAL_SHIFT=48, 729d643ce63SMatthew Knepley MATOP_ILUDT_FACTOR=49, 730d643ce63SMatthew Knepley MATOP_GET_BLOCK_SIZE=50, 731d643ce63SMatthew Knepley MATOP_GET_ROW_IJ=51, 732d643ce63SMatthew Knepley MATOP_RESTORE_ROW_IJ=52, 733d643ce63SMatthew Knepley MATOP_GET_COLUMN_IJ=53, 734d643ce63SMatthew Knepley MATOP_RESTORE_COLUMN_IJ=54, 735d643ce63SMatthew Knepley MATOP_FDCOLORING_CREATE=55, 736d643ce63SMatthew Knepley MATOP_COLORING_PATCH=56, 737d643ce63SMatthew Knepley MATOP_SET_UNFACTORED=57, 738d643ce63SMatthew Knepley MATOP_PERMUTE=58, 739d643ce63SMatthew Knepley MATOP_SET_VALUES_BLOCKED=59, 740d643ce63SMatthew Knepley MATOP_GET_SUBMATRIX=60, 741d643ce63SMatthew Knepley MATOP_DESTROY=61, 742d643ce63SMatthew Knepley MATOP_VIEW=62, 743d643ce63SMatthew Knepley MATOP_GET_MAPS=63, 744d643ce63SMatthew Knepley MATOP_USE_SCALED_FORM=64, 745d643ce63SMatthew Knepley MATOP_SCALE_SYSTEM=65, 746d643ce63SMatthew Knepley MATOP_UNSCALE_SYSTEM=66, 747d643ce63SMatthew Knepley MATOP_SET_LOCAL_TO_GLOBAL_MAPPING=67, 748d643ce63SMatthew Knepley MATOP_SET_VALUES_LOCAL=68, 749d643ce63SMatthew Knepley MATOP_ZERO_ROWS_LOCAL=69, 750d643ce63SMatthew Knepley MATOP_GET_ROW_MAX=70, 751d643ce63SMatthew Knepley MATOP_CONVERT=71, 752d643ce63SMatthew Knepley MATOP_SET_COLORING=72, 753d643ce63SMatthew Knepley MATOP_SET_VALUES_ADIC=73, 754d643ce63SMatthew Knepley MATOP_SET_VALUES_ADIFOR=74, 755d643ce63SMatthew Knepley MATOP_FD_COLORING_APPLY=75, 756d643ce63SMatthew Knepley MATOP_SET_FROM_OPTIONS=76, 757d643ce63SMatthew Knepley MATOP_MULT_CONSTRAINED=77, 758d643ce63SMatthew Knepley MATOP_MULT_TRANSPOSE_CONSTRAINED=78, 759d643ce63SMatthew Knepley MATOP_ILU_FACTOR_SYMBOLIC_CONSTRAINED=79, 760d643ce63SMatthew Knepley MATOP_PERMUTE_SPARSIFY=80, 761d643ce63SMatthew Knepley MATOP_MULT_MULTIPLE=81, 762d643ce63SMatthew Knepley MATOP_SOLVE_MULTIPLE=82 763fae171e0SBarry Smith } MatOperation; 764ca44d042SBarry Smith EXTERN int MatHasOperation(Mat,MatOperation,PetscTruth*); 765ff8b7a98SSatish Balay EXTERN int MatShellSetOperation(Mat,MatOperation,void(*)(void)); 766ff8b7a98SSatish Balay EXTERN int MatShellGetOperation(Mat,MatOperation,void(**)(void)); 767273d9f13SBarry Smith EXTERN int MatShellSetContext(Mat,void*); 768112a2221SBarry Smith 76990ace30eSBarry Smith /* 77090ace30eSBarry Smith Codes for matrices stored on disk. By default they are 77190ace30eSBarry Smith stored in a universal format. By changing the format with 772fb9695e5SSatish Balay PetscViewerSetFormat(viewer,PETSC_VIEWER_BINARY_NATIVE); the matrices will 77390ace30eSBarry Smith be stored in a way natural for the matrix, for example dense matrices 77490ace30eSBarry Smith would be stored as dense. Matrices stored this way may only be 77590ace30eSBarry Smith read into matrices of the same time. 77690ace30eSBarry Smith */ 77790ace30eSBarry Smith #define MATRIX_BINARY_FORMAT_DENSE -1 77890ace30eSBarry Smith 7793f1d51d7SBarry Smith /* 7803f1d51d7SBarry Smith New matrix classes not yet distributed 7813f1d51d7SBarry Smith */ 7823f1d51d7SBarry Smith /* 7833f1d51d7SBarry Smith MatAIJIndices is a data structure for storing the nonzero location information 7843f1d51d7SBarry Smith for sparse matrices. Several matrices with identical nonzero structure can share 7853f1d51d7SBarry Smith the same MatAIJIndices. 7863f1d51d7SBarry Smith */ 787e2a1c21fSSatish Balay typedef struct _p_MatAIJIndices* MatAIJIndices; 7883f1d51d7SBarry Smith 789ca44d042SBarry Smith EXTERN int MatCreateAIJIndices(int,int,int*,int*,PetscTruth,MatAIJIndices*); 790ca44d042SBarry Smith EXTERN int MatCreateAIJIndicesEmpty(int,int,int*,PetscTruth,MatAIJIndices*); 791ca44d042SBarry Smith EXTERN int MatAttachAIJIndices(MatAIJIndices,MatAIJIndices*); 792ca44d042SBarry Smith EXTERN int MatDestroyAIJIndices(MatAIJIndices); 793ca44d042SBarry Smith EXTERN int MatCopyAIJIndices(MatAIJIndices,MatAIJIndices*); 794ca44d042SBarry Smith EXTERN int MatValidateAIJIndices(int,MatAIJIndices); 795ca44d042SBarry Smith EXTERN int MatShiftAIJIndices(MatAIJIndices); 796ca44d042SBarry Smith EXTERN int MatShrinkAIJIndices(MatAIJIndices); 797ca44d042SBarry Smith EXTERN int MatTransposeAIJIndices(MatAIJIndices,MatAIJIndices*); 7983f1d51d7SBarry Smith 799ca44d042SBarry Smith EXTERN int MatCreateSeqCSN(MPI_Comm,int,int,int*,int,Mat*); 800ca44d042SBarry Smith EXTERN int MatCreateSeqCSN_Single(MPI_Comm,int,int,int*,int,Mat*); 80187828ca2SBarry Smith EXTERN int MatCreateSeqCSNWithPrecision(MPI_Comm,int,int,int*,int,PetscScalarPrecision,Mat*); 8023f1d51d7SBarry Smith 803ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices(MPI_Comm,MatAIJIndices,int,Mat *); 804ca44d042SBarry Smith EXTERN int MatCreateSeqCSNIndices_Single(MPI_Comm,MatAIJIndices,int,Mat *); 80587828ca2SBarry Smith EXTERN int MatCreateSeqCSNIndicesWithPrecision(MPI_Comm,MatAIJIndices,int,PetscScalarPrecision,Mat *); 8063f1d51d7SBarry Smith 8076d053be9SSatish Balay EXTERN int MatMPIBAIJSetHashTableFactor(Mat,PetscReal); 808ca44d042SBarry Smith EXTERN int MatSeqAIJGetInodeSizes(Mat,int *,int *[],int *); 80908918a0eSSatish Balay EXTERN int MatMPIRowbsGetColor(Mat,ISColoring *); 810860d1616SSatish Balay 811d9274352SBarry Smith /*S 812d9274352SBarry Smith MatNullSpace - Object that removes a null space from a vector, i.e. 813d9274352SBarry Smith orthogonalizes the vector to a subsapce 814d9274352SBarry Smith 815d9274352SBarry Smith Level: beginner 816d9274352SBarry Smith 817d9274352SBarry Smith Concepts: matrix; linear operator, null space 818d9274352SBarry Smith 819d9274352SBarry Smith .seealso: MatNullSpaceCreate() 820d9274352SBarry Smith S*/ 82174637425SBarry Smith typedef struct _p_MatNullSpace* MatNullSpace; 822d9274352SBarry Smith 82374637425SBarry Smith EXTERN int MatNullSpaceCreate(MPI_Comm,int,int,Vec *,MatNullSpace*); 82474637425SBarry Smith EXTERN int MatNullSpaceDestroy(MatNullSpace); 82574637425SBarry Smith EXTERN int MatNullSpaceRemove(MatNullSpace,Vec,Vec*); 82674637425SBarry Smith EXTERN int MatNullSpaceAttach(Mat,MatNullSpace); 82774637425SBarry Smith EXTERN int MatNullSpaceTest(MatNullSpace,Mat); 82874637425SBarry Smith 829273d9f13SBarry Smith EXTERN int MatReorderingSeqSBAIJ(Mat A,IS isp); 830273d9f13SBarry Smith EXTERN int MatMPISBAIJSetHashTableFactor(Mat,PetscReal); 831273d9f13SBarry Smith EXTERN int MatSeqSBAIJSetColumnIndices(Mat,int *); 832273d9f13SBarry Smith 8333f1d51d7SBarry Smith 834f069c275SSatish Balay EXTERN int MatCreateMAIJ(Mat,int,Mat*); 835c4f061fbSSatish Balay EXTERN int MatMAIJRedimension(Mat,int,Mat*); 836c4f061fbSSatish Balay EXTERN int MatMAIJGetAIJ(Mat,Mat*); 837c4f061fbSSatish Balay 838273d9f13SBarry Smith EXTERN int MatMPIAdjSetValues(Mat,int*,int*,int*); 839f069c275SSatish Balay 840b0a32e0cSBarry Smith EXTERN int MatComputeExplicitOperator(Mat,Mat*); 841b0a32e0cSBarry Smith 84224a595ddSBarry Smith EXTERN int MatESISetType(Mat,char*); 84324a595ddSBarry Smith EXTERN int MatESISetFromOptions(Mat); 84424a595ddSBarry Smith 8452eac72dbSBarry Smith #endif 8462eac72dbSBarry Smith 8472eac72dbSBarry Smith 8489d00d63dSBarry Smith 849