1938d9b04SRichard Tran Mills 2938d9b04SRichard Tran Mills #include <../src/mat/impls/aij/mpi/mpiaij.h> 3938d9b04SRichard Tran Mills /*@C 4938d9b04SRichard Tran Mills MatCreateMPIAIJPERM - Creates a sparse parallel matrix whose local 5938d9b04SRichard Tran Mills portions are stored as SEQAIJPERM matrices (a matrix class that inherits 6938d9b04SRichard Tran Mills from SEQAIJ but includes some optimizations to allow more effective 7938d9b04SRichard Tran Mills vectorization). The same guidelines that apply to MPIAIJ matrices for 8938d9b04SRichard Tran Mills preallocating the matrix storage apply here as well. 9938d9b04SRichard Tran Mills 10*d083f849SBarry Smith Collective 11938d9b04SRichard Tran Mills 12938d9b04SRichard Tran Mills Input Parameters: 13938d9b04SRichard Tran Mills + comm - MPI communicator 14938d9b04SRichard Tran Mills . m - number of local rows (or PETSC_DECIDE to have calculated if M is given) 15938d9b04SRichard Tran Mills This value should be the same as the local size used in creating the 16938d9b04SRichard Tran Mills y vector for the matrix-vector product y = Ax. 17938d9b04SRichard Tran Mills . n - This value should be the same as the local size used in creating the 18938d9b04SRichard Tran Mills x vector for the matrix-vector product y = Ax. (or PETSC_DECIDE to have 19938d9b04SRichard Tran Mills calculated if N is given) For square matrices n is almost always m. 20938d9b04SRichard Tran Mills . M - number of global rows (or PETSC_DETERMINE to have calculated if m is given) 21938d9b04SRichard Tran Mills . N - number of global columns (or PETSC_DETERMINE to have calculated if n is given) 22938d9b04SRichard Tran Mills . d_nz - number of nonzeros per row in DIAGONAL portion of local submatrix 23938d9b04SRichard Tran Mills (same value is used for all local rows) 24938d9b04SRichard Tran Mills . d_nnz - array containing the number of nonzeros in the various rows of the 25938d9b04SRichard Tran Mills DIAGONAL portion of the local submatrix (possibly different for each row) 26938d9b04SRichard Tran Mills or NULL, if d_nz is used to specify the nonzero structure. 27938d9b04SRichard Tran Mills The size of this array is equal to the number of local rows, i.e 'm'. 28938d9b04SRichard Tran Mills For matrices you plan to factor you must leave room for the diagonal entry and 29938d9b04SRichard Tran Mills put in the entry even if it is zero. 30938d9b04SRichard Tran Mills . o_nz - number of nonzeros per row in the OFF-DIAGONAL portion of local 31938d9b04SRichard Tran Mills submatrix (same value is used for all local rows). 32938d9b04SRichard Tran Mills - o_nnz - array containing the number of nonzeros in the various rows of the 33938d9b04SRichard Tran Mills OFF-DIAGONAL portion of the local submatrix (possibly different for 34938d9b04SRichard Tran Mills each row) or NULL, if o_nz is used to specify the nonzero 35938d9b04SRichard Tran Mills structure. The size of this array is equal to the number 36938d9b04SRichard Tran Mills of local rows, i.e 'm'. 37938d9b04SRichard Tran Mills 38938d9b04SRichard Tran Mills Output Parameter: 39938d9b04SRichard Tran Mills . A - the matrix 40938d9b04SRichard Tran Mills 41938d9b04SRichard Tran Mills Notes: 42938d9b04SRichard Tran Mills If the *_nnz parameter is given then the *_nz parameter is ignored 43938d9b04SRichard Tran Mills 44938d9b04SRichard Tran Mills m,n,M,N parameters specify the size of the matrix, and its partitioning across 45938d9b04SRichard Tran Mills processors, while d_nz,d_nnz,o_nz,o_nnz parameters specify the approximate 46938d9b04SRichard Tran Mills storage requirements for this matrix. 47938d9b04SRichard Tran Mills 48938d9b04SRichard Tran Mills If PETSC_DECIDE or PETSC_DETERMINE is used for a particular argument on one 49938d9b04SRichard Tran Mills processor than it must be used on all processors that share the object for 50938d9b04SRichard Tran Mills that argument. 51938d9b04SRichard Tran Mills 52938d9b04SRichard Tran Mills The user MUST specify either the local or global matrix dimensions 53938d9b04SRichard Tran Mills (possibly both). 54938d9b04SRichard Tran Mills 55938d9b04SRichard Tran Mills The parallel matrix is partitioned such that the first m0 rows belong to 56938d9b04SRichard Tran Mills process 0, the next m1 rows belong to process 1, the next m2 rows belong 57938d9b04SRichard Tran Mills to process 2 etc.. where m0,m1,m2... are the input parameter 'm'. 58938d9b04SRichard Tran Mills 59938d9b04SRichard Tran Mills The DIAGONAL portion of the local submatrix of a processor can be defined 60938d9b04SRichard Tran Mills as the submatrix which is obtained by extraction the part corresponding 61938d9b04SRichard Tran Mills to the rows r1-r2 and columns r1-r2 of the global matrix, where r1 is the 62938d9b04SRichard Tran Mills first row that belongs to the processor, and r2 is the last row belonging 63938d9b04SRichard Tran Mills to the this processor. This is a square mxm matrix. The remaining portion 64938d9b04SRichard Tran Mills of the local submatrix (mxN) constitute the OFF-DIAGONAL portion. 65938d9b04SRichard Tran Mills 66938d9b04SRichard Tran Mills If o_nnz, d_nnz are specified, then o_nz, and d_nz are ignored. 67938d9b04SRichard Tran Mills 68938d9b04SRichard Tran Mills When calling this routine with a single process communicator, a matrix of 69938d9b04SRichard Tran Mills type SEQAIJPERM is returned. If a matrix of type MPIAIJPERM is desired 70938d9b04SRichard Tran Mills for this type of communicator, use the construction mechanism: 71938d9b04SRichard Tran Mills MatCreate(...,&A); MatSetType(A,MPIAIJ); MatMPIAIJSetPreallocation(A,...); 72938d9b04SRichard Tran Mills 73938d9b04SRichard Tran Mills By default, this format uses inodes (identical nodes) when possible. 74938d9b04SRichard Tran Mills We search for consecutive rows with the same nonzero structure, thereby 75938d9b04SRichard Tran Mills reusing matrix information to achieve increased efficiency. 76938d9b04SRichard Tran Mills 77938d9b04SRichard Tran Mills Options Database Keys: 78938d9b04SRichard Tran Mills + -mat_no_inode - Do not use inodes 79938d9b04SRichard Tran Mills - -mat_inode_limit <limit> - Sets inode limit (max limit=5) 80938d9b04SRichard Tran Mills 81938d9b04SRichard Tran Mills Level: intermediate 82938d9b04SRichard Tran Mills 83938d9b04SRichard Tran Mills .seealso: MatCreate(), MatCreateSeqAIJPERM(), MatSetValues() 84938d9b04SRichard Tran Mills @*/ 85938d9b04SRichard Tran Mills PetscErrorCode MatCreateMPIAIJPERM(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) 86938d9b04SRichard Tran Mills { 87938d9b04SRichard Tran Mills PetscErrorCode ierr; 88938d9b04SRichard Tran Mills PetscMPIInt size; 89938d9b04SRichard Tran Mills 90938d9b04SRichard Tran Mills PetscFunctionBegin; 91938d9b04SRichard Tran Mills ierr = MatCreate(comm,A);CHKERRQ(ierr); 92938d9b04SRichard Tran Mills ierr = MatSetSizes(*A,m,n,M,N);CHKERRQ(ierr); 93938d9b04SRichard Tran Mills ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 94938d9b04SRichard Tran Mills if (size > 1) { 95938d9b04SRichard Tran Mills ierr = MatSetType(*A,MATMPIAIJPERM);CHKERRQ(ierr); 96938d9b04SRichard Tran Mills ierr = MatMPIAIJSetPreallocation(*A,d_nz,d_nnz,o_nz,o_nnz);CHKERRQ(ierr); 97938d9b04SRichard Tran Mills } else { 98938d9b04SRichard Tran Mills ierr = MatSetType(*A,MATSEQAIJPERM);CHKERRQ(ierr); 99938d9b04SRichard Tran Mills ierr = MatSeqAIJSetPreallocation(*A,d_nz,d_nnz);CHKERRQ(ierr); 100938d9b04SRichard Tran Mills } 101938d9b04SRichard Tran Mills PetscFunctionReturn(0); 102938d9b04SRichard Tran Mills } 103938d9b04SRichard Tran Mills 104938d9b04SRichard Tran Mills PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJPERM(Mat B,PetscInt d_nz,const PetscInt d_nnz[],PetscInt o_nz,const PetscInt o_nnz[]) 105938d9b04SRichard Tran Mills { 106938d9b04SRichard Tran Mills Mat_MPIAIJ *b = (Mat_MPIAIJ*)B->data; 107938d9b04SRichard Tran Mills PetscErrorCode ierr; 108938d9b04SRichard Tran Mills 109938d9b04SRichard Tran Mills PetscFunctionBegin; 110938d9b04SRichard Tran Mills ierr = MatMPIAIJSetPreallocation_MPIAIJ(B,d_nz,d_nnz,o_nz,o_nnz);CHKERRQ(ierr); 111938d9b04SRichard Tran Mills ierr = MatConvert_SeqAIJ_SeqAIJPERM(b->A, MATSEQAIJPERM, MAT_INPLACE_MATRIX, &b->A);CHKERRQ(ierr); 112938d9b04SRichard Tran Mills ierr = MatConvert_SeqAIJ_SeqAIJPERM(b->B, MATSEQAIJPERM, MAT_INPLACE_MATRIX, &b->B);CHKERRQ(ierr); 113938d9b04SRichard Tran Mills PetscFunctionReturn(0); 114938d9b04SRichard Tran Mills } 115938d9b04SRichard Tran Mills 116938d9b04SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJPERM(Mat A,MatType type,MatReuse reuse,Mat *newmat) 117938d9b04SRichard Tran Mills { 118938d9b04SRichard Tran Mills PetscErrorCode ierr; 119938d9b04SRichard Tran Mills Mat B = *newmat; 120938d9b04SRichard Tran Mills 121938d9b04SRichard Tran Mills PetscFunctionBegin; 122938d9b04SRichard Tran Mills if (reuse == MAT_INITIAL_MATRIX) { 123938d9b04SRichard Tran Mills ierr = MatDuplicate(A,MAT_COPY_VALUES,&B);CHKERRQ(ierr); 124938d9b04SRichard Tran Mills } 125938d9b04SRichard Tran Mills 126938d9b04SRichard Tran Mills ierr = PetscObjectChangeTypeName((PetscObject) B, MATMPIAIJPERM);CHKERRQ(ierr); 127938d9b04SRichard Tran Mills ierr = PetscObjectComposeFunction((PetscObject)B,"MatMPIAIJSetPreallocation_C",MatMPIAIJSetPreallocation_MPIAIJPERM);CHKERRQ(ierr); 128938d9b04SRichard Tran Mills *newmat = B; 129938d9b04SRichard Tran Mills PetscFunctionReturn(0); 130938d9b04SRichard Tran Mills } 131938d9b04SRichard Tran Mills 132938d9b04SRichard Tran Mills PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJPERM(Mat A) 133938d9b04SRichard Tran Mills { 134938d9b04SRichard Tran Mills PetscErrorCode ierr; 135938d9b04SRichard Tran Mills 136938d9b04SRichard Tran Mills PetscFunctionBegin; 137938d9b04SRichard Tran Mills ierr = MatSetType(A,MATMPIAIJ);CHKERRQ(ierr); 138938d9b04SRichard Tran Mills ierr = MatConvert_MPIAIJ_MPIAIJPERM(A,MATMPIAIJPERM,MAT_INPLACE_MATRIX,&A);CHKERRQ(ierr); 139938d9b04SRichard Tran Mills PetscFunctionReturn(0); 140938d9b04SRichard Tran Mills } 141938d9b04SRichard Tran Mills 142938d9b04SRichard Tran Mills /*MC 143938d9b04SRichard Tran Mills MATAIJPERM - MATAIJPERM = "AIJPERM" - A matrix type to be used for sparse matrices. 144938d9b04SRichard Tran Mills 145938d9b04SRichard Tran Mills This matrix type is identical to MATSEQAIJPERM when constructed with a single process communicator, 146938d9b04SRichard Tran Mills and MATMPIAIJPERM otherwise. As a result, for single process communicators, 147938d9b04SRichard Tran Mills MatSeqAIJSetPreallocation() is supported, and similarly MatMPIAIJSetPreallocation() is supported 148938d9b04SRichard Tran Mills for communicators controlling multiple processes. It is recommended that you call both of 149938d9b04SRichard Tran Mills the above preallocation routines for simplicity. 150938d9b04SRichard Tran Mills 151938d9b04SRichard Tran Mills Options Database Keys: 152938d9b04SRichard Tran Mills . -mat_type aijperm - sets the matrix type to "AIJPERM" during a call to MatSetFromOptions() 153938d9b04SRichard Tran Mills 154938d9b04SRichard Tran Mills Level: beginner 155938d9b04SRichard Tran Mills 156938d9b04SRichard Tran Mills .seealso: MatCreateMPIAIJPERM(), MATSEQAIJPERM, MATMPIAIJPERM 157938d9b04SRichard Tran Mills M*/ 158938d9b04SRichard Tran Mills 159