xref: /petsc/src/mat/utils/gcreate.c (revision 758f395b27ac8d6dbc276772ed0d06fa12e89e10)
1 #ifdef PETSC_RCS_HEADER
2 static char vcid[] = "$Id: gcreate.c,v 1.110 1998/04/27 03:52:38 curfman Exp curfman $";
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 global rows
20 .  n - number of global columns
21 -  comm - MPI communicator
22 
23    Output Parameter:
24 .  A - the matrix
25 
26    Basic Options Database Keys:
27    These options use MatCreateSeqXXX or MatCreateMPIXXX,
28    depending on the communicator, comm.
29 +    -mat_aij      - AIJ type
30 .    -mat_baij     - block AIJ type
31 .    -mat_dense    - dense type
32 -    -mat_bdiag    - block diagonal type
33 
34    More Options Database Keys:
35 +    -mat_seqaij   - AIJ type, uses MatCreateSeqAIJ()
36 .    -mat_mpiaij   - AIJ type, uses MatCreateMPIAIJ()
37 .    -mat_seqbdiag - block diagonal type, uses MatCreateSeqBDiag()
38 .    -mat_mpibdiag - block diagonal type, uses MatCreateMPIBDiag()
39 .    -mat_mpirowbs - rowbs type, uses MatCreateMPIRowbs()
40 .    -mat_seqdense - dense type, uses MatCreateSeqDense()
41 .    -mat_mpidense - dense type, uses MatCreateMPIDense()
42 .    -mat_seqbaij  - block AIJ type, uses MatCreateSeqBAIJ()
43 -    -mat_mpibaij  - block AIJ type, uses MatCreateMPIBAIJ()
44 
45    Even More Options Database Keys:
46    See the manpages for particular formats (e.g., MatCreateSeqAIJ())
47    for additional format-specific options.
48 
49    Notes:
50    This routine calls MatGetTypeFromOptions() to determine the matrix type.
51 
52    Level: beginner
53 
54 .keywords: matrix, create
55 
56 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(),
57           MatCreateSeqBDiag(),MatCreateMPIBDiag(),
58           MatCreateSeqDense(), MatCreateMPIDense(),
59           MatCreateMPIRowbs(), MatCreateSeqBAIJ(), MatCreateMPIBAIJ()
60           MatConvert(), MatGetTypeFromOptions()
61 @*/
62 int MatCreate(MPI_Comm comm,int m,int n,Mat *A)
63 {
64   MatType    type;
65   PetscTruth set;
66   int        ierr, bs=1, flg;
67 
68   PetscFunctionBegin;
69   ierr = MatGetTypeFromOptions(comm,0,&type,&set); CHKERRQ(ierr);
70   switch (type) {
71   case MATSEQDENSE:
72     ierr = MatCreateSeqDense(comm,m,n,PETSC_NULL,A); CHKERRQ(ierr);
73     break;
74   case MATMPIBDIAG:
75     ierr = MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_DEFAULT,
76            PETSC_NULL,PETSC_NULL,A); CHKERRQ(ierr);
77     break;
78   case MATSEQBDIAG:
79     ierr = MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,
80            PETSC_NULL,A); CHKERRQ(ierr);
81     break;
82   case MATMPIROWBS:
83     ierr = MatCreateMPIRowbs(comm,PETSC_DECIDE,m,PETSC_DEFAULT,PETSC_NULL,
84            PETSC_NULL,A); CHKERRQ(ierr);
85     break;
86   case MATMPIDENSE:
87     ierr = MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,A); CHKERRQ(ierr);
88     break;
89   case MATMPIAIJ:
90     ierr = MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT,
91            PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
92     break;
93   case MATSEQBAIJ:
94     ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr);
95     ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
96     break;
97   case MATMPIBAIJ:
98     ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr);
99     ierr = MatCreateMPIBAIJ(comm,bs,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
100     break;
101   default:
102     ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
103     break;
104   }
105   PetscFunctionReturn(0);
106 }
107 
108 
109 
110 
111 
112