Actual source code: mpicsrperm.c

petsc-3.3-p7 2013-05-11
  2: #include <../src/mat/impls/aij/mpi/mpiaij.h>
  5: /*@C
  6:    MatCreateMPIAIJPERM - Creates a sparse parallel matrix whose local 
  7:    portions are stored as SEQAIJPERM matrices (a matrix class that inherits 
  8:    from SEQAIJ but includes some optimizations to allow more effective 
  9:    vectorization).  The same guidelines that apply to MPIAIJ matrices for 
 10:    preallocating the matrix storage apply here as well.

 12:       Collective on MPI_Comm

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

 40:    Output Parameter:
 41: .  A - the matrix 

 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:    The parallel matrix is partitioned such that the first m0 rows belong to 
 58:    process 0, the next m1 rows belong to process 1, the next m2 rows belong 
 59:    to process 2 etc.. where m0,m1,m2... are the input parameter 'm'.

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

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

 70:    When calling this routine with a single process communicator, a matrix of
 71:    type SEQAIJPERM is returned.  If a matrix of type MPIAIJPERM is desired 
 72:    for this type of communicator, use the construction mechanism:
 73:      MatCreate(...,&A); MatSetType(A,MPIAIJ); MatMPIAIJSetPreallocation(A,...);

 75:    By default, this format uses inodes (identical nodes) when possible.
 76:    We search for consecutive rows with the same nonzero structure, thereby
 77:    reusing matrix information to achieve increased efficiency.

 79:    Options Database Keys:
 80: +  -mat_no_inode  - Do not use inodes
 81: .  -mat_inode_limit <limit> - Sets inode limit (max limit=5)
 82: -  -mat_aij_oneindex - Internally use indexing starting at 1
 83:         rather than 0.  Note that when calling MatSetValues(),
 84:         the user still MUST index entries starting at 0!

 86:    Level: intermediate

 88: .keywords: matrix, cray, sparse, parallel

 90: .seealso: MatCreate(), MatCreateSeqAIJPERM(), MatSetValues()
 91: @*/
 92: PetscErrorCode  MatCreateMPIAIJPERM(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)
 93: {
 95:   PetscMPIInt    size;

 98:   MatCreate(comm,A);
 99:   MatSetSizes(*A,m,n,M,N);
100:   MPI_Comm_size(comm,&size);
101:   if (size > 1) {
102:     MatSetType(*A,MATMPIAIJPERM);
103:     MatMPIAIJSetPreallocation(*A,d_nz,d_nnz,o_nz,o_nnz);
104:   } else {
105:     MatSetType(*A,MATSEQAIJPERM);
106:     MatSeqAIJSetPreallocation(*A,d_nz,d_nnz);
107:   }
108:   return(0);
109: }

111: EXTERN_C_BEGIN
112: extern PetscErrorCode MatConvert_SeqAIJ_SeqAIJPERM(Mat,const MatType,MatReuse,Mat*);
113: extern PetscErrorCode MatMPIAIJSetPreallocation_MPIAIJ(Mat,PetscInt,const PetscInt[],PetscInt,const PetscInt[]);
114: EXTERN_C_END

116: EXTERN_C_BEGIN
119: PetscErrorCode  MatMPIAIJSetPreallocation_MPIAIJPERM(Mat B,PetscInt d_nz,const PetscInt d_nnz[],PetscInt o_nz,const PetscInt o_nnz[])
120: {
121:   Mat_MPIAIJ     *b = (Mat_MPIAIJ*)B->data;

125:   MatMPIAIJSetPreallocation_MPIAIJ(B,d_nz,d_nnz,o_nz,o_nnz);
126:   MatConvert_SeqAIJ_SeqAIJPERM(b->A, MATSEQAIJPERM, MAT_REUSE_MATRIX, &b->A);
127:   MatConvert_SeqAIJ_SeqAIJPERM(b->B, MATSEQAIJPERM, MAT_REUSE_MATRIX, &b->B);
128:   return(0);
129: }
130: EXTERN_C_END

132: EXTERN_C_BEGIN
135: PetscErrorCode  MatConvert_MPIAIJ_MPIAIJPERM(Mat A,const MatType type,MatReuse reuse,Mat *newmat)
136: {
138:   Mat            B = *newmat;

141:   if (reuse == MAT_INITIAL_MATRIX) {
142:     MatDuplicate(A,MAT_COPY_VALUES,&B);
143:   }

145:   PetscObjectChangeTypeName( (PetscObject) B, MATMPIAIJPERM);
146:   PetscObjectComposeFunctionDynamic((PetscObject)B,"MatMPIAIJSetPreallocation_C",
147:                                      "MatMPIAIJSetPreallocation_MPIAIJPERM",
148:                                      MatMPIAIJSetPreallocation_MPIAIJPERM);
149:   *newmat = B;
150:   return(0);
151: }
152: EXTERN_C_END


155: EXTERN_C_BEGIN
158: PetscErrorCode  MatCreate_MPIAIJPERM(Mat A)
159: {

163:   MatSetType(A,MATMPIAIJ);
164:   MatConvert_MPIAIJ_MPIAIJPERM(A,MATMPIAIJPERM,MAT_REUSE_MATRIX,&A);
165:   return(0);
166: }
167: EXTERN_C_END

169: /*MC
170:    MATAIJPERM - MATAIJPERM = "AIJPERM" - A matrix type to be used for sparse matrices.

172:    This matrix type is identical to MATSEQAIJPERM when constructed with a single process communicator,
173:    and MATMPIAIJPERM otherwise.  As a result, for single process communicators, 
174:   MatSeqAIJSetPreallocation() is supported, and similarly MatMPIAIJSetPreallocation() is supported 
175:   for communicators controlling multiple processes.  It is recommended that you call both of
176:   the above preallocation routines for simplicity.

178:    Options Database Keys:
179: . -mat_type aijperm - sets the matrix type to "AIJPERM" during a call to MatSetFromOptions()

181:   Level: beginner

183: .seealso: MatCreateMPIAIJPERM(), MATSEQAIJPERM, MATMPIAIJPERM
184: M*/