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