1 2 #ifndef lint 3 static char vcid[] = "$Id: gcreate.c,v 1.36 1995/09/04 17:05:59 bsmith Exp curfman $"; 4 #endif 5 6 #include "sys.h" 7 #include "mat.h" /*I "mat.h" I*/ 8 9 /*@C 10 MatCreate - Creates a matrix, where the type is determined 11 from the options database. Generates a parallel MPI matrix if the 12 communicator has more than one processor. 13 14 Input Parameters: 15 . m - number of global rows 16 . n - number of global columns 17 . comm - MPI communicator 18 19 Output Parameter: 20 . V - location to stash resulting matrix 21 22 Options Database Keywords: 23 $ -mat_aij : AIJ type, uses MatCreateSequentialAIJ() 24 $ and MatCreateMPIAIJ() 25 $ -mat_dense : dense type, uses MatCreateSequentialDense() 26 $ -mat_row : row type, uses MatCreateSequentialRow() 27 $ and MatCreateMPIRow() 28 $ -mat_rowbs : rowbs type. 29 $ uses MatCreateMPIRowbs() 30 $ -mat_bdiag : block diagonal type, uses 31 $ MatCreateSequentialBDiag() and 32 $ MatCreateMPIBDiag() 33 $ 34 $ -mpi_objects : uses MPI matrix (parallel format), even for one processor 35 36 Notes: 37 The default matrix type is AIJ, using MatCreateSequentialAIJ() and 38 MatCreateMPIAIJ(). 39 40 .keywords: matrix, create, initial 41 42 .seealso: MatCreateSequentialAIJ((), MatCreateMPIAIJ(), 43 MatCreateSequentialRow(), MatCreateMPIRow(), 44 MatCreateSequentialBDiag(),MatCreateMPIBDiag(), 45 MatCreateSequentialDense(), MatCreateMPIRowbs(), MatConvert() 46 @*/ 47 int MatCreate(MPI_Comm comm,int m,int n,Mat *V) 48 { 49 int numtid; 50 MPI_Comm_size(comm,&numtid); 51 if (OptionsHasName(0,"-help")) { 52 MPIU_printf(comm,"MatCreate() options: -mat_dense, -mat_row -mat_rowbs\n"); 53 MPIU_printf(comm," -mat_bdiag, -mpi_objects\n"); 54 } 55 if (OptionsHasName(0,"-mat_dense")) { 56 return MatCreateSequentialDense(comm,m,n,V); 57 } 58 if (OptionsHasName(0,"-mat_bdiag")) { 59 int nb = 1, ndiag = 0, ndiag2, *d, ierr; 60 if (OptionsHasName(0,"-help")) { 61 MPIU_printf(comm,"Options with -mat_bdiag: -mat_bdiag_bsize block_size\n"); 62 MPIU_printf(comm," -mat_bdiag_ndiag number_diags \n"); 63 MPIU_printf(comm," -mat_bdiag_dvals d1,d2,d3... (diagonal numbers)\n"); 64 MPIU_printf(comm," (for example) -mat_bdiag_dvals -5,-1,0,1,5\n"); 65 } 66 OptionsGetInt(0,"-mat_bdiag_bsize",&nb); 67 OptionsGetInt(0,"-mat_bdiag_ndiag",&ndiag); 68 if (!ndiag) SETERRQ(1,"MatCreate:Must set diagonals before creating mat"); 69 d = (int *)PETSCMALLOC( ndiag * sizeof(int) ); CHKPTRQ(d); 70 ndiag2 = ndiag; 71 OptionsGetIntArray(0,"-mat_bdiag_dvals",d,&ndiag2); 72 if (ndiag2 != ndiag) { 73 SETERRQ(1,"MatCreate:Incompatible number of diags and diagonal vals"); 74 } 75 if (numtid > 1 || OptionsHasName(0,"-mpi_objects")) 76 ierr = MatCreateMPIBDiag(comm,PETSC_DECIDE,m,n,ndiag,nb,d,0,V); 77 else 78 ierr = MatCreateSequentialBDiag(comm,m,n,ndiag,nb,d,0,V); 79 CHKERRQ(ierr); 80 if (d) PETSCFREE(d); 81 return ierr; 82 } 83 #if defined(HAVE_BLOCKSOLVE) && !defined(__cplusplus) 84 if (OptionsHasName(0,"-mat_rowbs")) { 85 return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,5,0,0,V); 86 } 87 #endif 88 if (numtid > 1 || OptionsHasName(0,"-mpi_objects")) { 89 if (OptionsHasName(0,"-mat_row")) { 90 return MatCreateMPIRow(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 91 } 92 return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 93 } 94 if (OptionsHasName(0,"-mat_row")) { 95 return MatCreateSequentialRow(comm,m,n,10,0,V); 96 } 97 return MatCreateSequentialAIJ(comm,m,n,10,0,V); 98 } 99 100 #include "matimpl.h" 101 /*@C 102 MatGetName - Gets the matrix type name (as a string) from the matrix. 103 104 Input Parameter: 105 . mat - the matrix 106 107 Output Parameter: 108 . name - name of matrix type 109 110 .keywords: matrix, get, name 111 112 .seealso: MatGetType() 113 @*/ 114 int MatGetName(Mat mat,char **name) 115 { 116 /* Note: Be sure that this list corresponds to the enum in mat.h */ 117 int itype = (int)mat->type; 118 char *matname[9]; 119 matname[0] = "MATDENSE"; 120 matname[1] = "MATAIJ"; 121 matname[2] = "MATMPIAIJ"; 122 matname[3] = "MATSHELL"; 123 matname[4] = "MATROW"; 124 matname[5] = "MATMPIROW"; 125 matname[6] = "MATMPIROW_BS"; 126 matname[7] = "MATBDIAG"; 127 matname[8] = "MATMPIBDIAG"; 128 if (itype < 0 || itype > 8) *name = "unknown matrix type"; 129 else *name = matname[itype]; 130 return 0; 131 } 132 133