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