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