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 411a5261eSBarry Smith portions are stored as `MATSEQAIJMKL` matrices (a matrix class that inherits 511a5261eSBarry Smith from `MATSEQAIJ` but uses some operations provided by Intel MKL). The same 611a5261eSBarry Smith guidelines that apply to `MATMPIAIJ` 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 13*2ef1f0ffSBarry Smith . 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 1711a5261eSBarry Smith x vector for the matrix-vector product y = Ax. (or `PETSC_DECIDE` to have 18*2ef1f0ffSBarry Smith calculated if N is given) For square matrices n is almost always `m`. 19*2ef1f0ffSBarry Smith . M - number of global rows (or `PETSC_DETERMINE` to have calculated if `m` is given) 20*2ef1f0ffSBarry Smith . 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) 25*2ef1f0ffSBarry Smith or `NULL`, if `d_nz` is used to specify the nonzero structure. 26*2ef1f0ffSBarry Smith 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 33*2ef1f0ffSBarry Smith 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 35*2ef1f0ffSBarry Smith of local rows, i.e `m`. 36a84739b8SRichard Tran Mills 37a84739b8SRichard Tran Mills Output Parameter: 38a84739b8SRichard Tran Mills . A - the matrix 39a84739b8SRichard Tran Mills 40*2ef1f0ffSBarry Smith Options Database Key: 41*2ef1f0ffSBarry Smith . -mat_aijmkl_no_spmv2 - disables use of the SpMV2 inspector-executor routines 42*2ef1f0ffSBarry Smith 43*2ef1f0ffSBarry Smith Level: intermediate 44*2ef1f0ffSBarry Smith 45a84739b8SRichard Tran Mills Notes: 46a84739b8SRichard Tran Mills If the *_nnz parameter is given then the *_nz parameter is ignored 47a84739b8SRichard Tran Mills 48*2ef1f0ffSBarry Smith `m`,`n`,`M`,`N` parameters specify the size of the matrix, and its partitioning across 49*2ef1f0ffSBarry Smith processors, while `d_nz`,`d_nnz`,`o_nz`,`o_nnz` parameters specify the approximate 50a84739b8SRichard Tran Mills storage requirements for this matrix. 51a84739b8SRichard Tran Mills 5211a5261eSBarry Smith If `PETSC_DECIDE` or `PETSC_DETERMINE` is used for a particular argument on one 53a84739b8SRichard Tran Mills processor than it must be used on all processors that share the object for 54a84739b8SRichard Tran Mills that argument. 55a84739b8SRichard Tran Mills 56a84739b8SRichard Tran Mills The user MUST specify either the local or global matrix dimensions 57a84739b8SRichard Tran Mills (possibly both). 58a84739b8SRichard Tran Mills 59a84739b8SRichard Tran Mills The parallel matrix is partitioned such that the first m0 rows belong to 60a84739b8SRichard Tran Mills process 0, the next m1 rows belong to process 1, the next m2 rows belong 61*2ef1f0ffSBarry Smith to process 2 etc.. where m0,m1,m2... are the input parameter `m`. 62a84739b8SRichard Tran Mills 63a84739b8SRichard Tran Mills The DIAGONAL portion of the local submatrix of a processor can be defined 64a84739b8SRichard Tran Mills as the submatrix which is obtained by extraction the part corresponding 65a84739b8SRichard Tran Mills to the rows r1-r2 and columns r1-r2 of the global matrix, where r1 is the 66a84739b8SRichard Tran Mills first row that belongs to the processor, and r2 is the last row belonging 67a84739b8SRichard Tran Mills to the this processor. This is a square mxm matrix. The remaining portion 68a84739b8SRichard Tran Mills of the local submatrix (mxN) constitute the OFF-DIAGONAL portion. 69a84739b8SRichard Tran Mills 70*2ef1f0ffSBarry Smith If `o_nnz`, `d_nnz` are specified, then `o_nz`, and `d_nz` are ignored. 71a84739b8SRichard Tran Mills 72a84739b8SRichard Tran Mills When calling this routine with a single process communicator, a matrix of 7311a5261eSBarry Smith type `MATSEQAIJMKL` is returned. If a matrix of type `MATMPIAIJMKL` is desired 74a84739b8SRichard Tran Mills for this type of communicator, use the construction mechanism: 7511a5261eSBarry Smith `MatCreate`(...,&A); `MatSetType`(A,MPIAIJMKL); `MatMPIAIJSetPreallocation`(A,...); 76a84739b8SRichard Tran Mills 77*2ef1f0ffSBarry Smith .seealso: [](chapter_matrices), `Mat`, [Sparse Matrix Creation](sec_matsparse), `MATMPIAIJMKL`, `MatCreate()`, `MatCreateSeqAIJMKL()`, `MatSetValues()` 78a84739b8SRichard Tran Mills @*/ 79d71ae5a4SJacob Faibussowitsch 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) 80d71ae5a4SJacob Faibussowitsch { 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 } 943ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 95a84739b8SRichard Tran Mills } 96a84739b8SRichard Tran Mills 97a84739b8SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJMKL(Mat, MatType, MatReuse, Mat *); 98a84739b8SRichard Tran Mills 99d71ae5a4SJacob Faibussowitsch PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJMKL(Mat B, PetscInt d_nz, const PetscInt d_nnz[], PetscInt o_nz, const PetscInt o_nnz[]) 100d71ae5a4SJacob Faibussowitsch { 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)); 1073ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 108a84739b8SRichard Tran Mills } 109a84739b8SRichard Tran Mills 110d71ae5a4SJacob Faibussowitsch PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJMKL(Mat A, MatType type, MatReuse reuse, Mat *newmat) 111d71ae5a4SJacob Faibussowitsch { 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; 1193ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 120a84739b8SRichard Tran Mills } 121a84739b8SRichard Tran Mills 122d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJMKL(Mat A) 123d71ae5a4SJacob Faibussowitsch { 124a84739b8SRichard Tran Mills PetscFunctionBegin; 1259566063dSJacob Faibussowitsch PetscCall(MatSetType(A, MATMPIAIJ)); 1269566063dSJacob Faibussowitsch PetscCall(MatConvert_MPIAIJ_MPIAIJMKL(A, MATMPIAIJMKL, MAT_INPLACE_MATRIX, &A)); 1273ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 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 13311a5261eSBarry Smith This matrix type is identical to `MATSEQAIJMKL` when constructed with a single process communicator, 13411a5261eSBarry Smith and `MATMPIAIJMKL` otherwise. As a result, for single process communicators, 13511a5261eSBarry Smith 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 139*2ef1f0ffSBarry Smith Options Database Key: 14011a5261eSBarry Smith . -mat_type aijmkl - sets the matrix type to `MATAIJMKL` during a call to `MatSetFromOptions()` 141a84739b8SRichard Tran Mills 142a84739b8SRichard Tran Mills Level: beginner 143a84739b8SRichard Tran Mills 144*2ef1f0ffSBarry Smith .seealso: [](chapter_matrices), `Mat`, `MATMPIAIJMKL`, `MATSEQAIJMKL`, `MatCreateMPIAIJMKL()`, `MATSEQAIJMKL`, `MATMPIAIJMKL`, `MATSEQAIJSELL`, `MATMPIAIJSELL`, `MATSEQAIJPERM`, `MATMPIAIJPERM` 145a84739b8SRichard Tran Mills M*/ 146