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 411a5261eSBarry Smith portions are stored as `MATSEQAIJSELL` matrices (a matrix class that inherits 5ca9cdca7SRichard Tran Mills from SEQAIJ but performs some operations in SELL format). The same 611a5261eSBarry Smith guidelines that apply to `MATMPIAIJ` 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 13*2ef1f0ffSBarry Smith . 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 1711a5261eSBarry Smith x vector for the matrix-vector product y = Ax. (or `PETSC_DECIDE` to have 18*2ef1f0ffSBarry Smith calculated if `N` is given) For square matrices `n` is almost always `m`. 19*2ef1f0ffSBarry Smith . M - number of global rows (or `PETSC_DETERMINE` to have calculated if `m` is given) 20*2ef1f0ffSBarry Smith . 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) 25*2ef1f0ffSBarry Smith or `NULL`, if `d_nz` is used to specify the nonzero structure. 26*2ef1f0ffSBarry Smith 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 33*2ef1f0ffSBarry Smith 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 35*2ef1f0ffSBarry Smith of local rows, i.e `m`. 36ca9cdca7SRichard Tran Mills 37ca9cdca7SRichard Tran Mills Output Parameter: 38ca9cdca7SRichard Tran Mills . A - the matrix 39ca9cdca7SRichard Tran Mills 40*2ef1f0ffSBarry Smith Options Database Key: 41*2ef1f0ffSBarry Smith . -mat_aijsell_eager_shadow - Construct shadow matrix upon matrix assembly; default is to take a "lazy" approach, performing this step the first 42*2ef1f0ffSBarry Smith time the matrix is applied 43*2ef1f0ffSBarry Smith 44*2ef1f0ffSBarry Smith Level: intermediate 45*2ef1f0ffSBarry Smith 46ca9cdca7SRichard Tran Mills Notes: 47ca9cdca7SRichard Tran Mills If the *_nnz parameter is given then the *_nz parameter is ignored 48ca9cdca7SRichard Tran Mills 49*2ef1f0ffSBarry Smith `m`,`n`,`M`,`N` parameters specify the size of the matrix, and its partitioning across 50*2ef1f0ffSBarry Smith processors, while `d_nz`,`d_nnz`,`o_nz`,`o_nnz` parameters specify the approximate 51ca9cdca7SRichard Tran Mills storage requirements for this matrix. 52ca9cdca7SRichard Tran Mills 5311a5261eSBarry Smith If `PETSC_DECIDE` or `PETSC_DETERMINE` is used for a particular argument on one 54ca9cdca7SRichard Tran Mills processor than it must be used on all processors that share the object for 55ca9cdca7SRichard Tran Mills that argument. 56ca9cdca7SRichard Tran Mills 57ca9cdca7SRichard Tran Mills The user MUST specify either the local or global matrix dimensions 58ca9cdca7SRichard Tran Mills (possibly both). 59ca9cdca7SRichard Tran Mills 60ca9cdca7SRichard Tran Mills The parallel matrix is partitioned such that the first m0 rows belong to 61ca9cdca7SRichard Tran Mills process 0, the next m1 rows belong to process 1, the next m2 rows belong 62*2ef1f0ffSBarry Smith to process 2 etc.. where m0,m1,m2... are the input parameter `m`. 63ca9cdca7SRichard Tran Mills 64ca9cdca7SRichard Tran Mills The DIAGONAL portion of the local submatrix of a processor can be defined 65ca9cdca7SRichard Tran Mills as the submatrix which is obtained by extraction the part corresponding 66ca9cdca7SRichard Tran Mills to the rows r1-r2 and columns r1-r2 of the global matrix, where r1 is the 67ca9cdca7SRichard Tran Mills first row that belongs to the processor, and r2 is the last row belonging 68ca9cdca7SRichard Tran Mills to the this processor. This is a square mxm matrix. The remaining portion 69ca9cdca7SRichard Tran Mills of the local submatrix (mxN) constitute the OFF-DIAGONAL portion. 70ca9cdca7SRichard Tran Mills 71*2ef1f0ffSBarry Smith If `o_nnz`, `d_nnz` are specified, then `o_nz`, and `d_nz` are ignored. 72ca9cdca7SRichard Tran Mills 73ca9cdca7SRichard Tran Mills When calling this routine with a single process communicator, a matrix of 7411a5261eSBarry Smith type `MATSEQAIJSELL` is returned. If a matrix of type `MATMPIAIJSELL` is desired 75ca9cdca7SRichard Tran Mills for this type of communicator, use the construction mechanism: 76*2ef1f0ffSBarry Smith .vb 77*2ef1f0ffSBarry Smith MatCreate(...,&A); 78*2ef1f0ffSBarry Smith MatSetType(A,MPIAIJSELL); 79*2ef1f0ffSBarry Smith MatMPIAIJSetPreallocation(A,...); 80*2ef1f0ffSBarry Smith .ve 81ca9cdca7SRichard Tran Mills 82*2ef1f0ffSBarry Smith .seealso: [](chapter_matrices), `Mat`, [Sparse Matrix Creation](sec_matsparse), `MATSEQAIJSELL`, `MATMPIAIJSELL`, `MATAIJSELL`, `MatCreate()`, `MatCreateSeqAIJSELL()`, `MatSetValues()` 83ca9cdca7SRichard Tran Mills @*/ 84d71ae5a4SJacob Faibussowitsch 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) 85d71ae5a4SJacob Faibussowitsch { 86ca9cdca7SRichard Tran Mills PetscMPIInt size; 87ca9cdca7SRichard Tran Mills 88ca9cdca7SRichard Tran Mills PetscFunctionBegin; 899566063dSJacob Faibussowitsch PetscCall(MatCreate(comm, A)); 909566063dSJacob Faibussowitsch PetscCall(MatSetSizes(*A, m, n, M, N)); 919566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_size(comm, &size)); 92ca9cdca7SRichard Tran Mills if (size > 1) { 939566063dSJacob Faibussowitsch PetscCall(MatSetType(*A, MATMPIAIJSELL)); 949566063dSJacob Faibussowitsch PetscCall(MatMPIAIJSetPreallocation(*A, d_nz, d_nnz, o_nz, o_nnz)); 95ca9cdca7SRichard Tran Mills } else { 969566063dSJacob Faibussowitsch PetscCall(MatSetType(*A, MATSEQAIJSELL)); 979566063dSJacob Faibussowitsch PetscCall(MatSeqAIJSetPreallocation(*A, d_nz, d_nnz)); 98ca9cdca7SRichard Tran Mills } 993ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 100ca9cdca7SRichard Tran Mills } 101ca9cdca7SRichard Tran Mills 102ca9cdca7SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJSELL(Mat, MatType, MatReuse, Mat *); 103ca9cdca7SRichard Tran Mills 104d71ae5a4SJacob Faibussowitsch PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJSELL(Mat B, PetscInt d_nz, const PetscInt d_nnz[], PetscInt o_nz, const PetscInt o_nnz[]) 105d71ae5a4SJacob Faibussowitsch { 106ca9cdca7SRichard Tran Mills Mat_MPIAIJ *b = (Mat_MPIAIJ *)B->data; 107ca9cdca7SRichard Tran Mills 108ca9cdca7SRichard Tran Mills PetscFunctionBegin; 1099566063dSJacob Faibussowitsch PetscCall(MatMPIAIJSetPreallocation_MPIAIJ(B, d_nz, d_nnz, o_nz, o_nnz)); 1109566063dSJacob Faibussowitsch PetscCall(MatConvert_SeqAIJ_SeqAIJSELL(b->A, MATSEQAIJSELL, MAT_INPLACE_MATRIX, &b->A)); 1119566063dSJacob Faibussowitsch PetscCall(MatConvert_SeqAIJ_SeqAIJSELL(b->B, MATSEQAIJSELL, MAT_INPLACE_MATRIX, &b->B)); 1123ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 113ca9cdca7SRichard Tran Mills } 114ca9cdca7SRichard Tran Mills 115d71ae5a4SJacob Faibussowitsch PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJSELL(Mat A, MatType type, MatReuse reuse, Mat *newmat) 116d71ae5a4SJacob Faibussowitsch { 117ca9cdca7SRichard Tran Mills Mat B = *newmat; 118ca9cdca7SRichard Tran Mills 119ca9cdca7SRichard Tran Mills PetscFunctionBegin; 12048a46eb9SPierre Jolivet if (reuse == MAT_INITIAL_MATRIX) PetscCall(MatDuplicate(A, MAT_COPY_VALUES, &B)); 121ca9cdca7SRichard Tran Mills 1229566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)B, MATMPIAIJSELL)); 1239566063dSJacob Faibussowitsch PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatMPIAIJSetPreallocation_C", MatMPIAIJSetPreallocation_MPIAIJSELL)); 124ca9cdca7SRichard Tran Mills *newmat = B; 1253ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 126ca9cdca7SRichard Tran Mills } 127ca9cdca7SRichard Tran Mills 128d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJSELL(Mat A) 129d71ae5a4SJacob Faibussowitsch { 130ca9cdca7SRichard Tran Mills PetscFunctionBegin; 1319566063dSJacob Faibussowitsch PetscCall(MatSetType(A, MATMPIAIJ)); 1329566063dSJacob Faibussowitsch PetscCall(MatConvert_MPIAIJ_MPIAIJSELL(A, MATMPIAIJSELL, MAT_INPLACE_MATRIX, &A)); 1333ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 134ca9cdca7SRichard Tran Mills } 135ca9cdca7SRichard Tran Mills 136ca9cdca7SRichard Tran Mills /*MC 137*2ef1f0ffSBarry Smith MATAIJSELL - "AIJSELL" - A matrix type to be used for sparse matrices. 138ca9cdca7SRichard Tran Mills 13911a5261eSBarry Smith This matrix type is identical to `MATSEQAIJSELL` when constructed with a single process communicator, 14011a5261eSBarry Smith and `MATMPIAIJSELL` otherwise. As a result, for single process communicators, 14111a5261eSBarry Smith MatSeqAIJSetPreallocation() is supported, and similarly `MatMPIAIJSetPreallocation()` is supported 142ca9cdca7SRichard Tran Mills for communicators controlling multiple processes. It is recommended that you call both of 143ca9cdca7SRichard Tran Mills the above preallocation routines for simplicity. 144ca9cdca7SRichard Tran Mills 145*2ef1f0ffSBarry Smith Options Database Key: 146*2ef1f0ffSBarry Smith . -mat_type aijsell - sets the matrix type to `MATAIJSELL` 147ca9cdca7SRichard Tran Mills 148ca9cdca7SRichard Tran Mills Level: beginner 149ca9cdca7SRichard Tran Mills 150*2ef1f0ffSBarry Smith .seealso: [](chapter_matrices), `Mat`, `MatCreateMPIAIJSELL()`, `MATSEQAIJSELL`, `MATMPIAIJSELL`, `MATSEQAIJ`, `MATMPIAIJ`, `MATSEQAIJPERM`, `MATMPIAIJPERM`, `MATSEQAIJMKL`, `MATMPIAIJMKL` 151ca9cdca7SRichard Tran Mills M*/ 152