1 #ifndef lint 2 static char vcid[] = "$Id: gcreate.c,v 1.55 1995/10/26 21:39:52 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 = "-"; 32 if (pre) p = pre; 33 MPI_Comm_size(comm,&size); 34 if (OptionsHasName(0,"-help")) { 35 MPIU_printf(comm,"Matrix format options:\n"); 36 MPIU_printf(comm," %smat_aij, %smat_seqaij, %smat_mpiaij\n",p,p,p); 37 MPIU_printf(comm," %smat_row, %smat_seqrow, %smat_mpirow\n",p,p,p); 38 MPIU_printf(comm," %smat_dense, %smat_seqdense, %smat_mpidense\n",p,p,p); 39 MPIU_printf(comm," %smat_mpirowbs, %smat_bdiag, %smat_seqbdiag, %smat_mpibdiag\n",p,p,p,p); 40 /* We need to move the following to MatPrintHelp or some analogous routine */ 41 MPIU_printf(comm,"More matrix options:\n"); 42 MPIU_printf(comm," %smat_view_info : view basic matrix info during MatAssemblyEnd()\n",p); 43 MPIU_printf(comm," %smat_view_info_detailed : view detailed matrix info during MatAssemblyEnd()\n",p); 44 MPIU_printf(comm," %smat_view_draw : draw nonzero matrix structure during MatAssemblyEnd()\n",p); 45 MPIU_printf(comm," -pause <sec> : set seconds of display pause\n"); 46 MPIU_printf(comm," -display <name> : set alternate display\n"); 47 } 48 if (OptionsHasName(pre,"-mat_seqdense")) { 49 *type = MATSEQDENSE; 50 *set = 1; 51 } 52 else if (OptionsHasName(pre,"-mat_mpidense")) { 53 *type = MATMPIDENSE; 54 *set = 1; 55 } 56 else if (OptionsHasName(pre,"-mat_seqbdiag")) { 57 *type = MATSEQBDIAG; 58 *set = 1; 59 } 60 else if (OptionsHasName(pre,"-mat_mpibdiag")) { 61 *type = MATMPIBDIAG; 62 *set = 1; 63 } 64 else if (OptionsHasName(pre,"-mat_mpirowbs")) { 65 *type = MATMPIROWBS; 66 *set = 1; 67 } 68 else if (OptionsHasName(pre,"-mat_mpirow")) { 69 *type = MATMPIROW; 70 *set = 1; 71 } 72 else if (OptionsHasName(pre,"-mat_seqrow")){ 73 *type = MATSEQROW; 74 *set = 1; 75 } 76 else if (OptionsHasName(pre,"-mat_mpiaij")) { 77 *type = MATMPIAIJ; 78 *set = 1; 79 } 80 else if (OptionsHasName(pre,"-mat_seqaij")){ 81 *type = MATSEQAIJ; 82 *set = 1; 83 } 84 else if (OptionsHasName(pre,"-mat_aij")){ 85 if (size == 1) *type = MATSEQAIJ; 86 else *type = MATMPIAIJ; 87 *set = 1; 88 } 89 else if (OptionsHasName(pre,"-mat_row")){ 90 if (size == 1) *type = MATSEQROW; 91 else *type = MATMPIROW; 92 *set = 1; 93 } 94 else if (OptionsHasName(pre,"-mat_bdiag")){ 95 if (size == 1) *type = MATSEQBDIAG; 96 else *type = MATMPIBDIAG; 97 *set = 1; 98 } 99 else if (OptionsHasName(pre,"-mat_dense")){ 100 if (size == 1) *type = MATSEQDENSE; 101 else *type = MATMPIDENSE; 102 *set = 1; 103 } 104 else { 105 if (size == 1) *type = MATSEQAIJ; 106 else *type = MATMPIAIJ; 107 *set = 0; 108 } 109 return 0; 110 } 111 112 /*@C 113 MatCreate - Creates a matrix, where the type is determined 114 from the options database. Generates a parallel MPI matrix if the 115 communicator has more than one processor. 116 117 Input Parameters: 118 . m - number of global rows 119 . n - number of global columns 120 . comm - MPI communicator 121 122 Output Parameter: 123 . V - location to stash resulting matrix 124 125 Options Database Keywords: 126 $ -mat_seqaij : AIJ type, uses MatCreateSeqAIJ 127 $ -mat_mpiaij : AIJ type, uses MatCreateMPIAIJ 128 $ -mat_aij : AIJ type, (Seq or MPI depending on comm) 129 $ -mat_seqrow : row type, uses MatCreateSeqRow() 130 $ -mat_mpirow : MatCreateMPIRow() 131 $ -mat_row : row type, (Seq or MPI depending on comm) 132 $ -mat_seqbdiag : block diagonal type, uses 133 $ MatCreateSeqBDiag() 134 $ -mat_mpibdiag : block diagonal type, uses 135 $ MatCreateMPIBDiag() 136 $ -mat_bdiag : block diagonal type, 137 $ (Seq or MPI depending on comm) 138 $ -mat_mpirowbs : rowbs type, uses MatCreateMPIRowbs() 139 $ -mat_dense : dense type, (Seq or MPI depending on comm) 140 $ -mat_mpidense : dense type, uses MatCreateSeqDense() 141 $ -mat_mpidense : dense type, uses MatCreateMPIDense() 142 143 Notes: 144 The default matrix type is AIJ, using MatCreateSeqAIJ() and 145 MatCreateMPIAIJ(). 146 147 .keywords: matrix, create, initial 148 149 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(), 150 MatCreateSeqRow(), MatCreateMPIRow(), 151 MatCreateSeqBDiag(),MatCreateMPIBDiag(), 152 MatCreateSeqDense(), MatCreateMPIDense(), 153 MatCreateMPIRowbs(), MatConvert() 154 MatGetFormatFromOptions() 155 @*/ 156 int MatCreate(MPI_Comm comm,int m,int n,Mat *V) 157 { 158 MatType type; 159 int set,ierr; 160 161 ierr = MatGetFormatFromOptions(comm,0,&type,&set); CHKERRQ(ierr); 162 if (type == MATSEQDENSE) { 163 return MatCreateSeqDense(comm,m,n,V); 164 } 165 if (type == MATSEQBDIAG || type == MATMPIBDIAG) { 166 int nb = 1, ndiag = 0, ndiag2 = 0, *d = 0; 167 if (OptionsHasName(0,"-help")) { 168 MPIU_printf(comm,"Options with -mat_bdiag: -mat_bdiag_bsize <block_size>\n"); 169 MPIU_printf(comm," -mat_bdiag_ndiag <number_diags> \n"); 170 MPIU_printf(comm," -mat_bdiag_dvals <d1,d2,d3,...> (diagonal numbers)\n"); 171 MPIU_printf(comm," (for example) -mat_bdiag_dvals -5,-1,0,1,5\n"); 172 } 173 OptionsGetInt(0,"-mat_bdiag_bsize",&nb); 174 OptionsGetInt(0,"-mat_bdiag_ndiag",&ndiag); 175 if (ndiag) { 176 d = (int *)PetscMalloc( ndiag * sizeof(int) ); CHKPTRQ(d); 177 ndiag2 = ndiag; 178 OptionsGetIntArray(0,"-mat_bdiag_dvals",d,&ndiag2); 179 if (ndiag2 != ndiag) 180 SETERRQ(1,"MatCreate: Incompatible number of diags and diagonal vals"); 181 } else if (OptionsHasName(0,"-mat_bdiag_dvals")) { 182 SETERRQ(1,"MatCreate: Must specify number of diagonals with -mat_bdiag_ndiag"); 183 } 184 if (type == MATMPIBDIAG) { 185 ierr = MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,ndiag,nb,d,0,V); CHKERRQ(ierr); 186 } else { 187 ierr = MatCreateSeqBDiag(comm,m,n,ndiag,nb,d,0,V); CHKERRQ(ierr); 188 } 189 if (d) PetscFree(d); 190 return 0; 191 } 192 if (type == MATMPIROWBS) { 193 return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,5,0,0,V); 194 } 195 if (type == MATMPIROW) { 196 return MatCreateMPIRow(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 197 } 198 if (type == MATSEQROW) { 199 return MatCreateSeqRow(comm,m,n,10,0,V); 200 } 201 if (type == MATMPIDENSE) { 202 return MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,V); 203 } 204 if (type == MATMPIAIJ) { 205 return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 206 } 207 return MatCreateSeqAIJ(comm,m,n,10,0,V); 208 } 209 210 #include "matimpl.h" 211 /*@C 212 MatGetName - Gets the matrix type name (as a string) from the matrix. 213 214 Input Parameter: 215 . mat - the matrix 216 217 Output Parameter: 218 . name - name of matrix type 219 220 .keywords: matrix, get, name 221 222 .seealso: MatGetType() 223 @*/ 224 int MatGetName(Mat mat,char **name) 225 { 226 int itype = (int)mat->type; 227 char *matname[10]; 228 /* Note: Be sure that this list corresponds to the enum in mat.h */ 229 matname[0] = "MATSEQDENSE"; 230 matname[1] = "MATSEQAIJ"; 231 matname[2] = "MATMPIAIJ"; 232 matname[3] = "MATSHELL"; 233 matname[4] = "MATSEQROW"; 234 matname[5] = "MATMPIROW"; 235 matname[6] = "MATMPIROWBS"; 236 matname[7] = "MATSEQBDIAG"; 237 matname[8] = "MATMPIBDIAG"; 238 matname[9] = "MATMPIDENSE"; 239 if (itype < 0 || itype > 9) *name = "Unknown matrix type"; 240 else *name = matname[itype]; 241 return 0; 242 } 243 244