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