xref: /petsc/src/mat/utils/gcreate.c (revision d2dddef78eaf156b55f3bc8f3ebd813d1a1e7061)
1 
2 #ifndef lint
3 static char vcid[] = "$Id: gcreate.c,v 1.102 1997/01/27 18:17:25 bsmith Exp bsmith $";
4 #endif
5 
6 #include "sys.h"
7 #include "mat.h"       /*I "mat.h"  I*/
8 
9 #undef __FUNC__
10 #define __FUNC__ "MatCreate"
11 /*@C
12    MatCreate - Creates a matrix where the type is determined
13    from the options database. Generates a parallel MPI matrix if the
14    communicator has more than one processor.  The default matrix type is
15    AIJ, using the routines MatCreateSeqAIJ() and MatCreateMPIAIJ().
16 
17    Input Parameters:
18 .  m - number of global rows
19 .  n - number of global columns
20 .  comm - MPI communicator
21 
22    Output Parameter:
23 .  A - the matrix
24 
25    Basic Options Database Keys:
26    These options use MatCreateSeqXXX or MatCreateMPIXXX,
27    depending on the communicator, comm.
28 $    -mat_aij      : AIJ type
29 $    -mat_baij     : block AIJ type
30 $    -mat_dense    : dense type
31 $    -mat_bdiag    : block diagonal type
32 
33    More Options Database Keys:
34 $    -mat_seqaij   : AIJ type, uses MatCreateSeqAIJ()
35 $    -mat_mpiaij   : AIJ type, uses MatCreateMPIAIJ()
36 $    -mat_seqbdiag : block diagonal type, uses
37 $                    MatCreateSeqBDiag()
38 $    -mat_mpibdiag : block diagonal type, uses
39 $                    MatCreateMPIBDiag()
40 $    -mat_mpirowbs : rowbs type, uses MatCreateMPIRowbs()
41 $    -mat_seqdense : dense type, uses MatCreateSeqDense()
42 $    -mat_mpidense : dense type, uses MatCreateMPIDense()
43 $    -mat_seqbaij  : block AIJ type, uses MatCreateSeqBAIJ()
44 $    -mat_mpibaij  : block AIJ type, uses MatCreateMPIBAIJ()
45 
46    Even More Options Database Keys:
47    See the manpages for particular formats (e.g., MatCreateSeqAIJ())
48    for additional format-specific options.
49 
50    Notes:
51    This routine calls MatGetTypeFromOptions() to determind the matrix type.
52 
53 .keywords: matrix, create
54 
55 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(),
56           MatCreateSeqBDiag(),MatCreateMPIBDiag(),
57           MatCreateSeqDense(), MatCreateMPIDense(),
58           MatCreateMPIRowbs(), MatCreateSeqBAIJ,
59           MatConvert(), MatGetTypeFromOptions()
60  @*/
61 int MatCreate(MPI_Comm comm,int m,int n,Mat *A)
62 {
63   MatType    type;
64   PetscTruth set;
65   int        ierr, bs=1, flg;
66 
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   return 0;
104 }
105 
106 
107 
108 
109 
110