1 #ifndef lint 2 static char vcid[] = "$Id: gcreate.c,v 1.65 1996/01/03 16:11:06 curfman Exp bsmith $"; 3 #endif 4 5 #include "sys.h" 6 #include "mat.h" /*I "mat.h" I*/ 7 8 /*@C 9 MatGetFormatFromOptions - Determines from the options database what matrix 10 format the user has specified. 11 12 Input Parameter: 13 . comm - the MPI communicator 14 . type - the type of matrix desired, for example MATSEQAIJ, MATMPIAIJ 15 . pre - optional string to prepend to the name 16 17 Output Parameters: 18 . set - flag indicating whether user set matrix type option. 19 20 Note: 21 This routine is automatically called within MatCreate(). 22 23 .keywords: matrix, get, format, from, options 24 25 .seealso: MatCreate() 26 @*/ 27 28 int MatGetFormatFromOptions(MPI_Comm comm,char *pre,MatType *type,int *set) 29 { 30 int size; 31 char p[64]; 32 33 PetscStrcpy(p,"-"); 34 if (pre) PetscStrcat(p,pre); 35 36 MPI_Comm_size(comm,&size); 37 if (OptionsHasName(PETSC_NULL,"-help")) { 38 MPIU_printf(comm,"Matrix format options:\n"); 39 MPIU_printf(comm," %smat_aij, %smat_seqaij, %smat_mpiaij\n",p,p,p); 40 MPIU_printf(comm," %smat_row, %smat_seqrow, %smat_mpirow\n",p,p,p); 41 MPIU_printf(comm," %smat_dense, %smat_seqdense, %smat_mpidense\n",p,p,p); 42 MPIU_printf(comm," %smat_mpirowbs, %smat_bdiag, %smat_seqbdiag, %smat_mpibdiag\n",p,p,p,p); 43 } 44 if (OptionsHasName(pre,"-mat_seqdense")) { 45 *type = MATSEQDENSE; 46 *set = 1; 47 } 48 else if (OptionsHasName(pre,"-mat_mpidense")) { 49 *type = MATMPIDENSE; 50 *set = 1; 51 } 52 else if (OptionsHasName(pre,"-mat_seqbdiag")) { 53 *type = MATSEQBDIAG; 54 *set = 1; 55 } 56 else if (OptionsHasName(pre,"-mat_mpibdiag")) { 57 *type = MATMPIBDIAG; 58 *set = 1; 59 } 60 else if (OptionsHasName(pre,"-mat_mpirowbs")) { 61 *type = MATMPIROWBS; 62 *set = 1; 63 } 64 else if (OptionsHasName(pre,"-mat_mpirow")) { 65 *type = MATMPIROW; 66 *set = 1; 67 } 68 else if (OptionsHasName(pre,"-mat_seqrow")){ 69 *type = MATSEQROW; 70 *set = 1; 71 } 72 else if (OptionsHasName(pre,"-mat_mpiaij")) { 73 *type = MATMPIAIJ; 74 *set = 1; 75 } 76 else if (OptionsHasName(pre,"-mat_seqaij")){ 77 *type = MATSEQAIJ; 78 *set = 1; 79 } 80 else if (OptionsHasName(pre,"-mat_aij")){ 81 if (size == 1) *type = MATSEQAIJ; 82 else *type = MATMPIAIJ; 83 *set = 1; 84 } 85 else if (OptionsHasName(pre,"-mat_row")){ 86 if (size == 1) *type = MATSEQROW; 87 else *type = MATMPIROW; 88 *set = 1; 89 } 90 else if (OptionsHasName(pre,"-mat_bdiag")){ 91 if (size == 1) *type = MATSEQBDIAG; 92 else *type = MATMPIBDIAG; 93 *set = 1; 94 } 95 else if (OptionsHasName(pre,"-mat_dense")){ 96 if (size == 1) *type = MATSEQDENSE; 97 else *type = MATMPIDENSE; 98 *set = 1; 99 } 100 else { 101 if (size == 1) *type = MATSEQAIJ; 102 else *type = MATMPIAIJ; 103 *set = 0; 104 } 105 return 0; 106 } 107 108 /*@C 109 MatCreate - Creates a matrix, where the type is determined 110 from the options database. Generates a parallel MPI matrix if the 111 communicator has more than one processor. 112 113 Input Parameters: 114 . m - number of global rows 115 . n - number of global columns 116 . comm - MPI communicator 117 118 Output Parameter: 119 . V - location to stash resulting matrix 120 121 Options Database Keywords: 122 $ -mat_seqaij : AIJ type, uses MatCreateSeqAIJ 123 $ -mat_mpiaij : AIJ type, uses MatCreateMPIAIJ 124 $ -mat_aij : AIJ type, (Seq or MPI depending on comm) 125 $ -mat_seqrow : row type, uses MatCreateSeqRow() 126 $ -mat_mpirow : MatCreateMPIRow() 127 $ -mat_row : row type, (Seq or MPI depending on comm) 128 $ -mat_seqbdiag : block diagonal type, uses 129 $ MatCreateSeqBDiag() 130 $ -mat_mpibdiag : block diagonal type, uses 131 $ MatCreateMPIBDiag() 132 $ -mat_bdiag : block diagonal type, 133 $ (Seq or MPI depending on comm) 134 $ -mat_mpirowbs : rowbs type, uses MatCreateMPIRowbs() 135 $ -mat_dense : dense type, (Seq or MPI depending on comm) 136 $ -mat_mpidense : dense type, uses MatCreateSeqDense() 137 $ -mat_mpidense : dense type, uses MatCreateMPIDense() 138 139 Notes: 140 The default matrix type is AIJ, using MatCreateSeqAIJ() and 141 MatCreateMPIAIJ(). 142 143 .keywords: matrix, create, initial 144 145 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(), 146 MatCreateSeqRow(), MatCreateMPIRow(), 147 MatCreateSeqBDiag(),MatCreateMPIBDiag(), 148 MatCreateSeqDense(), MatCreateMPIDense(), 149 MatCreateMPIRowbs(), MatConvert() 150 MatGetFormatFromOptions() 151 @*/ 152 int MatCreate(MPI_Comm comm,int m,int n,Mat *V) 153 { 154 MatType type; 155 int set,ierr; 156 157 ierr = MatGetFormatFromOptions(comm,0,&type,&set); CHKERRQ(ierr); 158 if (type == MATSEQDENSE) 159 return MatCreateSeqDense(comm,m,n,PETSC_NULL,V); 160 if (type == MATMPIBDIAG) 161 return MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_DEFAULT, 162 PETSC_NULL,PETSC_NULL,V); 163 if (type == MATSEQBDIAG) 164 return MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL, 165 PETSC_NULL,V); 166 if (type == MATMPIROWBS) 167 return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,V); 168 if (type == MATMPIROW) 169 return MatCreateMPIRow(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT, 170 PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,V); 171 if (type == MATSEQROW) 172 return MatCreateSeqRow(comm,m,n,PETSC_DEFAULT,PETSC_NULL,V); 173 if (type == MATMPIDENSE) 174 return MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,V); 175 if (type == MATMPIAIJ) 176 return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT, 177 PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,V); 178 return MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,V); 179 } 180 181 #include "matimpl.h" 182 /*@C 183 MatGetType - Gets the matrix type and name (as a string) from the matrix. 184 185 Input Parameter: 186 . mat - the matrix 187 188 Output Parameter: 189 . type - the matrix type (or use PETSC_NULL) 190 . name - name of matrix type (or use PETSC_NULL) 191 192 .keywords: matrix, get, name 193 @*/ 194 int MatGetType(Mat mat,MatType *type,char **name) 195 { 196 int itype = (int)mat->type; 197 char *matname[10]; 198 199 if (type) *type = (MatType) mat->type; 200 if (name) { 201 /* Note: Be sure that this list corresponds to the enum in mat.h */ 202 matname[0] = "MATSEQDENSE"; 203 matname[1] = "MATSEQAIJ"; 204 matname[2] = "MATMPIAIJ"; 205 matname[3] = "MATSHELL"; 206 matname[4] = "MATSEQROW"; 207 matname[5] = "MATMPIROW"; 208 matname[6] = "MATMPIROWBS"; 209 matname[7] = "MATSEQBDIAG"; 210 matname[8] = "MATMPIBDIAG"; 211 matname[9] = "MATMPIDENSE"; 212 if (itype < 0 || itype > 9) *name = "Unknown matrix type"; 213 else *name = matname[itype]; 214 } 215 return 0; 216 } 217 218 219 220