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