1 /*$Id: gcreate.c,v 1.122 2000/09/01 19:09:14 balay Exp curfman $*/ 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 MatCreateSeqSBAIJ(), MatCreateMPISBAIJ(), 69 MatConvert(), MatGetTypeFromOptions() 70 @*/ 71 int MatCreate(MPI_Comm comm,int m,int n,int M,int N,Mat *A) 72 { 73 MatType type; 74 PetscTruth set; 75 int ierr,bs = 1; 76 77 PetscFunctionBegin; 78 ierr = MatGetTypeFromOptions(comm,0,&type,&set);CHKERRQ(ierr); 79 switch (type) { 80 case MATSEQDENSE: 81 m = PetscMax(m,M); 82 n = PetscMax(n,N); 83 ierr = MatCreateSeqDense(comm,m,n,PETSC_NULL,A);CHKERRQ(ierr); 84 break; 85 case MATMPIBDIAG: 86 ierr = MatCreateMPIBDiag(comm,m,M,N,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr); 87 break; 88 case MATSEQBDIAG: 89 m = PetscMax(m,M); 90 n = PetscMax(n,N); 91 ierr = MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr); 92 break; 93 #if defined(PETSC_HAVE_BLOCKSOLVE) && !defined(PETSC_USE_COMPLEX) 94 case MATMPIROWBS: 95 ierr = MatCreateMPIRowbs(comm,m,M,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 96 break; 97 #endif 98 case MATMPIDENSE: 99 ierr = MatCreateMPIDense(comm,m,n,M,N,PETSC_NULL,A);CHKERRQ(ierr); 100 break; 101 case MATMPIAIJ: 102 ierr = MatCreateMPIAIJ(comm,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 103 break; 104 case MATSEQBAIJ: 105 m = PetscMax(m,M); 106 n = PetscMax(n,N); 107 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 108 ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 109 break; 110 case MATMPIBAIJ: 111 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 112 ierr = MatCreateMPIBAIJ(comm,bs,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 113 break; 114 case MATSEQSBAIJ: 115 m = PetscMax(m,M); 116 n = PetscMax(n,N); 117 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 118 ierr = MatCreateSeqSBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 119 break; 120 case MATMPISBAIJ: 121 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,PETSC_NULL);CHKERRQ(ierr); 122 ierr = MatCreateMPISBAIJ(comm,bs,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 123 break; 124 default: 125 m = PetscMax(m,M); 126 n = PetscMax(n,N); 127 ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 128 break; 129 } 130 PetscFunctionReturn(0); 131 } 132 133 134 135 136 137