xref: /petsc/src/mat/utils/gcreate.c (revision 7411e5dbc8dd9aaa8344ef355aeda9bcaeb679a8)
1 #ifdef PETSC_RCS_HEADER
2 static char vcid[] = "$Id: gcreate.c,v 1.113 1999/05/04 20:33:40 balay Exp balay $";
3 #endif
4 
5 #include "sys.h"
6 #include "mat.h"       /*I "mat.h"  I*/
7 
8 #undef __FUNC__
9 #define __FUNC__ "MatCreate"
10 /*@C
11    MatCreate - Creates a matrix where the type is determined
12    from the options database. Generates a parallel MPI matrix if the
13    communicator has more than one processor.  The default matrix type is
14    AIJ, using the routines MatCreateSeqAIJ() and MatCreateMPIAIJ().
15 
16    Collective on MPI_Comm
17 
18    Input Parameters:
19 +  m - number of local rows (or PETSC_DECIDE)
20 .  n - number of local columns (or PETSC_DECIDE)
21 .  M - number of global rows (or PETSC_DETERMINE)
22 .  N - number of global columns (or PETSC_DETERMINE)
23 -  comm - MPI communicator
24 
25    Output Parameter:
26 .  A - the matrix
27 
28    Basic Options Database Keys:
29    These options use MatCreateSeqXXX or MatCreateMPIXXX,
30    depending on the communicator, comm.
31 +    -mat_aij      - AIJ type
32 .    -mat_baij     - block AIJ type
33 .    -mat_dense    - dense type
34 -    -mat_bdiag    - block diagonal type
35 
36    More Options Database Keys:
37 +    -mat_seqaij   - AIJ type, uses MatCreateSeqAIJ()
38 .    -mat_mpiaij   - AIJ type, uses MatCreateMPIAIJ()
39 .    -mat_seqbdiag - block diagonal type, uses MatCreateSeqBDiag()
40 .    -mat_mpibdiag - block diagonal type, uses MatCreateMPIBDiag()
41 .    -mat_mpirowbs - rowbs type, uses MatCreateMPIRowbs()
42 .    -mat_seqdense - dense type, uses MatCreateSeqDense()
43 .    -mat_mpidense - dense type, uses MatCreateMPIDense()
44 .    -mat_seqbaij  - block AIJ type, uses MatCreateSeqBAIJ()
45 -    -mat_mpibaij  - block AIJ type, uses MatCreateMPIBAIJ()
46 
47    Even More Options Database Keys:
48    See the manpages for particular formats (e.g., MatCreateSeqAIJ())
49    for additional format-specific options.
50 
51    Notes:
52    If PETSC_DECIDE is not used for the arguments 'm' and 'n', then the
53    user must ensure that they are chosen to be compatible with the
54    vectors. To do this, one first considers the matrix-vector product
55    'y = A x'. The 'm' that is used in the above routine must match the
56    local size used in the vector creation routine VecCreateMPI() for 'y'.
57    Likewise, the 'n' used must match that used as the local size in
58    VecCreateMPI() for 'x'.
59 
60    This routine calls MatGetTypeFromOptions() to determine the matrix type.
61 
62    Level: beginner
63 
64 .keywords: matrix, create
65 
66 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(),
67           MatCreateSeqBDiag(),MatCreateMPIBDiag(),
68           MatCreateSeqDense(), MatCreateMPIDense(),
69           MatCreateMPIRowbs(), MatCreateSeqBAIJ(), MatCreateMPIBAIJ()
70           MatConvert(), MatGetTypeFromOptions()
71 @*/
72 int MatCreate(MPI_Comm comm,int m,int n,int M,int N,Mat *A)
73 {
74   MatType    type;
75   PetscTruth set;
76   int        ierr, bs=1, flg;
77 
78   PetscFunctionBegin;
79   ierr = MatGetTypeFromOptions(comm,0,&type,&set);CHKERRQ(ierr);
80   switch (type) {
81   case MATSEQDENSE:
82     m    = PetscMax(m,M);
83     n    = PetscMax(n,N);
84     ierr = MatCreateSeqDense(comm,m,n,PETSC_NULL,A);CHKERRQ(ierr);
85     break;
86   case MATMPIBDIAG:
87     ierr = MatCreateMPIBDiag(comm,m,M,N,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr);
88     break;
89   case MATSEQBDIAG:
90     m    = PetscMax(m,M);
91     n    = PetscMax(n,N);
92     ierr = MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr);
93     break;
94   case MATMPIROWBS:
95     ierr = MatCreateMPIRowbs(comm,m,M,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr);
96     break;
97   case MATMPIDENSE:
98     ierr = MatCreateMPIDense(comm,m,n,M,N,PETSC_NULL,A);CHKERRQ(ierr);
99     break;
100   case MATMPIAIJ:
101     ierr = MatCreateMPIAIJ(comm,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr);
102     break;
103   case MATSEQBAIJ:
104     m    = PetscMax(m,M);
105     n    = PetscMax(n,N);
106     ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg);CHKERRQ(ierr);
107     ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr);
108     break;
109   case MATMPIBAIJ:
110     ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg);CHKERRQ(ierr);
111     ierr = MatCreateMPIBAIJ(comm,bs,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr);
112     break;
113   default:
114     m    = PetscMax(m,M);
115     n    = PetscMax(n,N);
116     ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr);
117     break;
118   }
119   PetscFunctionReturn(0);
120 }
121 
122 
123 
124 
125 
126