Actual source code: ex136.c
petsc-3.3-p6 2013-02-11
2: static char help[] = "Tests MatLoad() MatView() for MPIBAIJ.\n\n";
4: #include <petscmat.h>
8: int main(int argc,char **args)
9: {
10: Mat A,B;
12: char file[PETSC_MAX_PATH_LEN];
13: PetscBool flg;
14: PetscViewer fd;
15: const MatType type = MATMPIBAIJ;
17: PetscInitialize(&argc,&args,(char *)0,help);
18: PetscOptionsHasName(PETSC_NULL,"-aij",&flg);
19: if (flg) type = MATMPIAIJ;
21: PetscOptionsGetString(PETSC_NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);
22: if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate binary file with the -f option");
24: /*
25: Open binary file. Note that we use FILE_MODE_READ to indicate
26: reading from this file.
27: */
28: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
30: /*
31: Load the matrix; then destroy the viewer.
32: */
33: MatCreate(PETSC_COMM_WORLD,&A);
34: MatSetType(A,type);
35: MatLoad(A,fd);
36: PetscViewerDestroy(&fd);
38: /*
39: Open another binary file. Note that we use FILE_MODE_WRITE to indicate
40: reading from this file.
41: */
42: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_WRITE,&fd);
43: PetscViewerBinarySetFlowControl(fd,3);
44: /*
45: Save the matrix and vector; then destroy the viewer.
46: */
47: MatView(A,fd);
48: PetscViewerDestroy(&fd);
50: /* load the new matrix */
51: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_READ,&fd);
52: MatCreate(PETSC_COMM_WORLD,&B);
53: MatSetType(B,type);
54: MatLoad(B,fd);
55: PetscViewerDestroy(&fd);
57: MatEqual(A,B,&flg);
58: if (flg) {
59: PetscPrintf(PETSC_COMM_WORLD,"Matrices are equal\n");
60: } else {
61: PetscPrintf(PETSC_COMM_WORLD,"Matrices are not equal\n");
62: }
64: MatDestroy(&A);
65: MatDestroy(&B);
66: PetscFinalize();
67: return 0;
68: }