1 #ifndef lint 2 static char vcid[] = "$Id: gcreate.c,v 1.95 1996/07/12 14:25:23 balay Exp bsmith $"; 3 #endif 4 5 #include "sys.h" 6 #include "mat.h" /*I "mat.h" I*/ 7 8 /*@C 9 MatGetTypeFromOptions - 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 Basic Options Database Keys: 21 These options return MATSEQxxx or MATMPIxxx, 22 depending on the communicator, comm. 23 $ -mat_aij : AIJ type 24 $ -mat_baij : block AIJ type 25 $ -mat_dense : dense type 26 $ -mat_bdiag : block diagonal type 27 28 More Options Database Keys: 29 $ -mat_seqaij : MATSEQAIJ 30 $ -mat_mpiaij : MATMPIAIJ 31 $ -mat_seqbaij : MATSEQBAIJ 32 $ -mat_mpibaij : MATMPIBAIJ 33 $ -mat_seqbdiag : MATSEQBDAIG 34 $ -mat_mpibdiag : MATMPIBDIAG 35 $ -mat_mpirowbs : MATMPIROWBS 36 $ -mat_seqdense : MATSEQDENSE 37 $ -mat_mpidense : MATMPIDENSE 38 39 Note: 40 This routine is automatically called within MatCreate() and MatLoad(). 41 42 .keywords: matrix, get, format, from, options 43 44 .seealso: MatCreate(), MatLoad() 45 @*/ 46 47 int MatGetTypeFromOptions(MPI_Comm comm,char *pre,MatType *type,int *set) 48 { 49 int size,flg1,flg2,flg3,flg4,flg5,flg8,flg9,flg10,flg12,flg13,ierr,flg11,flg14,flg15; 50 char p[64]; 51 52 PetscStrcpy(p,"-"); 53 if (pre) PetscStrcat(p,pre); 54 55 MPI_Comm_size(comm,&size); 56 ierr = OptionsHasName(PETSC_NULL,"-help",&flg1); CHKERRQ(ierr); 57 if (flg1) { 58 PetscPrintf(comm,"Matrix format options:\n"); 59 PetscPrintf(comm," %smat_aij, %smat_seqaij, %smat_mpiaij\n",p,p,p); 60 PetscPrintf(comm," %smat_baij, %smat_seqbaij, %smat_mpibaij\n",p,p,p); 61 PetscPrintf(comm," %smat_dense, %smat_seqdense, %smat_mpidense\n",p,p,p); 62 PetscPrintf(comm," %smat_mpirowbs, %smat_bdiag, %smat_seqbdiag, %smat_mpibdiag\n",p,p,p,p); 63 } 64 ierr = OptionsHasName(pre,"-mat_seqdense",&flg1); CHKERRQ(ierr); 65 ierr = OptionsHasName(pre,"-mat_mpidense",&flg2); CHKERRQ(ierr); 66 ierr = OptionsHasName(pre,"-mat_seqbdiag",&flg3); CHKERRQ(ierr); 67 ierr = OptionsHasName(pre,"-mat_mpibdiag",&flg4); CHKERRQ(ierr); 68 ierr = OptionsHasName(pre,"-mat_mpirowbs",&flg5); CHKERRQ(ierr); 69 ierr = OptionsHasName(pre,"-mat_seqbaij",&flg11); CHKERRQ(ierr); 70 ierr = OptionsHasName(pre,"-mat_mpibaij",&flg14); CHKERRQ(ierr); 71 ierr = OptionsHasName(pre,"-mat_mpiaij",&flg8); CHKERRQ(ierr); 72 ierr = OptionsHasName(pre,"-mat_seqaij",&flg9); CHKERRQ(ierr); 73 ierr = OptionsHasName(pre,"-mat_aij",&flg10); CHKERRQ(ierr); 74 ierr = OptionsHasName(pre,"-mat_bdiag",&flg12); CHKERRQ(ierr); 75 ierr = OptionsHasName(pre,"-mat_dense",&flg13); CHKERRQ(ierr); 76 ierr = OptionsHasName(pre,"-mat_baij",&flg15); CHKERRQ(ierr); 77 if (flg1) { 78 *type = MATSEQDENSE; 79 *set = 1; 80 } 81 else if (flg2) { 82 *type = MATMPIDENSE; 83 *set = 1; 84 } 85 else if (flg3) { 86 *type = MATSEQBDIAG; 87 *set = 1; 88 } 89 else if (flg4) { 90 *type = MATMPIBDIAG; 91 *set = 1; 92 } 93 else if (flg5) { 94 *type = MATMPIROWBS; 95 *set = 1; 96 } 97 else if (flg8) { 98 *type = MATMPIAIJ; 99 *set = 1; 100 } 101 else if (flg9){ 102 *type = MATSEQAIJ; 103 *set = 1; 104 } 105 else if (flg10) { 106 if (size == 1) *type = MATSEQAIJ; 107 else *type = MATMPIAIJ; 108 *set = 1; 109 } 110 else if (flg11) { 111 *type = MATSEQBAIJ; 112 *set = 1; 113 } 114 else if (flg12) { 115 if (size == 1) *type = MATSEQBDIAG; 116 else *type = MATMPIBDIAG; 117 *set = 1; 118 } 119 else if (flg13) { 120 if (size == 1) *type = MATSEQDENSE; 121 else *type = MATMPIDENSE; 122 *set = 1; 123 } 124 else if (flg14) { 125 *type = MATMPIBAIJ; 126 *set = 1; 127 } 128 else if (flg15) { 129 if (size == 1) *type = MATSEQBAIJ; 130 else *type = MATMPIBAIJ; 131 *set = 1; 132 } 133 else { 134 if (size == 1) *type = MATSEQAIJ; 135 else *type = MATMPIAIJ; 136 *set = 0; 137 } 138 return 0; 139 } 140 141 /*@C 142 MatCreate - Creates a matrix, where the type is determined 143 from the options database. Generates a parallel MPI matrix if the 144 communicator has more than one processor. The default matrix type is 145 AIJ, using the routines MatCreateSeqAIJ() and MatCreateMPIAIJ(). 146 147 Input Parameters: 148 . m - number of global rows 149 . n - number of global columns 150 . comm - MPI communicator 151 152 Output Parameter: 153 . A - the matrix 154 155 Basic Options Database Keys: 156 These options use MatCreateSeqXXX or MatCreateMPIXXX, 157 depending on the communicator, comm. 158 $ -mat_aij : AIJ type 159 $ -mat_baij : block AIJ type 160 $ -mat_dense : dense type 161 $ -mat_bdiag : block diagonal type 162 163 More Options Database Keys: 164 $ -mat_seqaij : AIJ type, uses MatCreateSeqAIJ() 165 $ -mat_mpiaij : AIJ type, uses MatCreateMPIAIJ() 166 $ -mat_seqbdiag : block diagonal type, uses 167 $ MatCreateSeqBDiag() 168 $ -mat_mpibdiag : block diagonal type, uses 169 $ MatCreateMPIBDiag() 170 $ -mat_mpirowbs : rowbs type, uses MatCreateMPIRowbs() 171 $ -mat_seqdense : dense type, uses MatCreateSeqDense() 172 $ -mat_mpidense : dense type, uses MatCreateMPIDense() 173 $ -mat_seqbaij : block AIJ type, uses MatCreateSeqBAIJ() 174 $ -mat_mpibaij : block AIJ type, uses MatCreateMPIBAIJ() 175 176 Even More Options Database Keys: 177 See the manpages for particular formats (e.g., MatCreateSeqAIJ()) 178 for additional format-specific options. 179 180 Notes: 181 This routine calls MatGetTypeFromOptions() to determind the matrix type. 182 183 .keywords: matrix, create 184 185 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(), 186 MatCreateSeqBDiag(),MatCreateMPIBDiag(), 187 MatCreateSeqDense(), MatCreateMPIDense(), 188 MatCreateMPIRowbs(), MatCreateSeqBAIJ, 189 MatConvert(), MatGetTypeFromOptions() 190 @*/ 191 int MatCreate(MPI_Comm comm,int m,int n,Mat *A) 192 { 193 MatType type; 194 int set, ierr, bs=1, flg; 195 196 ierr = MatGetTypeFromOptions(comm,0,&type,&set); CHKERRQ(ierr); 197 switch (type) { 198 case MATSEQDENSE: 199 ierr = MatCreateSeqDense(comm,m,n,PETSC_NULL,A); CHKERRQ(ierr); 200 break; 201 case MATMPIBDIAG: 202 ierr = MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_DEFAULT, 203 PETSC_NULL,PETSC_NULL,A); CHKERRQ(ierr); 204 break; 205 case MATSEQBDIAG: 206 ierr = MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL, 207 PETSC_NULL,A); CHKERRQ(ierr); 208 break; 209 case MATMPIROWBS: 210 ierr = MatCreateMPIRowbs(comm,PETSC_DECIDE,m,PETSC_DEFAULT,PETSC_NULL, 211 PETSC_NULL,A); CHKERRQ(ierr); 212 break; 213 case MATMPIDENSE: 214 ierr = MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,A); CHKERRQ(ierr); 215 break; 216 case MATMPIAIJ: 217 ierr = MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT, 218 PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 219 break; 220 case MATSEQBAIJ: 221 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr); 222 ierr = MatCreateSeqBAIJ(comm,bs,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 223 break; 224 case MATMPIBAIJ: 225 ierr = OptionsGetInt(PETSC_NULL,"-mat_block_size",&bs,&flg); CHKERRQ(ierr); 226 ierr = MatCreateMPIBAIJ(comm,bs,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 227 break; 228 default: 229 ierr = MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,A); CHKERRQ(ierr); 230 break; 231 } 232 return 0; 233 } 234 235 #include "src/mat/matimpl.h" 236 /*@C 237 MatGetType - Gets the matrix type and name (as a string) from the matrix. 238 239 Input Parameter: 240 . mat - the matrix 241 242 Output Parameter: 243 . type - the matrix type (or use PETSC_NULL) 244 . name - name of matrix type (or use PETSC_NULL) 245 246 .keywords: matrix, get, type, name 247 @*/ 248 int MatGetType(Mat mat,MatType *type,char **name) 249 { 250 int itype = (int)mat->type; 251 char *matname[10]; 252 253 if (type) *type = (MatType) mat->type; 254 if (name) { 255 /* Note: Be sure that this list corresponds to the enum in mat.h */ 256 matname[0] = "MATSEQDENSE"; 257 matname[1] = "MATSEQAIJ"; 258 matname[2] = "MATMPIAIJ"; 259 matname[3] = "MATSHELL"; 260 matname[4] = "MATMPIROWBS"; 261 matname[5] = "MATSEQBDIAG"; 262 matname[6] = "MATMPIBDIAG"; 263 matname[7] = "MATMPIDENSE"; 264 matname[8] = "MATSEQBAIJ"; 265 matname[9] = "MATMPIBAIJ"; 266 267 if (itype < 0 || itype > 9) *name = "Unknown matrix type"; 268 else *name = matname[itype]; 269 } 270 return 0; 271 } 272 273 274 275