1 #ifndef lint 2 static char vcid[] = "$Id: gcreate.c,v 1.68 1996/01/24 05:46:49 bsmith Exp curfman $"; 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,flg1,flg2,flg3,flg4,flg5,flg8,flg9,flg10,flg12,flg13,ierr; 31 char p[64]; 32 33 PetscStrcpy(p,"-"); 34 if (pre) PetscStrcat(p,pre); 35 36 MPI_Comm_size(comm,&size); 37 ierr = OptionsHasName(PETSC_NULL,"-help",&flg1); CHKERRQ(ierr); 38 if (flg1) { 39 MPIU_printf(comm,"Matrix format options:\n"); 40 MPIU_printf(comm," %smat_aij, %smat_seqaij, %smat_mpiaij\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 ierr = OptionsHasName(pre,"-mat_seqdense",&flg1); CHKERRQ(ierr); 45 ierr = OptionsHasName(pre,"-mat_mpidense",&flg2); CHKERRQ(ierr); 46 ierr = OptionsHasName(pre,"-mat_seqbdiag",&flg3); CHKERRQ(ierr); 47 ierr = OptionsHasName(pre,"-mat_mpibdiag",&flg4); CHKERRQ(ierr); 48 ierr = OptionsHasName(pre,"-mat_mpirowbs",&flg5); CHKERRQ(ierr); 49 ierr = OptionsHasName(pre,"-mat_mpiaij",&flg8); CHKERRQ(ierr); 50 ierr = OptionsHasName(pre,"-mat_seqaij",&flg9); CHKERRQ(ierr); 51 ierr = OptionsHasName(pre,"-mat_aij",&flg10); CHKERRQ(ierr); 52 ierr = OptionsHasName(pre,"-mat_bdiag",&flg12); CHKERRQ(ierr); 53 ierr = OptionsHasName(pre,"-mat_dense",&flg13); CHKERRQ(ierr); 54 if (flg1) { 55 *type = MATSEQDENSE; 56 *set = 1; 57 } 58 else if (flg2) { 59 *type = MATMPIDENSE; 60 *set = 1; 61 } 62 else if (flg3) { 63 *type = MATSEQBDIAG; 64 *set = 1; 65 } 66 else if (flg4) { 67 *type = MATMPIBDIAG; 68 *set = 1; 69 } 70 else if (flg5) { 71 *type = MATMPIROWBS; 72 *set = 1; 73 } 74 else if (flg8) { 75 *type = MATMPIAIJ; 76 *set = 1; 77 } 78 else if (flg9){ 79 *type = MATSEQAIJ; 80 *set = 1; 81 } 82 else if (flg10){ 83 if (size == 1) *type = MATSEQAIJ; 84 else *type = MATMPIAIJ; 85 *set = 1; 86 } 87 else if (flg12){ 88 if (size == 1) *type = MATSEQBDIAG; 89 else *type = MATMPIBDIAG; 90 *set = 1; 91 } 92 else if (flg13){ 93 if (size == 1) *type = MATSEQDENSE; 94 else *type = MATMPIDENSE; 95 *set = 1; 96 } 97 else { 98 if (size == 1) *type = MATSEQAIJ; 99 else *type = MATMPIAIJ; 100 *set = 0; 101 } 102 return 0; 103 } 104 105 /*@C 106 MatCreate - Creates a matrix, where the type is determined 107 from the options database. Generates a parallel MPI matrix if the 108 communicator has more than one processor. 109 110 Input Parameters: 111 . m - number of global rows 112 . n - number of global columns 113 . comm - MPI communicator 114 115 Output Parameter: 116 . V - location to stash resulting matrix 117 118 Options Database Keywords: 119 $ -mat_seqaij : AIJ type, uses MatCreateSeqAIJ 120 $ -mat_mpiaij : AIJ type, uses MatCreateMPIAIJ 121 $ -mat_aij : AIJ type, (Seq or MPI depending on comm) 122 $ -mat_seqbdiag : block diagonal type, uses 123 $ MatCreateSeqBDiag() 124 $ -mat_mpibdiag : block diagonal type, uses 125 $ MatCreateMPIBDiag() 126 $ -mat_bdiag : block diagonal type, 127 $ (Seq or MPI depending on comm) 128 $ -mat_mpirowbs : rowbs type, uses MatCreateMPIRowbs() 129 $ -mat_dense : dense type, (Seq or MPI depending on comm) 130 $ -mat_mpidense : dense type, uses MatCreateSeqDense() 131 $ -mat_mpidense : dense type, uses MatCreateMPIDense() 132 133 Notes: 134 The default matrix type is AIJ, using MatCreateSeqAIJ() and 135 MatCreateMPIAIJ(). 136 137 .keywords: matrix, create, initial 138 139 .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(), 140 MatCreateSeqBDiag(),MatCreateMPIBDiag(), 141 MatCreateSeqDense(), MatCreateMPIDense(), 142 MatCreateMPIRowbs(), MatConvert() 143 MatGetFormatFromOptions() 144 @*/ 145 int MatCreate(MPI_Comm comm,int m,int n,Mat *V) 146 { 147 MatType type; 148 int set,ierr; 149 150 ierr = MatGetFormatFromOptions(comm,0,&type,&set); CHKERRQ(ierr); 151 if (type == MATSEQDENSE) 152 return MatCreateSeqDense(comm,m,n,PETSC_NULL,V); 153 if (type == MATMPIBDIAG) 154 return MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_DEFAULT, 155 PETSC_NULL,PETSC_NULL,V); 156 if (type == MATSEQBDIAG) 157 return MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL, 158 PETSC_NULL,V); 159 if (type == MATMPIROWBS) 160 return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,V); 161 if (type == MATMPIDENSE) 162 return MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,V); 163 if (type == MATMPIAIJ) 164 return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT, 165 PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,V); 166 return MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,V); 167 } 168 169 #include "matimpl.h" 170 /*@C 171 MatGetType - Gets the matrix type and name (as a string) from the matrix. 172 173 Input Parameter: 174 . mat - the matrix 175 176 Output Parameter: 177 . type - the matrix type (or use PETSC_NULL) 178 . name - name of matrix type (or use PETSC_NULL) 179 180 .keywords: matrix, get, type, name 181 @*/ 182 int MatGetType(Mat mat,MatType *type,char **name) 183 { 184 int itype = (int)mat->type; 185 char *matname[10]; 186 187 if (type) *type = (MatType) mat->type; 188 if (name) { 189 /* Note: Be sure that this list corresponds to the enum in mat.h */ 190 matname[0] = "MATSEQDENSE"; 191 matname[1] = "MATSEQAIJ"; 192 matname[2] = "MATMPIAIJ"; 193 matname[3] = "MATSHELL"; 194 matname[4] = "MATMPIROWBS"; 195 matname[5] = "MATSEQBDIAG"; 196 matname[6] = "MATMPIBDIAG"; 197 matname[7] = "MATMPIDENSE"; 198 if (itype < 0 || itype > 7) *name = "Unknown matrix type"; 199 else *name = matname[itype]; 200 } 201 return 0; 202 } 203 204 205 206