1 /*$Id: gcreate.c,v 1.114 1999/07/06 22:00:57 balay Exp bsmith $*/ 2 3 #include "sys.h" 4 #include "mat.h" /*I "mat.h" I*/ 5 6 #undef __FUNC__ 7 #define __FUNC__ "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, flg; 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 case MATMPIROWBS: 93 ierr = MatCreateMPIRowbs(comm,m,M,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,A);CHKERRQ(ierr); 94 break; 95 case MATMPIDENSE: 96 ierr = MatCreateMPIDense(comm,m,n,M,N,PETSC_NULL,A);CHKERRQ(ierr); 97 break; 98 case MATMPIAIJ: 99 ierr = MatCreateMPIAIJ(comm,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 100 break; 101 case MATSEQBAIJ: 102 m = PetscMax(m,M); 103 n = PetscMax(n,N); 104 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg);CHKERRQ(ierr); 105 ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 106 break; 107 case MATMPIBAIJ: 108 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg);CHKERRQ(ierr); 109 ierr = MatCreateMPIBAIJ(comm,bs,m,n,M,N,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 110 break; 111 default: 112 m = PetscMax(m,M); 113 n = PetscMax(n,N); 114 ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A);CHKERRQ(ierr); 115 break; 116 } 117 PetscFunctionReturn(0); 118 } 119 120 121 122 123 124