xref: /petsc/src/mat/utils/matio.c (revision 0de55854bfaa60ad6b9e2d93a899f4a8e4f316bb)
1 #ifndef lint
2 static char vcid[] = "$Id: matio.c,v 1.6 1995/09/07 04:27:09 bsmith 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 <unistd.h>
11 #include "vec/vecimpl.h"
12 #include "sysio.h"
13 #include "pinclude/pviewer.h"
14 #include "matimpl.h"
15 #include "row.h"
16 
17 extern int MatLoad_MPIRowbs(Viewer,MatType,Mat *);
18 
19 
20 /* -------------------------------------------------------------------- */
21 
22 
23 /* @
24    MatLoad - Loads a matrix that has been stored in binary format
25    with MatView().
26 
27    Input Parameters:
28 .  comm - MPI communicator
29 .  fd - file descriptor (not FILE pointer).  Use open() for this.
30 .  outtype - type of output matrix
31 .  ind - optional index set of matrix rows to be locally owned
32    (or 0 for loading the entire matrix on each processor)
33 .  ind2 - optional index set with new matrix ordering (size = global
34    number of rows)
35 
36    Output Parameters:
37 .  newmat - new matrix
38 
39    Notes:
40    In parallel, each processor can load a subset of rows (or the
41    entire matrix).  This routine is especially useful when a large
42    matrix is stored on disk and only part of it is desired on each
43    processor.  For example, a parallel solver may access only some of
44    the rows from each processor.  The algorithm used here reads
45    relatively small blocks of data rather than reading the entire
46    matrix and then subsetting it.
47 
48    Currently, the _entire_ matrix must be loaded.  This should
49    probably change.
50 
51 .seealso: MatView(), VecLoad()
52 */
53 int MatLoad(Viewer bview,MatType outtype,Mat *newmat)
54 {
55   PetscObject vobj = (PetscObject) bview;
56   *newmat = 0;
57 
58   PETSCVALIDHEADERSPECIFIC(vobj,VIEWER_COOKIE);
59   if (vobj->type != BINARY_FILE_VIEWER)
60    SETERRQ(1,"MatLoad: Invalid viewer; open viewer with ViewerFileOpenBinary()");
61 
62   if (outtype == MATMPIROW_BS) {
63     return MatLoad_MPIRowbs(bview,outtype,newmat);
64   }
65   else {
66     SETERRQ(1,"MatLoad: cannot load with that matrix type yet");
67   }
68 
69   return 0;
70 }
71