xref: /petsc/src/mat/utils/gcreate.c (revision 3a40ed3dce77c081171d005ae1a6ff4bb9d13b6f)
1 #ifdef PETSC_RCS_HEADER
2 static char vcid[] = "$Id: gcreate.c,v 1.104 1997/07/09 20:56:43 balay Exp bsmith $";
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    Input Parameters:
17 .  m - number of global rows
18 .  n - number of global columns
19 .  comm - MPI communicator
20 
21    Output Parameter:
22 .  A - the matrix
23 
24    Basic Options Database Keys:
25    These options use MatCreateSeqXXX or MatCreateMPIXXX,
26    depending on the communicator, comm.
27 $    -mat_aij      : AIJ type
28 $    -mat_baij     : block AIJ type
29 $    -mat_dense    : dense type
30 $    -mat_bdiag    : block diagonal type
31 
32    More Options Database Keys:
33 $    -mat_seqaij   : AIJ type, uses MatCreateSeqAIJ()
34 $    -mat_mpiaij   : AIJ type, uses MatCreateMPIAIJ()
35 $    -mat_seqbdiag : block diagonal type, uses
36 $                    MatCreateSeqBDiag()
37 $    -mat_mpibdiag : block diagonal type, uses
38 $                    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 determind the matrix type.
51 
52 .keywords: matrix, create
53 
54 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(),
55           MatCreateSeqBDiag(),MatCreateMPIBDiag(),
56           MatCreateSeqDense(), MatCreateMPIDense(),
57           MatCreateMPIRowbs(), MatCreateSeqBAIJ,
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