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 9*d083f849SBarry 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 77ca9cdca7SRichard Tran Mills .seealso: MatCreate(), MatCreateSeqAIJSELL(), MatSetValues() 78ca9cdca7SRichard Tran Mills @*/ 79ca9cdca7SRichard Tran Mills 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 { 81ca9cdca7SRichard Tran Mills PetscErrorCode ierr; 82ca9cdca7SRichard Tran Mills PetscMPIInt size; 83ca9cdca7SRichard Tran Mills 84ca9cdca7SRichard Tran Mills PetscFunctionBegin; 85ca9cdca7SRichard Tran Mills ierr = MatCreate(comm,A);CHKERRQ(ierr); 86ca9cdca7SRichard Tran Mills ierr = MatSetSizes(*A,m,n,M,N);CHKERRQ(ierr); 87ca9cdca7SRichard Tran Mills ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 88ca9cdca7SRichard Tran Mills if (size > 1) { 89ca9cdca7SRichard Tran Mills ierr = MatSetType(*A,MATMPIAIJSELL);CHKERRQ(ierr); 90ca9cdca7SRichard Tran Mills ierr = MatMPIAIJSetPreallocation(*A,d_nz,d_nnz,o_nz,o_nnz);CHKERRQ(ierr); 91ca9cdca7SRichard Tran Mills } else { 92ca9cdca7SRichard Tran Mills ierr = MatSetType(*A,MATSEQAIJSELL);CHKERRQ(ierr); 93ca9cdca7SRichard Tran Mills ierr = MatSeqAIJSetPreallocation(*A,d_nz,d_nnz);CHKERRQ(ierr); 94ca9cdca7SRichard Tran Mills } 95ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 96ca9cdca7SRichard Tran Mills } 97ca9cdca7SRichard Tran Mills 98ca9cdca7SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJSELL(Mat,MatType,MatReuse,Mat*); 99ca9cdca7SRichard Tran Mills 100ca9cdca7SRichard Tran Mills PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJSELL(Mat B,PetscInt d_nz,const PetscInt d_nnz[],PetscInt o_nz,const PetscInt o_nnz[]) 101ca9cdca7SRichard Tran Mills { 102ca9cdca7SRichard Tran Mills Mat_MPIAIJ *b = (Mat_MPIAIJ*)B->data; 103ca9cdca7SRichard Tran Mills PetscErrorCode ierr; 104ca9cdca7SRichard Tran Mills 105ca9cdca7SRichard Tran Mills PetscFunctionBegin; 106ca9cdca7SRichard Tran Mills ierr = MatMPIAIJSetPreallocation_MPIAIJ(B,d_nz,d_nnz,o_nz,o_nnz);CHKERRQ(ierr); 107ca9cdca7SRichard Tran Mills ierr = MatConvert_SeqAIJ_SeqAIJSELL(b->A, MATSEQAIJSELL, MAT_INPLACE_MATRIX, &b->A);CHKERRQ(ierr); 108ca9cdca7SRichard Tran Mills ierr = MatConvert_SeqAIJ_SeqAIJSELL(b->B, MATSEQAIJSELL, MAT_INPLACE_MATRIX, &b->B);CHKERRQ(ierr); 109ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 110ca9cdca7SRichard Tran Mills } 111ca9cdca7SRichard Tran Mills 112ca9cdca7SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJSELL(Mat A,MatType type,MatReuse reuse,Mat *newmat) 113ca9cdca7SRichard Tran Mills { 114ca9cdca7SRichard Tran Mills PetscErrorCode ierr; 115ca9cdca7SRichard Tran Mills Mat B = *newmat; 116ca9cdca7SRichard Tran Mills 117ca9cdca7SRichard Tran Mills PetscFunctionBegin; 118ca9cdca7SRichard Tran Mills if (reuse == MAT_INITIAL_MATRIX) { 119ca9cdca7SRichard Tran Mills ierr = MatDuplicate(A,MAT_COPY_VALUES,&B);CHKERRQ(ierr); 120ca9cdca7SRichard Tran Mills } 121ca9cdca7SRichard Tran Mills 122ca9cdca7SRichard Tran Mills ierr = PetscObjectChangeTypeName((PetscObject) B, MATMPIAIJSELL);CHKERRQ(ierr); 123ca9cdca7SRichard Tran Mills ierr = PetscObjectComposeFunction((PetscObject)B,"MatMPIAIJSetPreallocation_C",MatMPIAIJSetPreallocation_MPIAIJSELL);CHKERRQ(ierr); 124ca9cdca7SRichard Tran Mills *newmat = B; 125ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 126ca9cdca7SRichard Tran Mills } 127ca9cdca7SRichard Tran Mills 128ca9cdca7SRichard Tran Mills PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJSELL(Mat A) 129ca9cdca7SRichard Tran Mills { 130ca9cdca7SRichard Tran Mills PetscErrorCode ierr; 131ca9cdca7SRichard Tran Mills 132ca9cdca7SRichard Tran Mills PetscFunctionBegin; 133ca9cdca7SRichard Tran Mills ierr = MatSetType(A,MATMPIAIJ);CHKERRQ(ierr); 134ca9cdca7SRichard Tran Mills ierr = MatConvert_MPIAIJ_MPIAIJSELL(A,MATMPIAIJSELL,MAT_INPLACE_MATRIX,&A);CHKERRQ(ierr); 135ca9cdca7SRichard Tran Mills PetscFunctionReturn(0); 136ca9cdca7SRichard Tran Mills } 137ca9cdca7SRichard Tran Mills 138ca9cdca7SRichard Tran Mills /*MC 139ca9cdca7SRichard Tran Mills MATAIJSELL - MATAIJSELL = "AIJSELL" - A matrix type to be used for sparse matrices. 140ca9cdca7SRichard Tran Mills 141ca9cdca7SRichard Tran Mills This matrix type is identical to MATSEQAIJSELL when constructed with a single process communicator, 142ca9cdca7SRichard Tran Mills and MATMPIAIJSELL otherwise. As a result, for single process communicators, 143ca9cdca7SRichard Tran Mills MatSeqAIJSetPreallocation() is supported, and similarly MatMPIAIJSetPreallocation() is supported 144ca9cdca7SRichard Tran Mills for communicators controlling multiple processes. It is recommended that you call both of 145ca9cdca7SRichard Tran Mills the above preallocation routines for simplicity. 146ca9cdca7SRichard Tran Mills 147ca9cdca7SRichard Tran Mills Options Database Keys: 148ca9cdca7SRichard Tran Mills . -mat_type aijsell - sets the matrix type to "AIJSELL" during a call to MatSetFromOptions() 149ca9cdca7SRichard Tran Mills 150ca9cdca7SRichard Tran Mills Level: beginner 151ca9cdca7SRichard Tran Mills 152ca9cdca7SRichard Tran Mills .seealso: MatCreateMPIAIJSELL(), MATSEQAIJSELL, MATMPIAIJSELL 153ca9cdca7SRichard Tran Mills M*/ 154ca9cdca7SRichard Tran Mills 155