1 #ifndef lint 2 static char vcid[] = "$Id: gcreate.c,v 1.16 1995/04/29 14:18:09 curfman Exp curfman $"; 3 #endif 4 5 #include "sys.h" 6 #include "options.h" 7 #include "sysio.h" 8 #include "mat.h" 9 10 /*@C 11 MatCreateInitialMatrix - Creates a matrix, where the type is determined 12 from the options database. Generates a parallel MPI matrix if the 13 communicator has more than one processor. 14 15 Input Parameters: 16 . m - number of global rows 17 . n - number of global columns 18 . comm - MPI communicator 19 20 Output Parameter: 21 . V - location to stash resulting matrix 22 23 Options Database Keywords: 24 $ -mat_dense : dense type, uses MatCreateSequentialDense() 25 $ -mat_row : row type, uses MatCreateSequentialRow() 26 $ and MatCreateMPIRow() 27 $ -mat_rowbs : rowbs type (for parallel symmetric matrices), 28 $ uses MatCreateMPIRowbs() 29 $ -mat_bdiag : block diagonal type, uses 30 $ MatCreateSequentialBDiag() and 31 $ MatCreateMPIBDiag() 32 $ 33 $ -mpi_objects : uses MPI matrix, even for one processor 34 35 Notes: 36 The default matrix type is AIJ, using MatCreateSequentialAIJ() and 37 MatCreateMPIAIJ(). 38 39 .keywords: matrix, create, initial 40 41 .seealso: MatCreateSequentialAIJ((), MatCreateMPIAIJ(), 42 MatCreateSequentialRow(), MatCreateMPIRow(), 43 MatCreateSequentialDense(), MatCreateSequentialBDiag(), 44 MatCreateMPIRowbs() 45 @*/ 46 int MatCreateInitialMatrix(MPI_Comm comm,int m,int n,Mat *V) 47 { 48 int numtid; 49 MPI_Comm_size(comm,&numtid); 50 if (OptionsHasName(0,0,"-mat_dense")) { 51 return MatCreateSequentialDense(comm,m,n,V); 52 } 53 if (numtid > 1 || OptionsHasName(0,0,"-mpi_objects")) { 54 if (OptionsHasName(0,0,"-mat_row")) { 55 return MatCreateMPIRow(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 56 } 57 #if defined(HAVE_BLOCKSOLVE) && !defined(PETSC_COMPLEX) 58 if (OptionsHasName(0,0,"-mat_rowbs")) { 59 return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,5,0,0,V); 60 } 61 #endif 62 return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 63 } 64 if (OptionsHasName(0,0,"-mat_row")) { 65 return MatCreateSequentialRow(comm,m,n,10,0,V); 66 } 67 if (OptionsHasName(0,0,"-mat_bdiag")) { 68 int nb = 1, ndiag = 0, ndiag2, i, *d, ierr; 69 OptionsGetInt(0,0,"-mat_bdiag_bsize",&nb); 70 OptionsGetInt(0,0,"-mat_bdiag_ndiag",&ndiag); 71 if (ndiag) { 72 d = (int *)MALLOC( ndiag * sizeof(int) ); CHKPTR(d); 73 ndiag2 = ndiag; 74 OptionsGetIntArray(0,0,"-mat_bdiag_dvals",d,&ndiag2); 75 if (ndiag2 != ndiag) 76 SETERR(1,"Incompatible number of diagonals and diagonal values."); 77 } else SETERR(1,"Must set diagonals before creating matrix."); 78 ierr = MatCreateSequentialBDiag(comm,m,n,ndiag,nb,d,0,V); 79 if (d) FREE(d); 80 return ierr; 81 } 82 return MatCreateSequentialAIJ(comm,m,n,10,0,V); 83 } 84 85