1ca9cdca7SRichard Tran Mills #include <../src/mat/impls/aij/mpi/mpiaij.h> 2ca9cdca7SRichard Tran Mills /*@C 3ca9cdca7SRichard Tran Mills MatCreateMPIAIJSELL - Creates a sparse parallel matrix whose local 4ca9cdca7SRichard Tran Mills portions are stored as SEQAIJSELL matrices (a matrix class that inherits 5ca9cdca7SRichard Tran Mills from SEQAIJ but performs some operations in SELL format). The same 6ca9cdca7SRichard Tran Mills guidelines that apply to MPIAIJ matrices for preallocating the matrix 7ca9cdca7SRichard Tran Mills storage apply here as well. 8ca9cdca7SRichard Tran Mills 9d083f849SBarry Smith Collective 10ca9cdca7SRichard Tran Mills 11ca9cdca7SRichard Tran Mills Input Parameters: 12ca9cdca7SRichard Tran Mills + comm - MPI communicator 13ca9cdca7SRichard Tran Mills . m - number of local rows (or PETSC_DECIDE to have calculated if M is given) 14ca9cdca7SRichard Tran Mills This value should be the same as the local size used in creating the 15ca9cdca7SRichard Tran Mills y vector for the matrix-vector product y = Ax. 16ca9cdca7SRichard Tran Mills . n - This value should be the same as the local size used in creating the 17ca9cdca7SRichard Tran Mills x vector for the matrix-vector product y = Ax. (or PETSC_DECIDE to have 18ca9cdca7SRichard Tran Mills calculated if N is given) For square matrices n is almost always m. 19ca9cdca7SRichard Tran Mills . M - number of global rows (or PETSC_DETERMINE to have calculated if m is given) 20ca9cdca7SRichard Tran Mills . N - number of global columns (or PETSC_DETERMINE to have calculated if n is given) 21ca9cdca7SRichard Tran Mills . d_nz - number of nonzeros per row in DIAGONAL portion of local submatrix 22ca9cdca7SRichard Tran Mills (same value is used for all local rows) 23ca9cdca7SRichard Tran Mills . d_nnz - array containing the number of nonzeros in the various rows of the 24ca9cdca7SRichard Tran Mills DIAGONAL portion of the local submatrix (possibly different for each row) 25ca9cdca7SRichard Tran Mills or NULL, if d_nz is used to specify the nonzero structure. 26ca9cdca7SRichard Tran Mills The size of this array is equal to the number of local rows, i.e 'm'. 27ca9cdca7SRichard Tran Mills For matrices you plan to factor you must leave room for the diagonal entry and 28ca9cdca7SRichard Tran Mills put in the entry even if it is zero. 29ca9cdca7SRichard Tran Mills . o_nz - number of nonzeros per row in the OFF-DIAGONAL portion of local 30ca9cdca7SRichard Tran Mills submatrix (same value is used for all local rows). 31ca9cdca7SRichard Tran Mills - o_nnz - array containing the number of nonzeros in the various rows of the 32ca9cdca7SRichard Tran Mills OFF-DIAGONAL portion of the local submatrix (possibly different for 33ca9cdca7SRichard Tran Mills each row) or NULL, if o_nz is used to specify the nonzero 34ca9cdca7SRichard Tran Mills structure. The size of this array is equal to the number 35ca9cdca7SRichard Tran Mills of local rows, i.e 'm'. 36ca9cdca7SRichard Tran Mills 37ca9cdca7SRichard Tran Mills Output Parameter: 38ca9cdca7SRichard Tran Mills . A - the matrix 39ca9cdca7SRichard Tran Mills 40ca9cdca7SRichard Tran Mills Notes: 41ca9cdca7SRichard Tran Mills If the *_nnz parameter is given then the *_nz parameter is ignored 42ca9cdca7SRichard Tran Mills 43ca9cdca7SRichard Tran Mills m,n,M,N parameters specify the size of the matrix, and its partitioning across 44ca9cdca7SRichard Tran Mills processors, while d_nz,d_nnz,o_nz,o_nnz parameters specify the approximate 45ca9cdca7SRichard Tran Mills storage requirements for this matrix. 46ca9cdca7SRichard Tran Mills 47ca9cdca7SRichard Tran Mills If PETSC_DECIDE or PETSC_DETERMINE is used for a particular argument on one 48ca9cdca7SRichard Tran Mills processor than it must be used on all processors that share the object for 49ca9cdca7SRichard Tran Mills that argument. 50ca9cdca7SRichard Tran Mills 51ca9cdca7SRichard Tran Mills The user MUST specify either the local or global matrix dimensions 52ca9cdca7SRichard Tran Mills (possibly both). 53ca9cdca7SRichard Tran Mills 54ca9cdca7SRichard Tran Mills The parallel matrix is partitioned such that the first m0 rows belong to 55ca9cdca7SRichard Tran Mills process 0, the next m1 rows belong to process 1, the next m2 rows belong 56ca9cdca7SRichard Tran Mills to process 2 etc.. where m0,m1,m2... are the input parameter 'm'. 57ca9cdca7SRichard Tran Mills 58ca9cdca7SRichard Tran Mills The DIAGONAL portion of the local submatrix of a processor can be defined 59ca9cdca7SRichard Tran Mills as the submatrix which is obtained by extraction the part corresponding 60ca9cdca7SRichard Tran Mills to the rows r1-r2 and columns r1-r2 of the global matrix, where r1 is the 61ca9cdca7SRichard Tran Mills first row that belongs to the processor, and r2 is the last row belonging 62ca9cdca7SRichard Tran Mills to the this processor. This is a square mxm matrix. The remaining portion 63ca9cdca7SRichard Tran Mills of the local submatrix (mxN) constitute the OFF-DIAGONAL portion. 64ca9cdca7SRichard Tran Mills 65ca9cdca7SRichard Tran Mills If o_nnz, d_nnz are specified, then o_nz, and d_nz are ignored. 66ca9cdca7SRichard Tran Mills 67ca9cdca7SRichard Tran Mills When calling this routine with a single process communicator, a matrix of 68ca9cdca7SRichard Tran Mills type SEQAIJSELL is returned. If a matrix of type MPIAIJSELL is desired 69ca9cdca7SRichard Tran Mills for this type of communicator, use the construction mechanism: 70ca9cdca7SRichard Tran Mills MatCreate(...,&A); MatSetType(A,MPIAIJSELL); MatMPIAIJSetPreallocation(A,...); 71ca9cdca7SRichard Tran Mills 72ca9cdca7SRichard Tran Mills Options Database Keys: 73ca9cdca7SRichard Tran Mills . -mat_aijsell_eager_shadow - Construct shadow matrix upon matrix assembly; default is to take a "lazy" approach, performing this step the first time the matrix is applied 74ca9cdca7SRichard Tran Mills 75ca9cdca7SRichard Tran Mills Level: intermediate 76ca9cdca7SRichard Tran Mills 77db781477SPatrick Sanan .seealso: `MatCreate()`, `MatCreateSeqAIJSELL()`, `MatSetValues()` 78ca9cdca7SRichard Tran Mills @*/ 79*9371c9d4SSatish Balay PetscErrorCode MatCreateMPIAIJSELL(MPI_Comm comm, PetscInt m, PetscInt n, PetscInt M, PetscInt N, PetscInt d_nz, const PetscInt d_nnz[], PetscInt o_nz, const PetscInt o_nnz[], Mat *A) { 80ca9cdca7SRichard Tran Mills PetscMPIInt size; 81ca9cdca7SRichard Tran Mills 82ca9cdca7SRichard Tran Mills PetscFunctionBegin; 839566063dSJacob Faibussowitsch PetscCall(MatCreate(comm, A)); 849566063dSJacob Faibussowitsch PetscCall(MatSetSizes(*A, m, n, M, N)); 859566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_size(comm, &size)); 86ca9cdca7SRichard Tran Mills if (size > 1) { 879566063dSJacob Faibussowitsch PetscCall(MatSetType(*A, MATMPIAIJSELL)); 889566063dSJacob Faibussowitsch PetscCall(MatMPIAIJSetPreallocation(*A, d_nz, d_nnz, o_nz, o_nnz)); 89ca9cdca7SRichard Tran Mills } else { 909566063dSJacob Faibussowitsch PetscCall(MatSetType(*A, MATSEQAIJSELL)); 919566063dSJacob Faibussowitsch PetscCall(MatSeqAIJSetPreallocation(*A, d_nz, d_nnz)); 92ca9cdca7SRichard Tran Mills } 93ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 94ca9cdca7SRichard Tran Mills } 95ca9cdca7SRichard Tran Mills 96ca9cdca7SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJSELL(Mat, MatType, MatReuse, Mat *); 97ca9cdca7SRichard Tran Mills 98*9371c9d4SSatish Balay PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJSELL(Mat B, PetscInt d_nz, const PetscInt d_nnz[], PetscInt o_nz, const PetscInt o_nnz[]) { 99ca9cdca7SRichard Tran Mills Mat_MPIAIJ *b = (Mat_MPIAIJ *)B->data; 100ca9cdca7SRichard Tran Mills 101ca9cdca7SRichard Tran Mills PetscFunctionBegin; 1029566063dSJacob Faibussowitsch PetscCall(MatMPIAIJSetPreallocation_MPIAIJ(B, d_nz, d_nnz, o_nz, o_nnz)); 1039566063dSJacob Faibussowitsch PetscCall(MatConvert_SeqAIJ_SeqAIJSELL(b->A, MATSEQAIJSELL, MAT_INPLACE_MATRIX, &b->A)); 1049566063dSJacob Faibussowitsch PetscCall(MatConvert_SeqAIJ_SeqAIJSELL(b->B, MATSEQAIJSELL, MAT_INPLACE_MATRIX, &b->B)); 105ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 106ca9cdca7SRichard Tran Mills } 107ca9cdca7SRichard Tran Mills 108*9371c9d4SSatish Balay PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJSELL(Mat A, MatType type, MatReuse reuse, Mat *newmat) { 109ca9cdca7SRichard Tran Mills Mat B = *newmat; 110ca9cdca7SRichard Tran Mills 111ca9cdca7SRichard Tran Mills PetscFunctionBegin; 112*9371c9d4SSatish Balay if (reuse == MAT_INITIAL_MATRIX) { PetscCall(MatDuplicate(A, MAT_COPY_VALUES, &B)); } 113ca9cdca7SRichard Tran Mills 1149566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)B, MATMPIAIJSELL)); 1159566063dSJacob Faibussowitsch PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatMPIAIJSetPreallocation_C", MatMPIAIJSetPreallocation_MPIAIJSELL)); 116ca9cdca7SRichard Tran Mills *newmat = B; 117ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 118ca9cdca7SRichard Tran Mills } 119ca9cdca7SRichard Tran Mills 120*9371c9d4SSatish Balay PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJSELL(Mat A) { 121ca9cdca7SRichard Tran Mills PetscFunctionBegin; 1229566063dSJacob Faibussowitsch PetscCall(MatSetType(A, MATMPIAIJ)); 1239566063dSJacob Faibussowitsch PetscCall(MatConvert_MPIAIJ_MPIAIJSELL(A, MATMPIAIJSELL, MAT_INPLACE_MATRIX, &A)); 124ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 125ca9cdca7SRichard Tran Mills } 126ca9cdca7SRichard Tran Mills 127ca9cdca7SRichard Tran Mills /*MC 128ca9cdca7SRichard Tran Mills MATAIJSELL - MATAIJSELL = "AIJSELL" - A matrix type to be used for sparse matrices. 129ca9cdca7SRichard Tran Mills 130ca9cdca7SRichard Tran Mills This matrix type is identical to MATSEQAIJSELL when constructed with a single process communicator, 131ca9cdca7SRichard Tran Mills and MATMPIAIJSELL otherwise. As a result, for single process communicators, 132ca9cdca7SRichard Tran Mills MatSeqAIJSetPreallocation() is supported, and similarly MatMPIAIJSetPreallocation() is supported 133ca9cdca7SRichard Tran Mills for communicators controlling multiple processes. It is recommended that you call both of 134ca9cdca7SRichard Tran Mills the above preallocation routines for simplicity. 135ca9cdca7SRichard Tran Mills 136ca9cdca7SRichard Tran Mills Options Database Keys: 137ca9cdca7SRichard Tran Mills . -mat_type aijsell - sets the matrix type to "AIJSELL" during a call to MatSetFromOptions() 138ca9cdca7SRichard Tran Mills 139ca9cdca7SRichard Tran Mills Level: beginner 140ca9cdca7SRichard Tran Mills 141db781477SPatrick Sanan .seealso: `MatCreateMPIAIJSELL()`, `MATSEQAIJSELL`, `MATMPIAIJSELL` 142ca9cdca7SRichard Tran Mills M*/ 143