1 /*$Id: gcreate.c,v 1.121 2000/07/10 03:39:59 bsmith Exp balay $*/ 2 3 #include "petscsys.h" 4 #include "petscmat.h" /*I "petscmat.h" I*/ 5 6 #undef __FUNC__ 7 #define __FUNC__ /*<a name=""></a>*/"MatCreate" 8 /*@C 9 MatCreate - Creates a matrix where the type is determined 10 from the options database. Generates a parallel MPI matrix if the 11 communicator has more than one processor. The default matrix type is 12 AIJ, using the routines MatCreateSeqAIJ() and MatCreateMPIAIJ(). 13 14 Collective on MPI_Comm 15 16 Input Parameters: 17 + m - number of local rows (or PETSC_DECIDE) 18 . n - number of local columns (or PETSC_DECIDE) 19 . M - number of global rows (or PETSC_DETERMINE) 20 . N - number of global columns (or PETSC_DETERMINE) 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 If PETSC_DECIDE is not used for the arguments 'm' and 'n', then the 51 user must ensure that they are chosen to be compatible with the 52 vectors. To do this, one first considers the matrix-vector product 53 'y = A x'. The 'm' that is used in the above routine must match the 54 local size used in the vector creation routine VecCreateMPI() for 'y'. 55 Likewise, the 'n' used must match that used as the local size in 56 VecCreateMPI() for 'x'. 57 58 This routine calls MatGetTypeFromOptions() to determine the matrix type. 59 60 Level: beginner 61 62 .keywords: matrix, create 63 64 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(), 65 MatCreateSeqBDiag(),MatCreateMPIBDiag(), 66 MatCreateSeqDense(), MatCreateMPIDense(), 67 MatCreateMPIRowbs(), MatCreateSeqBAIJ(), MatCreateMPIBAIJ() 68 MatConvert(), MatGetTypeFromOptions() 69 @*/ 70 int MatCreate(MPI_Comm comm,int m,int n,int M,int N,Mat *A) 71 { 72 MatType type; 73 PetscTruth set; 74 int ierr,bs = 1; 75 76 PetscFunctionBegin; 77 ierr = MatGetTypeFromOptions(comm,0,&type,&set);CHKERRQ(ierr); 78 switch (type) { 79 case MATSEQDENSE: 80 m = PetscMax(m,M); 81 n = PetscMax(n,N); 82 ierr = MatCreateSeqDense(comm,m,n,PETSC_NULL,A);CHKERRQ(ierr); 83 break; 84 case MATMPIBDIAG: 85 ierr = MatCreateMPIBDiag(comm,m,M,N,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr); 86 break; 87 case MATSEQBDIAG: 88 m = PetscMax(m,M); 89 n = PetscMax(n,N); 90 ierr = MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr); 91 break; 92 #if defined(PETSC_HAVE_BLOCKSOLVE) && !defined(PETSC_USE_COMPLEX) 93 case MATMPIROWBS: 94 ierr = MatCreateMPIRowbs(comm,m,M,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 95 break; 96 #endif 97 case MATMPIDENSE: 98 ierr = MatCreateMPIDense(comm,m,n,M,N,PETSC_NULL,A);CHKERRQ(ierr); 99 break; 100 case MATMPIAIJ: 101 ierr = MatCreateMPIAIJ(comm,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 102 break; 103 case MATSEQBAIJ: 104 m = PetscMax(m,M); 105 n = PetscMax(n,N); 106 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 107 ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 108 break; 109 case MATMPIBAIJ: 110 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 111 ierr = MatCreateMPIBAIJ(comm,bs,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 112 break; 113 case MATSEQSBAIJ: 114 m = PetscMax(m,M); 115 n = PetscMax(n,N); 116 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 117 ierr = MatCreateSeqSBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 118 break; 119 case MATMPISBAIJ: 120 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 121 ierr = MatCreateMPISBAIJ(comm,bs,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 122 break; 123 default: 124 m = PetscMax(m,M); 125 n = PetscMax(n,N); 126 ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 127 break; 128 } 129 PetscFunctionReturn(0); 130 } 131 132 133 134 135 136