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