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 520f4b53cSBarry Smith from `MATSEQAIJ` but uses some operations provided by Intel MKL). 6a84739b8SRichard Tran Mills 7d083f849SBarry Smith Collective 8a84739b8SRichard Tran Mills 9a84739b8SRichard Tran Mills Input Parameters: 10a84739b8SRichard Tran Mills + comm - MPI communicator 112ef1f0ffSBarry Smith . m - number of local rows (or `PETSC_DECIDE` to have calculated if `M` is given) 12a84739b8SRichard Tran Mills This value should be the same as the local size used in creating the 13a84739b8SRichard Tran Mills y vector for the matrix-vector product y = Ax. 14a84739b8SRichard Tran Mills . n - This value should be the same as the local size used in creating the 1511a5261eSBarry Smith x vector for the matrix-vector product y = Ax. (or `PETSC_DECIDE` to have 162ef1f0ffSBarry Smith calculated if N is given) For square matrices n is almost always `m`. 172ef1f0ffSBarry Smith . M - number of global rows (or `PETSC_DETERMINE` to have calculated if `m` is given) 182ef1f0ffSBarry Smith . N - number of global columns (or `PETSC_DETERMINE` to have calculated if `n` is given) 19a84739b8SRichard Tran Mills . d_nz - number of nonzeros per row in DIAGONAL portion of local submatrix 20a84739b8SRichard Tran Mills (same value is used for all local rows) 21a84739b8SRichard Tran Mills . d_nnz - array containing the number of nonzeros in the various rows of the 22a84739b8SRichard Tran Mills DIAGONAL portion of the local submatrix (possibly different for each row) 232ef1f0ffSBarry Smith or `NULL`, if `d_nz` is used to specify the nonzero structure. 242ef1f0ffSBarry Smith The size of this array is equal to the number of local rows, i.e `m`. 25a84739b8SRichard Tran Mills For matrices you plan to factor you must leave room for the diagonal entry and 26a84739b8SRichard Tran Mills put in the entry even if it is zero. 27a84739b8SRichard Tran Mills . o_nz - number of nonzeros per row in the OFF-DIAGONAL portion of local 28a84739b8SRichard Tran Mills submatrix (same value is used for all local rows). 29a84739b8SRichard Tran Mills - o_nnz - array containing the number of nonzeros in the various rows of the 30a84739b8SRichard Tran Mills OFF-DIAGONAL portion of the local submatrix (possibly different for 312ef1f0ffSBarry Smith each row) or `NULL`, if `o_nz` is used to specify the nonzero 32a84739b8SRichard Tran Mills structure. The size of this array is equal to the number 332ef1f0ffSBarry Smith of local rows, i.e `m`. 34a84739b8SRichard Tran Mills 35a84739b8SRichard Tran Mills Output Parameter: 36a84739b8SRichard Tran Mills . A - the matrix 37a84739b8SRichard Tran Mills 382ef1f0ffSBarry Smith Options Database Key: 392ef1f0ffSBarry Smith . -mat_aijmkl_no_spmv2 - disables use of the SpMV2 inspector-executor routines 402ef1f0ffSBarry Smith 412ef1f0ffSBarry Smith Level: intermediate 422ef1f0ffSBarry Smith 43a84739b8SRichard Tran Mills Notes: 44a84739b8SRichard Tran Mills If the *_nnz parameter is given then the *_nz parameter is ignored 45a84739b8SRichard Tran Mills 462ef1f0ffSBarry Smith `m`,`n`,`M`,`N` parameters specify the size of the matrix, and its partitioning across 472ef1f0ffSBarry Smith processors, while `d_nz`,`d_nnz`,`o_nz`,`o_nnz` parameters specify the approximate 48a84739b8SRichard Tran Mills storage requirements for this matrix. 49a84739b8SRichard Tran Mills 5011a5261eSBarry Smith If `PETSC_DECIDE` or `PETSC_DETERMINE` is used for a particular argument on one 51a84739b8SRichard Tran Mills processor than it must be used on all processors that share the object for 52a84739b8SRichard Tran Mills that argument. 53a84739b8SRichard Tran Mills 54a84739b8SRichard Tran Mills The user MUST specify either the local or global matrix dimensions 55a84739b8SRichard Tran Mills (possibly both). 56a84739b8SRichard Tran Mills 57a84739b8SRichard Tran Mills The parallel matrix is partitioned such that the first m0 rows belong to 58a84739b8SRichard Tran Mills process 0, the next m1 rows belong to process 1, the next m2 rows belong 592ef1f0ffSBarry Smith to process 2 etc.. where m0,m1,m2... are the input parameter `m`. 60a84739b8SRichard Tran Mills 61a84739b8SRichard Tran Mills The DIAGONAL portion of the local submatrix of a processor can be defined 62a84739b8SRichard Tran Mills as the submatrix which is obtained by extraction the part corresponding 63a84739b8SRichard Tran Mills to the rows r1-r2 and columns r1-r2 of the global matrix, where r1 is the 64a84739b8SRichard Tran Mills first row that belongs to the processor, and r2 is the last row belonging 65a84739b8SRichard Tran Mills to the this processor. This is a square mxm matrix. The remaining portion 66a84739b8SRichard Tran Mills of the local submatrix (mxN) constitute the OFF-DIAGONAL portion. 67a84739b8SRichard Tran Mills 682ef1f0ffSBarry Smith If `o_nnz`, `d_nnz` are specified, then `o_nz`, and `d_nz` are ignored. 69a84739b8SRichard Tran Mills 70a84739b8SRichard Tran Mills When calling this routine with a single process communicator, a matrix of 7111a5261eSBarry Smith type `MATSEQAIJMKL` is returned. If a matrix of type `MATMPIAIJMKL` is desired 7220f4b53cSBarry Smith for this type of communicator, use the construction mechanism 7320f4b53cSBarry Smith .vb 7420f4b53cSBarry Smith MatCreate(...,&A); 7520f4b53cSBarry Smith MatSetType(A,MPIAIJMKL); 7620f4b53cSBarry Smith MatMPIAIJSetPreallocation(A,...); 7720f4b53cSBarry Smith .ve 78a84739b8SRichard Tran Mills 79*1cc06b55SBarry Smith .seealso: [](ch_matrices), `Mat`, [Sparse Matrix Creation](sec_matsparse), `MATMPIAIJMKL`, `MatCreate()`, `MatCreateSeqAIJMKL()`, `MatSetValues()` 80a84739b8SRichard Tran Mills @*/ 81d71ae5a4SJacob 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) 82d71ae5a4SJacob Faibussowitsch { 83a84739b8SRichard Tran Mills PetscMPIInt size; 84a84739b8SRichard Tran Mills 85a84739b8SRichard Tran Mills PetscFunctionBegin; 869566063dSJacob Faibussowitsch PetscCall(MatCreate(comm, A)); 879566063dSJacob Faibussowitsch PetscCall(MatSetSizes(*A, m, n, M, N)); 889566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_size(comm, &size)); 89a84739b8SRichard Tran Mills if (size > 1) { 909566063dSJacob Faibussowitsch PetscCall(MatSetType(*A, MATMPIAIJMKL)); 919566063dSJacob Faibussowitsch PetscCall(MatMPIAIJSetPreallocation(*A, d_nz, d_nnz, o_nz, o_nnz)); 92a84739b8SRichard Tran Mills } else { 939566063dSJacob Faibussowitsch PetscCall(MatSetType(*A, MATSEQAIJMKL)); 949566063dSJacob Faibussowitsch PetscCall(MatSeqAIJSetPreallocation(*A, d_nz, d_nnz)); 95a84739b8SRichard Tran Mills } 963ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 97a84739b8SRichard Tran Mills } 98a84739b8SRichard Tran Mills 99a84739b8SRichard Tran Mills PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJMKL(Mat, MatType, MatReuse, Mat *); 100a84739b8SRichard Tran Mills 101d71ae5a4SJacob Faibussowitsch PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJMKL(Mat B, PetscInt d_nz, const PetscInt d_nnz[], PetscInt o_nz, const PetscInt o_nnz[]) 102d71ae5a4SJacob Faibussowitsch { 103a84739b8SRichard Tran Mills Mat_MPIAIJ *b = (Mat_MPIAIJ *)B->data; 104a84739b8SRichard Tran Mills 105a84739b8SRichard Tran Mills PetscFunctionBegin; 1069566063dSJacob Faibussowitsch PetscCall(MatMPIAIJSetPreallocation_MPIAIJ(B, d_nz, d_nnz, o_nz, o_nnz)); 1079566063dSJacob Faibussowitsch PetscCall(MatConvert_SeqAIJ_SeqAIJMKL(b->A, MATSEQAIJMKL, MAT_INPLACE_MATRIX, &b->A)); 1089566063dSJacob Faibussowitsch PetscCall(MatConvert_SeqAIJ_SeqAIJMKL(b->B, MATSEQAIJMKL, MAT_INPLACE_MATRIX, &b->B)); 1093ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 110a84739b8SRichard Tran Mills } 111a84739b8SRichard Tran Mills 112d71ae5a4SJacob Faibussowitsch PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJMKL(Mat A, MatType type, MatReuse reuse, Mat *newmat) 113d71ae5a4SJacob Faibussowitsch { 114a84739b8SRichard Tran Mills Mat B = *newmat; 115a84739b8SRichard Tran Mills 116a84739b8SRichard Tran Mills PetscFunctionBegin; 1179566063dSJacob Faibussowitsch if (reuse == MAT_INITIAL_MATRIX) PetscCall(MatDuplicate(A, MAT_COPY_VALUES, &B)); 1189566063dSJacob Faibussowitsch PetscCall(PetscObjectChangeTypeName((PetscObject)B, MATMPIAIJMKL)); 1199566063dSJacob Faibussowitsch PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatMPIAIJSetPreallocation_C", MatMPIAIJSetPreallocation_MPIAIJMKL)); 120a84739b8SRichard Tran Mills *newmat = B; 1213ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 122a84739b8SRichard Tran Mills } 123a84739b8SRichard Tran Mills 124d71ae5a4SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJMKL(Mat A) 125d71ae5a4SJacob Faibussowitsch { 126a84739b8SRichard Tran Mills PetscFunctionBegin; 1279566063dSJacob Faibussowitsch PetscCall(MatSetType(A, MATMPIAIJ)); 1289566063dSJacob Faibussowitsch PetscCall(MatConvert_MPIAIJ_MPIAIJMKL(A, MATMPIAIJMKL, MAT_INPLACE_MATRIX, &A)); 1293ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 130a84739b8SRichard Tran Mills } 131a84739b8SRichard Tran Mills 132a84739b8SRichard Tran Mills /*MC 133a84739b8SRichard Tran Mills MATAIJMKL - MATAIJMKL = "AIJMKL" - A matrix type to be used for sparse matrices. 134a84739b8SRichard Tran Mills 13511a5261eSBarry Smith This matrix type is identical to `MATSEQAIJMKL` when constructed with a single process communicator, 13611a5261eSBarry Smith and `MATMPIAIJMKL` otherwise. As a result, for single process communicators, 13711a5261eSBarry Smith MatSeqAIJSetPreallocation() is supported, and similarly `MatMPIAIJSetPreallocation()` is supported 138a84739b8SRichard Tran Mills for communicators controlling multiple processes. It is recommended that you call both of 139a84739b8SRichard Tran Mills the above preallocation routines for simplicity. 140a84739b8SRichard Tran Mills 1412ef1f0ffSBarry Smith Options Database Key: 14211a5261eSBarry Smith . -mat_type aijmkl - sets the matrix type to `MATAIJMKL` during a call to `MatSetFromOptions()` 143a84739b8SRichard Tran Mills 144a84739b8SRichard Tran Mills Level: beginner 145a84739b8SRichard Tran Mills 146*1cc06b55SBarry Smith .seealso: [](ch_matrices), `Mat`, `MATMPIAIJMKL`, `MATSEQAIJMKL`, `MatCreateMPIAIJMKL()`, `MATSEQAIJMKL`, `MATMPIAIJMKL`, `MATSEQAIJSELL`, `MATMPIAIJSELL`, `MATSEQAIJPERM`, `MATMPIAIJPERM` 147a84739b8SRichard Tran Mills M*/ 148