Actual source code: ex34.c
2: static char help[] = "Reads a matrix and vector from a file and writes to another. Input options:\n\
3: -fin <input_file> : file to load. For an example of a 5X5 5-pt. stencil,\n\
4: use the file matbinary.ex.\n\
5: -fout <output_file> : file for saving output matrix and vector\n\n";
7: #include <petscmat.h>
11: int main(int argc,char **args)
12: {
14: PetscBool flg;
15: Vec x;
16: Mat A;
17: char file[256];
18: PetscViewer fd;
20: PetscInitialize(&argc,&args,(char *)0,help);
22: /* Read matrix and RHS */
23: PetscOptionsGetString(PETSC_NULL,"-fin",file,256,&flg);
24: if (!flg) SETERRQ(PETSC_COMM_WORLD,1,help);
25: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
26: MatCreate(PETSC_COMM_WORLD,&A);
27: MatSetType(A,MATSEQAIJ);
28: MatLoad(A,fd);
29: VecCreate(PETSC_COMM_WORLD,&x);
30: VecLoad(x,fd);
31: PetscViewerDestroy(&fd);
33: /* Write matrix and vector */
34: PetscOptionsGetString(PETSC_NULL,"-fout",file,256,&flg);
35: if (!flg) SETERRQ(PETSC_COMM_WORLD,1,help);
36: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_WRITE,&fd);
37: MatView(A,fd);
38: VecView(x,fd);
40: /* Free data structures */
41: MatDestroy(&A);
42: VecDestroy(&x);
43: PetscViewerDestroy(&fd);
45: PetscFinalize();
46: return 0;
47: }