1 #ifndef lint 2 static char vcid[] = "$Id: gcreate.c,v 1.23 1995/05/18 22:46:31 bsmith Exp bsmith $"; 3 #endif 4 5 #include "sys.h" 6 #include "sysio.h" 7 #include "mat.h" 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_dense : dense type, uses MatCreateSequentialDense() 24 $ -mat_row : row type, uses MatCreateSequentialRow() 25 $ and MatCreateMPIRow() 26 $ -mat_rowbs : rowbs type (for parallel symmetric matrices), 27 $ uses MatCreateMPIRowbs() 28 $ -mat_bdiag : block diagonal type, uses 29 $ MatCreateSequentialBDiag() and 30 $ MatCreateMPIBDiag() 31 $ 32 $ -mpi_objects : uses MPI matrix, even for one processor 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_rowbs\n"); 51 MPIU_printf(comm," -mat_bdiag, -mpi_objects\n"); 52 } 53 if (OptionsHasName(0,"-mat_dense")) { 54 return MatCreateSequentialDense(comm,m,n,V); 55 } 56 if (numtid > 1 || OptionsHasName(0,"-mpi_objects")) { 57 if (OptionsHasName(0,"-mat_row")) { 58 return MatCreateMPIRow(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 59 } 60 #if defined(HAVE_BLOCKSOLVE) && !defined(__cplusplus) 61 if (OptionsHasName(0,"-mat_rowbs")) { 62 return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,5,0,0,V); 63 } 64 #endif 65 return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 66 } 67 if (OptionsHasName(0,"-mat_row")) { 68 return MatCreateSequentialRow(comm,m,n,10,0,V); 69 } 70 if (OptionsHasName(0,"-mat_bdiag")) { 71 int nb = 1, ndiag = 0, ndiag2, *d, ierr; 72 OptionsGetInt(0,"-mat_bdiag_bsize",&nb); 73 OptionsGetInt(0,"-mat_bdiag_ndiag",&ndiag); 74 if (ndiag) { 75 d = (int *)MALLOC( ndiag * sizeof(int) ); CHKPTR(d); 76 ndiag2 = ndiag; 77 OptionsGetIntArray(0,"-mat_bdiag_dvals",d,&ndiag2); 78 if (ndiag2 != ndiag) { 79 SETERR(1,"Incompatible number of diagonals and diagonal values."); 80 } 81 } 82 else SETERR(1,"Must set diagonals before creating matrix."); 83 ierr = MatCreateSequentialBDiag(comm,m,n,ndiag,nb,d,0,V); 84 if (d) FREE(d); 85 return ierr; 86 } 87 return MatCreateSequentialAIJ(comm,m,n,10,0,V); 88 } 89 90