2
#ifdef PETSC_RCS_HEADER
3
static char vcid[] = "$Id: ex2.c,v 1.2 1999/04/06 21:27:41 bsmith Exp $";
7
"Reads a PETSc matrix and vector from a file and saves in an ASCII file that\n\
8
can be read by the SPAI test program. Input parameters include\n\
9
-f0 <input_file> : file to load\n\n";
12
Routines: MatLoad(); VecLoad();
13
Routines: ViewerBinaryOpen();
18
Include "mat.h" so that we can use matrices. Note that this file
19
automatically includes:
20
petsc.h - base PETSc routines vec.h - vectors
21
sys.h - system routines is.h - index sets
25
#include "src/contrib/spai/include/spai.h"
27
int main(int argc,char **args)
31
Viewer viewer; /* viewer */
32
char file[128]; /* input file name */
38
PetscInitialize(&argc,&args,(char *)0,help);
40
#if defined(USE_PETSC_COMPLEX)
41
SETERRA(1,0,"This example does not work with complex numbers");
45
Determine files from which we read the linear system
46
(matrix and right-hand-side vector).
48
ierr = OptionsGetString(PETSC_NULL,"-f0",file,127,&flg); CHKERRA(ierr);
49
if (!flg) SETERRA(1,0,"Must indicate binary file with the -f0 option");
53
Open binary file. Note that we use BINARY_RDONLY to indicate
54
reading from this file.
56
ierr = ViewerBinaryOpen(PETSC_COMM_WORLD,file,BINARY_RDONLY,&viewer);CHKERRA(ierr);
59
Determine matrix format to be used (specified at runtime).
60
See the manpage for MatLoad() for available formats.
62
ierr = MatGetTypeFromOptions(PETSC_COMM_WORLD,0,&mtype,&set); CHKERRQ(ierr);
65
Load the matrix and vector; then destroy the viewer.
67
ierr = MatLoad(viewer,mtype,&A); CHKERRA(ierr);
68
ierr = VecLoad(viewer,&b); CHKERRA(ierr);
69
ierr = ViewerDestroy(viewer); CHKERRA(ierr);
71
fd = fopen("example_matrix","w");
72
ierr = MatDumpSPAI(A,fd); CHKERRQ(ierr);
74
fd = fopen("example_rhs","w");
75
ierr = VecDumpSPAI(b,fd); CHKERRQ(ierr);
78
ierr = MatDestroy(A); CHKERRA(ierr);
79
ierr = VecDestroy(b); CHKERRA(ierr);