1 #ifndef lint 2 static char vcid[] = "$Id: gcreate.c,v 1.22 1995/05/16 00:42:45 curfman 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,"-mat_dense")) { 50 return MatCreateSequentialDense(comm,m,n,V); 51 } 52 if (numtid > 1 || OptionsHasName(0,"-mpi_objects")) { 53 if (OptionsHasName(0,"-mat_row")) { 54 return MatCreateMPIRow(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 55 } 56 #if defined(HAVE_BLOCKSOLVE) && !defined(__cplusplus) 57 if (OptionsHasName(0,"-mat_rowbs")) { 58 return MatCreateMPIRowbs(comm,PETSC_DECIDE,m,5,0,0,V); 59 } 60 #endif 61 return MatCreateMPIAIJ(comm,PETSC_DECIDE,PETSC_DECIDE,m,n,5,0,0,0,V); 62 } 63 if (OptionsHasName(0,"-mat_row")) { 64 return MatCreateSequentialRow(comm,m,n,10,0,V); 65 } 66 if (OptionsHasName(0,"-mat_bdiag")) { 67 int nb = 1, ndiag = 0, ndiag2, *d, ierr; 68 OptionsGetInt(0,"-mat_bdiag_bsize",&nb); 69 OptionsGetInt(0,"-mat_bdiag_ndiag",&ndiag); 70 if (ndiag) { 71 d = (int *)MALLOC( ndiag * sizeof(int) ); CHKPTR(d); 72 ndiag2 = ndiag; 73 OptionsGetIntArray(0,"-mat_bdiag_dvals",d,&ndiag2); 74 if (ndiag2 != ndiag) { 75 SETERR(1,"Incompatible number of diagonals and diagonal values."); 76 } 77 } 78 else SETERR(1,"Must set diagonals before creating matrix."); 79 ierr = MatCreateSequentialBDiag(comm,m,n,ndiag,nb,d,0,V); 80 if (d) FREE(d); 81 return ierr; 82 } 83 return MatCreateSequentialAIJ(comm,m,n,10,0,V); 84 } 85 86