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