1 #ifndef lint 2 static char vcid[] = "$Id: matio.c,v 1.20 1995/10/26 21:45:14 curfman Exp bsmith $"; 3 #endif 4 5 /* 6 This file contains simple binary read/write routines for matrices. 7 */ 8 9 #include "petsc.h" 10 #include "vec/vecimpl.h" 11 #include "../matimpl.h" 12 #include "sysio.h" 13 #include "pinclude/pviewer.h" 14 15 extern int MatLoad_MPIRowbs(Viewer,MatType,Mat*); 16 extern int MatLoad_SeqAIJ(Viewer,MatType,Mat*); 17 extern int MatLoad_MPIAIJ(Viewer,MatType,Mat*); 18 extern int MatLoad_SeqBDiag(Viewer,MatType,Mat*); 19 extern int MatLoad_MPIBDiag(Viewer,MatType,Mat*); 20 extern int MatLoad_SeqDense(Viewer,MatType,Mat*); 21 extern int MatLoad_MPIDense(Viewer,MatType,Mat*); 22 23 /*@C 24 MatLoad - Loads a matrix that has been stored in binary format 25 with MatView(). 26 27 Input Parameters: 28 . bview - binary file viewer, created with ViewerFileOpenBinary() 29 . outtype - type of matrix desired, for example MATSEQAIJ, 30 MATMPIROWBS, etc. See types in petsc/include/mat.h. 31 32 Output Parameters: 33 . newmat - new matrix 34 35 Notes: 36 In parallel, each processor can load a subset of rows (or the 37 entire matrix). This routine is especially useful when a large 38 matrix is stored on disk and only part of it is desired on each 39 processor. For example, a parallel solver may access only some of 40 the rows from each processor. The algorithm used here reads 41 relatively small blocks of data rather than reading the entire 42 matrix and then subsetting it. 43 44 Notes for advanced users: 45 Most users should not need to know the details of the binary storage 46 format, since MatLoad() and MatView() completely hide these details. 47 But for anyone who's interested, the standard binary matrix storage 48 format is 49 50 $ int MAT_COOKIE 51 $ int number of rows 52 $ int number of columns 53 $ int total number of nonzeros 54 $ int *number nonzeros in each row 55 $ int *column indices of all nonzeros (starting index is zero) 56 $ Scalar *values of all nonzeros 57 58 .keywords: matrix, load, binary, input 59 60 .seealso: ViewerFileOpenBinary(), MatView(), VecLoad() 61 @*/ 62 int MatLoad(Viewer bview,MatType outtype,Mat *newmat) 63 { 64 PetscObject vobj = (PetscObject) bview; 65 int ierr,set; 66 MatType type; 67 *newmat = 0; 68 69 PETSCVALIDHEADERSPECIFIC(vobj,VIEWER_COOKIE); 70 if (vobj->type != BINARY_FILE_VIEWER) 71 SETERRQ(1,"MatLoad: Invalid viewer; open viewer with ViewerFileOpenBinary()"); 72 73 PLogEventBegin(MAT_Load,bview,0,0,0); 74 ierr = MatGetFormatFromOptions(vobj->comm,0,&type,&set); CHKERRQ(ierr); 75 if (!set) type = outtype; 76 77 if (type == MATSEQAIJ) { 78 ierr = MatLoad_SeqAIJ(bview,type,newmat); CHKERRQ(ierr); 79 } 80 else if (type == MATMPIAIJ) { 81 ierr = MatLoad_MPIAIJ(bview,type,newmat); CHKERRQ(ierr); 82 } 83 else if (type == MATSEQBDIAG) { 84 ierr = MatLoad_SeqBDiag(bview,type,newmat); CHKERRQ(ierr); 85 } 86 else if (type == MATMPIBDIAG) { 87 ierr = MatLoad_MPIBDiag(bview,type,newmat); CHKERRQ(ierr); 88 } 89 else if (type == MATSEQDENSE) { 90 ierr = MatLoad_SeqDense(bview,type,newmat); CHKERRQ(ierr); 91 } 92 else if (type == MATMPIDENSE) { 93 ierr = MatLoad_MPIDense(bview,type,newmat); CHKERRQ(ierr); 94 } 95 #if defined(HAVE_BLOCKSOLVE) && !defined(__cplusplus) 96 else if (type == MATMPIROWBS) { 97 ierr = MatLoad_MPIRowbs(bview,type,newmat); CHKERRQ(ierr); 98 } 99 #endif 100 else { 101 SETERRQ(1,"MatLoad: cannot load with that matrix type yet"); 102 } 103 104 PLogEventEnd(MAT_Load,bview,0,0,0); 105 return 0; 106 } 107