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).

      7:   Collective

      9:   Input Parameters:
     10: + comm  - MPI communicator
     11: . m     - number of local rows (or `PETSC_DECIDE` to have calculated if `M` is given)
     12:            This value should be the same as the local size used in creating the
     13:            y vector for the matrix-vector product y = Ax.
     14: . n     - This value should be the same as the local size used in creating the
     15:        x vector for the matrix-vector product y = Ax. (or `PETSC_DECIDE` to have
     16:        calculated if N is given) For square matrices n is almost always `m`.
     17: . M     - number of global rows (or `PETSC_DETERMINE` to have calculated if `m` is given)
     18: . N     - number of global columns (or `PETSC_DETERMINE` to have calculated if `n` is given)
     19: . d_nz  - number of nonzeros per row in DIAGONAL portion of local submatrix
     20:            (same value is used for all local rows)
     21: . d_nnz - array containing the number of nonzeros in the various rows of the
     22:            DIAGONAL portion of the local submatrix (possibly different for each row)
     23:            or `NULL`, if `d_nz` is used to specify the nonzero structure.
     24:            The size of this array is equal to the number of local rows, i.e `m`.
     25:            For matrices you plan to factor you must leave room for the diagonal entry and
     26:            put in the entry even if it is zero.
     27: . o_nz  - number of nonzeros per row in the OFF-DIAGONAL portion of local
     28:            submatrix (same value is used for all local rows).
     29: - o_nnz - array containing the number of nonzeros in the various rows of the
     30:            OFF-DIAGONAL portion of the local submatrix (possibly different for
     31:            each row) or `NULL`, if `o_nz` is used to specify the nonzero
     32:            structure. The size of this array is equal to the number
     33:            of local rows, i.e `m`.

     35:   Output Parameter:
     36: . A - the matrix

     38:   Options Database Key:
     39: . -mat_aijmkl_no_spmv2 - disables use of the SpMV2 inspector-executor routines

     41:   Level: intermediate

     43:   Notes:
     44:   If the *_nnz parameter is given then the *_nz parameter is ignored

     46:   `m`,`n`,`M`,`N` parameters specify the size of the matrix, and its partitioning across
     47:   processors, while `d_nz`,`d_nnz`,`o_nz`,`o_nnz` parameters specify the approximate
     48:   storage requirements for this matrix.

     50:   If `PETSC_DECIDE` or `PETSC_DETERMINE` is used for a particular argument on one
     51:   processor than it must be used on all processors that share the object for
     52:   that argument.

     54:   The user MUST specify either the local or global matrix dimensions
     55:   (possibly both).

     57:   If `m` and `n` are not `PETSC_DECIDE`, then the values determine the `PetscLayout` of the matrix and the ranges returned by
     58:   `MatGetOwnershipRange()`, `MatGetOwnershipRanges()`, `MatGetOwnershipRangeColumn()`, and `MatGetOwnershipRangesColumn()`.

     60:   The parallel matrix is partitioned such that the first `m0` rows belong to
     61:   process 0, the next `m1` rows belong to process 1, the next `m2` rows belong
     62:   to process 2, etc., where `m0`, `m1`, `m2`... are the input parameter `m` on each MPI process.

     64:   The DIAGONAL portion of the local submatrix of a processor can be defined
     65:   as the submatrix which is obtained by extraction the part corresponding
     66:   to the rows `r1` - `r2` and columns `r1` - `r2` of the global matrix, where `r1` is the
     67:   first row that belongs to the processor, and `r2` is the last row belonging
     68:   to the this processor. This is a square mxm matrix. The remaining portion
     69:   of the local submatrix (mxN) constitute the OFF-DIAGONAL portion.

     71:   If `o_nnz`, `d_nnz` are specified, then `o_nz`, and `d_nz` are ignored.

     73:   When calling this routine with a single process communicator, a matrix of
     74:   type `MATSEQAIJMKL` is returned.  If a matrix of type `MATMPIAIJMKL` is desired
     75:   for this type of communicator, use the construction mechanism
     76: .vb
     77:   MatCreate(...,&A);
     78:   MatSetType(A,MPIAIJMKL);
     79:   MatMPIAIJSetPreallocation(A,...);
     80: .ve

     82: .seealso: [](ch_matrices), `Mat`, [Sparse Matrix Creation](sec_matsparse), `MATMPIAIJMKL`, `MatCreate()`, `MatCreateSeqAIJMKL()`,
     83:           `MatSetValues()`, `MatGetOwnershipRange()`, `MatGetOwnershipRanges()`, `MatGetOwnershipRangeColumn()`,
     84:           `MatGetOwnershipRangesColumn()`, `PetscLayout`
     85: @*/
     86: 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)
     87: {
     88:   PetscMPIInt size;

     90:   PetscFunctionBegin;
     91:   PetscCall(MatCreate(comm, A));
     92:   PetscCall(MatSetSizes(*A, m, n, M, N));
     93:   PetscCallMPI(MPI_Comm_size(comm, &size));
     94:   if (size > 1) {
     95:     PetscCall(MatSetType(*A, MATMPIAIJMKL));
     96:     PetscCall(MatMPIAIJSetPreallocation(*A, d_nz, d_nnz, o_nz, o_nnz));
     97:   } else {
     98:     PetscCall(MatSetType(*A, MATSEQAIJMKL));
     99:     PetscCall(MatSeqAIJSetPreallocation(*A, d_nz, d_nnz));
    100:   }
    101:   PetscFunctionReturn(PETSC_SUCCESS);
    102: }

    104: PETSC_INTERN PetscErrorCode MatConvert_SeqAIJ_SeqAIJMKL(Mat, MatType, MatReuse, Mat *);

    106: static PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJMKL(Mat B, PetscInt d_nz, const PetscInt d_nnz[], PetscInt o_nz, const PetscInt o_nnz[])
    107: {
    108:   Mat_MPIAIJ *b = (Mat_MPIAIJ *)B->data;

    110:   PetscFunctionBegin;
    111:   PetscCall(MatMPIAIJSetPreallocation_MPIAIJ(B, d_nz, d_nnz, o_nz, o_nnz));
    112:   PetscCall(MatConvert_SeqAIJ_SeqAIJMKL(b->A, MATSEQAIJMKL, MAT_INPLACE_MATRIX, &b->A));
    113:   PetscCall(MatConvert_SeqAIJ_SeqAIJMKL(b->B, MATSEQAIJMKL, MAT_INPLACE_MATRIX, &b->B));
    114:   PetscFunctionReturn(PETSC_SUCCESS);
    115: }

    117: PETSC_INTERN PetscErrorCode MatConvert_MPIAIJ_MPIAIJMKL(Mat A, MatType type, MatReuse reuse, Mat *newmat)
    118: {
    119:   Mat B = *newmat;

    121:   PetscFunctionBegin;
    122:   if (reuse == MAT_INITIAL_MATRIX) PetscCall(MatDuplicate(A, MAT_COPY_VALUES, &B));
    123:   PetscCall(PetscObjectChangeTypeName((PetscObject)B, MATMPIAIJMKL));
    124:   PetscCall(PetscObjectComposeFunction((PetscObject)B, "MatMPIAIJSetPreallocation_C", MatMPIAIJSetPreallocation_MPIAIJMKL));
    125:   *newmat = B;
    126:   PetscFunctionReturn(PETSC_SUCCESS);
    127: }

    129: PETSC_EXTERN PetscErrorCode MatCreate_MPIAIJMKL(Mat A)
    130: {
    131:   PetscFunctionBegin;
    132:   PetscCall(MatSetType(A, MATMPIAIJ));
    133:   PetscCall(MatConvert_MPIAIJ_MPIAIJMKL(A, MATMPIAIJMKL, MAT_INPLACE_MATRIX, &A));
    134:   PetscFunctionReturn(PETSC_SUCCESS);
    135: }

    137: /*MC
    138:    MATAIJMKL - MATAIJMKL = "AIJMKL" - A matrix type to be used for sparse matrices.

    140:    This matrix type is identical to `MATSEQAIJMKL` when constructed with a single process communicator,
    141:    and `MATMPIAIJMKL` otherwise.  As a result, for single process communicators,
    142:   MatSeqAIJSetPreallocation() is supported, and similarly `MatMPIAIJSetPreallocation()` is supported
    143:   for communicators controlling multiple processes.  It is recommended that you call both of
    144:   the above preallocation routines for simplicity.

    146:    Options Database Key:
    147: . -mat_type aijmkl - sets the matrix type to `MATAIJMKL` during a call to `MatSetFromOptions()`

    149:   Level: beginner

    151: .seealso: [](ch_matrices), `Mat`, `MATMPIAIJMKL`, `MATSEQAIJMKL`, `MatCreateMPIAIJMKL()`, `MATSEQAIJMKL`, `MATMPIAIJMKL`, `MATSEQAIJSELL`, `MATMPIAIJSELL`, `MATSEQAIJPERM`, `MATMPIAIJPERM`
    152: M*/