xref: /petsc/src/mat/utils/gcreate.c (revision 0713fee8a27481b0deeccc792613f84c28abcf5e)
1 #ifdef PETSC_RCS_HEADER
2 static char vcid[] = "$Id: gcreate.c,v 1.109 1998/04/23 21:58:05 bsmith 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 .keywords: matrix, create
53 
54 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(),
55           MatCreateSeqBDiag(),MatCreateMPIBDiag(),
56           MatCreateSeqDense(), MatCreateMPIDense(),
57           MatCreateMPIRowbs(), MatCreateSeqBAIJ(), MatCreateMPIBAIJ()
58           MatConvert(), MatGetTypeFromOptions()
59 @*/
60 int MatCreate(MPI_Comm comm,int m,int n,Mat *A)
61 {
62   MatType    type;
63   PetscTruth set;
64   int        ierr, bs=1, flg;
65 
66   PetscFunctionBegin;
67   ierr = MatGetTypeFromOptions(comm,0,&type,&set); CHKERRQ(ierr);
68   switch (type) {
69   case MATSEQDENSE:
70     ierr = MatCreateSeqDense(comm,m,n,PETSC_NULL,A); CHKERRQ(ierr);
71     break;
72   case MATMPIBDIAG:
73     ierr = MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_DEFAULT,
74            PETSC_NULL,PETSC_NULL,A); CHKERRQ(ierr);
75     break;
76   case MATSEQBDIAG:
77     ierr = MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,
78            PETSC_NULL,A); CHKERRQ(ierr);
79     break;
80   case MATMPIROWBS:
81     ierr = MatCreateMPIRowbs(comm,PETSC_DECIDE,m,PETSC_DEFAULT,PETSC_NULL,
82            PETSC_NULL,A); CHKERRQ(ierr);
83     break;
84   case MATMPIDENSE:
85     ierr = MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,A); CHKERRQ(ierr);
86     break;
87   case MATMPIAIJ:
88     ierr = MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT,
89            PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
90     break;
91   case MATSEQBAIJ:
92     ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr);
93     ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
94     break;
95   case MATMPIBAIJ:
96     ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr);
97     ierr = MatCreateMPIBAIJ(comm,bs,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
98     break;
99   default:
100     ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr);
101     break;
102   }
103   PetscFunctionReturn(0);
104 }
105 
106 
107 
108 
109 
110