1cb512458SBarry Smith #ifndef lint 2*6daaf66cSBarry Smith static char vcid[] = "$Id: gcreate.c,v 1.65 1996/01/03 16:11:06 curfman Exp bsmith $"; 3cb512458SBarry Smith #endif 47807a1faSBarry Smith 57807a1faSBarry Smith #include "sys.h" 648b35521SBarry Smith #include "mat.h" /*I "mat.h" I*/ 77807a1faSBarry Smith 8e3726954SLois Curfman McInnes /*@C 98c645567SLois Curfman McInnes MatGetFormatFromOptions - Determines from the options database what matrix 108c645567SLois Curfman McInnes format the user has specified. 11416022c9SBarry Smith 12932b0c3eSLois Curfman McInnes Input Parameter: 13932b0c3eSLois Curfman McInnes . comm - the MPI communicator 1439ddd567SLois Curfman McInnes . type - the type of matrix desired, for example MATSEQAIJ, MATMPIAIJ 15e3726954SLois Curfman McInnes . pre - optional string to prepend to the name 16416022c9SBarry Smith 17416022c9SBarry Smith Output Parameters: 18932b0c3eSLois Curfman McInnes . set - flag indicating whether user set matrix type option. 19416022c9SBarry Smith 208c645567SLois Curfman McInnes Note: 218c645567SLois Curfman McInnes This routine is automatically called within MatCreate(). 228c645567SLois Curfman McInnes 2339ddd567SLois Curfman McInnes .keywords: matrix, get, format, from, options 2439ddd567SLois Curfman McInnes 25416022c9SBarry Smith .seealso: MatCreate() 26416022c9SBarry Smith @*/ 27e3726954SLois Curfman McInnes 28e3726954SLois Curfman McInnes int MatGetFormatFromOptions(MPI_Comm comm,char *pre,MatType *type,int *set) 29dbb450caSBarry Smith { 3017699dbbSLois Curfman McInnes int size; 31*6daaf66cSBarry Smith char p[64]; 32d5d45c9bSBarry Smith 33*6daaf66cSBarry Smith PetscStrcpy(p,"-"); 34*6daaf66cSBarry Smith if (pre) PetscStrcat(p,pre); 35*6daaf66cSBarry Smith 3617699dbbSLois Curfman McInnes MPI_Comm_size(comm,&size); 37b4fd4287SBarry Smith if (OptionsHasName(PETSC_NULL,"-help")) { 38e3726954SLois Curfman McInnes MPIU_printf(comm,"Matrix format options:\n"); 39e3726954SLois Curfman McInnes MPIU_printf(comm," %smat_aij, %smat_seqaij, %smat_mpiaij\n",p,p,p); 40e3726954SLois Curfman McInnes MPIU_printf(comm," %smat_row, %smat_seqrow, %smat_mpirow\n",p,p,p); 41e3726954SLois Curfman McInnes MPIU_printf(comm," %smat_dense, %smat_seqdense, %smat_mpidense\n",p,p,p); 42e3726954SLois Curfman McInnes MPIU_printf(comm," %smat_mpirowbs, %smat_bdiag, %smat_seqbdiag, %smat_mpibdiag\n",p,p,p,p); 43dbb450caSBarry Smith } 44e3726954SLois Curfman McInnes if (OptionsHasName(pre,"-mat_seqdense")) { 45dbb450caSBarry Smith *type = MATSEQDENSE; 46dbb450caSBarry Smith *set = 1; 47dbb450caSBarry Smith } 48e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_mpidense")) { 4939ddd567SLois Curfman McInnes *type = MATMPIDENSE; 5039ddd567SLois Curfman McInnes *set = 1; 5139ddd567SLois Curfman McInnes } 52e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_seqbdiag")) { 53dbb450caSBarry Smith *type = MATSEQBDIAG; 54dbb450caSBarry Smith *set = 1; 55dbb450caSBarry Smith } 56e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_mpibdiag")) { 57dbb450caSBarry Smith *type = MATMPIBDIAG; 58dbb450caSBarry Smith *set = 1; 59dbb450caSBarry Smith } 60e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_mpirowbs")) { 61dbb450caSBarry Smith *type = MATMPIROWBS; 62dbb450caSBarry Smith *set = 1; 63dbb450caSBarry Smith } 64e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_mpirow")) { 65dbb450caSBarry Smith *type = MATMPIROW; 66dbb450caSBarry Smith *set = 1; 67dbb450caSBarry Smith } 68e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_seqrow")){ 69dbb450caSBarry Smith *type = MATSEQROW; 70dbb450caSBarry Smith *set = 1; 71dbb450caSBarry Smith } 72e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_mpiaij")) { 73dbb450caSBarry Smith *type = MATMPIAIJ; 74dbb450caSBarry Smith *set = 1; 75dbb450caSBarry Smith } 76e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_seqaij")){ 77dbb450caSBarry Smith *type = MATSEQAIJ; 78dbb450caSBarry Smith *set = 1; 79dbb450caSBarry Smith } 80e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_aij")){ 8117699dbbSLois Curfman McInnes if (size == 1) *type = MATSEQAIJ; 82dbb450caSBarry Smith else *type = MATMPIAIJ; 83dbb450caSBarry Smith *set = 1; 84dbb450caSBarry Smith } 85e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_row")){ 8617699dbbSLois Curfman McInnes if (size == 1) *type = MATSEQROW; 87dbb450caSBarry Smith else *type = MATMPIROW; 88dbb450caSBarry Smith *set = 1; 89dbb450caSBarry Smith } 90e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_bdiag")){ 9117699dbbSLois Curfman McInnes if (size == 1) *type = MATSEQBDIAG; 92dbb450caSBarry Smith else *type = MATMPIBDIAG; 93dbb450caSBarry Smith *set = 1; 94dbb450caSBarry Smith } 95e3726954SLois Curfman McInnes else if (OptionsHasName(pre,"-mat_dense")){ 9639ddd567SLois Curfman McInnes if (size == 1) *type = MATSEQDENSE; 9739ddd567SLois Curfman McInnes else *type = MATMPIDENSE; 9839ddd567SLois Curfman McInnes *set = 1; 9939ddd567SLois Curfman McInnes } 100dbb450caSBarry Smith else { 10117699dbbSLois Curfman McInnes if (size == 1) *type = MATSEQAIJ; 102dbb450caSBarry Smith else *type = MATMPIAIJ; 103dbb450caSBarry Smith *set = 0; 104dbb450caSBarry Smith } 105dbb450caSBarry Smith return 0; 106dbb450caSBarry Smith } 107dbb450caSBarry Smith 108325ab940SBarry Smith /*@C 1096469c4f9SBarry Smith MatCreate - Creates a matrix, where the type is determined 11002a82ca1SLois Curfman McInnes from the options database. Generates a parallel MPI matrix if the 11102a82ca1SLois Curfman McInnes communicator has more than one processor. 1127807a1faSBarry Smith 1137807a1faSBarry Smith Input Parameters: 114e0b365e2SLois Curfman McInnes . m - number of global rows 115e0b365e2SLois Curfman McInnes . n - number of global columns 1166b5873e3SBarry Smith . comm - MPI communicator 1177807a1faSBarry Smith 1187807a1faSBarry Smith Output Parameter: 119df998da4SLois Curfman McInnes . V - location to stash resulting matrix 120e0b365e2SLois Curfman McInnes 121e0b365e2SLois Curfman McInnes Options Database Keywords: 1222a9f886eSLois Curfman McInnes $ -mat_seqaij : AIJ type, uses MatCreateSeqAIJ 1232a9f886eSLois Curfman McInnes $ -mat_mpiaij : AIJ type, uses MatCreateMPIAIJ 1242a9f886eSLois Curfman McInnes $ -mat_aij : AIJ type, (Seq or MPI depending on comm) 125dbb450caSBarry Smith $ -mat_seqrow : row type, uses MatCreateSeqRow() 1265f52d6abSBarry Smith $ -mat_mpirow : MatCreateMPIRow() 127dbb450caSBarry Smith $ -mat_row : row type, (Seq or MPI depending on comm) 128dbb450caSBarry Smith $ -mat_seqbdiag : block diagonal type, uses 129fafbff53SBarry Smith $ MatCreateSeqBDiag() 1307641ccfcSLois Curfman McInnes $ -mat_mpibdiag : block diagonal type, uses 1317641ccfcSLois Curfman McInnes $ MatCreateMPIBDiag() 1327641ccfcSLois Curfman McInnes $ -mat_bdiag : block diagonal type, 1337641ccfcSLois Curfman McInnes $ (Seq or MPI depending on comm) 1347641ccfcSLois Curfman McInnes $ -mat_mpirowbs : rowbs type, uses MatCreateMPIRowbs() 13539ddd567SLois Curfman McInnes $ -mat_dense : dense type, (Seq or MPI depending on comm) 13639ddd567SLois Curfman McInnes $ -mat_mpidense : dense type, uses MatCreateSeqDense() 13739ddd567SLois Curfman McInnes $ -mat_mpidense : dense type, uses MatCreateMPIDense() 138e0b365e2SLois Curfman McInnes 139e0b365e2SLois Curfman McInnes Notes: 140fafbff53SBarry Smith The default matrix type is AIJ, using MatCreateSeqAIJ() and 141e0b365e2SLois Curfman McInnes MatCreateMPIAIJ(). 142e0b365e2SLois Curfman McInnes 143e0b365e2SLois Curfman McInnes .keywords: matrix, create, initial 144e0b365e2SLois Curfman McInnes 145fafbff53SBarry Smith .seealso: MatCreateSeqAIJ((), MatCreateMPIAIJ(), 146fafbff53SBarry Smith MatCreateSeqRow(), MatCreateMPIRow(), 147fafbff53SBarry Smith MatCreateSeqBDiag(),MatCreateMPIBDiag(), 14839ddd567SLois Curfman McInnes MatCreateSeqDense(), MatCreateMPIDense(), 14939ddd567SLois Curfman McInnes MatCreateMPIRowbs(), MatConvert() 150416022c9SBarry Smith MatGetFormatFromOptions() 1517807a1faSBarry Smith @*/ 1526469c4f9SBarry Smith int MatCreate(MPI_Comm comm,int m,int n,Mat *V) 1537807a1faSBarry Smith { 154dbb450caSBarry Smith MatType type; 155dbb450caSBarry Smith int set,ierr; 156dbb450caSBarry Smith 157e3726954SLois Curfman McInnes ierr = MatGetFormatFromOptions(comm,0,&type,&set); CHKERRQ(ierr); 1582a7368beSLois Curfman McInnes if (type == MATSEQDENSE) 159b4fd4287SBarry Smith return MatCreateSeqDense(comm,m,n,PETSC_NULL,V); 1602a7368beSLois Curfman McInnes if (type == MATMPIBDIAG) 1612a7368beSLois Curfman McInnes return MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,PETSC_DEFAULT,PETSC_DEFAULT, 1622a7368beSLois Curfman McInnes PETSC_NULL,PETSC_NULL,V); 1632a7368beSLois Curfman McInnes if (type == MATSEQBDIAG) 1642a7368beSLois Curfman McInnes return MatCreateSeqBDiag(comm,m,n,PETSC_DEFAULT,PETSC_DEFAULT,PETSC_NULL, 1652a7368beSLois Curfman McInnes PETSC_NULL,V); 1662a7368beSLois Curfman McInnes if (type == MATMPIROWBS) 1672a7368beSLois Curfman McInnes return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,PETSC_DEFAULT,PETSC_NULL,PETSC_NULL,V); 1682a7368beSLois Curfman McInnes if (type == MATMPIROW) 1692a7368beSLois Curfman McInnes return MatCreateMPIRow(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT, 1702a7368beSLois Curfman McInnes PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,V); 1712a7368beSLois Curfman McInnes if (type == MATSEQROW) 1722a7368beSLois Curfman McInnes return MatCreateSeqRow(comm,m,n,PETSC_DEFAULT,PETSC_NULL,V); 1732a7368beSLois Curfman McInnes if (type == MATMPIDENSE) 174b4fd4287SBarry Smith return MatCreateMPIDense(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_NULL,V); 1752a7368beSLois Curfman McInnes if (type == MATMPIAIJ) 1762a7368beSLois Curfman McInnes return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,PETSC_DEFAULT, 1772a7368beSLois Curfman McInnes PETSC_NULL,PETSC_DEFAULT,PETSC_NULL,V); 1782a7368beSLois Curfman McInnes return MatCreateSeqAIJ(comm,m,n,PETSC_DEFAULT,PETSC_NULL,V); 1797807a1faSBarry Smith } 1807807a1faSBarry Smith 181dae03382SLois Curfman McInnes #include "matimpl.h" 182dae03382SLois Curfman McInnes /*@C 1834b0e389bSBarry Smith MatGetType - Gets the matrix type and name (as a string) from the matrix. 184dae03382SLois Curfman McInnes 185dae03382SLois Curfman McInnes Input Parameter: 186dae03382SLois Curfman McInnes . mat - the matrix 187dae03382SLois Curfman McInnes 188dae03382SLois Curfman McInnes Output Parameter: 1899a28b0a6SLois Curfman McInnes . type - the matrix type (or use PETSC_NULL) 1909a28b0a6SLois Curfman McInnes . name - name of matrix type (or use PETSC_NULL) 191dae03382SLois Curfman McInnes 192dae03382SLois Curfman McInnes .keywords: matrix, get, name 193dae03382SLois Curfman McInnes @*/ 1944b0e389bSBarry Smith int MatGetType(Mat mat,MatType *type,char **name) 195dae03382SLois Curfman McInnes { 196dae03382SLois Curfman McInnes int itype = (int)mat->type; 19739ddd567SLois Curfman McInnes char *matname[10]; 198d5d45c9bSBarry Smith 1994b0e389bSBarry Smith if (type) *type = (MatType) mat->type; 2004b0e389bSBarry Smith if (name) { 201416022c9SBarry Smith /* Note: Be sure that this list corresponds to the enum in mat.h */ 202ec8511deSBarry Smith matname[0] = "MATSEQDENSE"; 203ec8511deSBarry Smith matname[1] = "MATSEQAIJ"; 204dae03382SLois Curfman McInnes matname[2] = "MATMPIAIJ"; 205dae03382SLois Curfman McInnes matname[3] = "MATSHELL"; 206ec8511deSBarry Smith matname[4] = "MATSEQROW"; 207dae03382SLois Curfman McInnes matname[5] = "MATMPIROW"; 208ec8511deSBarry Smith matname[6] = "MATMPIROWBS"; 209ec8511deSBarry Smith matname[7] = "MATSEQBDIAG"; 2104c742c1bSLois Curfman McInnes matname[8] = "MATMPIBDIAG"; 21139ddd567SLois Curfman McInnes matname[9] = "MATMPIDENSE"; 212096963f5SLois Curfman McInnes if (itype < 0 || itype > 9) *name = "Unknown matrix type"; 213dae03382SLois Curfman McInnes else *name = matname[itype]; 2144b0e389bSBarry Smith } 215dae03382SLois Curfman McInnes return 0; 216dae03382SLois Curfman McInnes } 217dae03382SLois Curfman McInnes 218d5d45c9bSBarry Smith 219d5d45c9bSBarry Smith 220