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