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