1 #ifdef PETSC_RCS_HEADER 2 static char vcid[] = "$Id: gcreate.c,v 1.107 1998/04/15 19:38:11 curfman Exp curfman $"; 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 Collective on MPI_Comm 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 38 $ MatCreateSeqBDiag() 39 $ -mat_mpibdiag : block diagonal type, uses 40 $ MatCreateMPIBDiag() 41 $ -mat_mpirowbs : rowbs type, uses MatCreateMPIRowbs() 42 $ -mat_seqdense : dense type, uses MatCreateSeqDense() 43 $ -mat_mpidense : dense type, uses MatCreateMPIDense() 44 $ -mat_seqbaij : block AIJ type, uses MatCreateSeqBAIJ() 45 $ -mat_mpibaij : block AIJ type, uses MatCreateMPIBAIJ() 46 47 Even More Options Database Keys: 48 See the manpages for particular formats (e.g., MatCreateSeqAIJ()) 49 for additional format-specific options. 50 51 Notes: 52 This routine calls MatGetTypeFromOptions() to determine the matrix type. 53 54 .keywords: matrix, create 55 56 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(), 57 MatCreateSeqBDiag(),MatCreateMPIBDiag(), 58 MatCreateSeqDense(), MatCreateMPIDense(), 59 MatCreateMPIRowbs(), MatCreateSeqBAIJ, 60 MatConvert(), MatGetTypeFromOptions() 61 @*/ 62 int MatCreate(MPI_Comm comm,int m,int n,Mat *A) 63 { 64 MatType type; 65 PetscTruth set; 66 int ierr, bs=1, flg; 67 68 PetscFunctionBegin; 69 ierr = MatGetTypeFromOptions(comm,0,&type,&set); CHKERRQ(ierr); 70 switch (type) { 71 case MATSEQDENSE: 72 ierr = MatCreateSeqDense(comm,m,n,PETSC_NULL,A); CHKERRQ(ierr); 73 break; 74 case MATMPIBDIAG: 75 ierr = MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_DEFAULT, 76 PETSC_NULL,PETSC_NULL,A); CHKERRQ(ierr); 77 break; 78 case MATSEQBDIAG: 79 ierr = MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL, 80 PETSC_NULL,A); CHKERRQ(ierr); 81 break; 82 case MATMPIROWBS: 83 ierr = MatCreateMPIRowbs(comm,PETSC_DECIDE,m,PETSC_DEFAULT,PETSC_NULL, 84 PETSC_NULL,A); CHKERRQ(ierr); 85 break; 86 case MATMPIDENSE: 87 ierr = MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,A); CHKERRQ(ierr); 88 break; 89 case MATMPIAIJ: 90 ierr = MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT, 91 PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 92 break; 93 case MATSEQBAIJ: 94 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr); 95 ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 96 break; 97 case MATMPIBAIJ: 98 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr); 99 ierr = MatCreateMPIBAIJ(comm,bs,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 100 break; 101 default: 102 ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 103 break; 104 } 105 PetscFunctionReturn(0); 106 } 107 108 109 110 111 112