Actual source code: ex136.c
petsc-3.13.6 2020-09-29
2: static char help[] = "Tests MatLoad() MatView() for MPIBAIJ.\n\n";
4: #include <petscmat.h>
6: int main(int argc,char **args)
7: {
8: Mat A,B;
10: char file[PETSC_MAX_PATH_LEN];
11: PetscBool flg;
12: PetscViewer fd;
14: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
15: PetscOptionsGetString(NULL,NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);
16: if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f option");
18: /*
19: Open binary file. Note that we use FILE_MODE_READ to indicate
20: reading from this file.
21: */
22: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
24: /*
25: Load the matrix; then destroy the viewer.
26: */
27: MatCreate(PETSC_COMM_WORLD,&A);
28: MatSetFromOptions(A);
29: MatLoad(A,fd);
30: PetscViewerDestroy(&fd);
32: /*
33: Open another binary file. Note that we use FILE_MODE_WRITE to indicate writing to the file
34: */
35: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_WRITE,&fd);
36: PetscViewerBinarySetFlowControl(fd,3);
37: /*
38: Save the matrix and vector; then destroy the viewer.
39: */
40: MatView(A,fd);
41: PetscViewerDestroy(&fd);
43: /* load the new matrix */
44: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"fileoutput",FILE_MODE_READ,&fd);
45: MatCreate(PETSC_COMM_WORLD,&B);
46: MatSetFromOptions(B);
47: MatLoad(B,fd);
48: PetscViewerDestroy(&fd);
50: MatEqual(A,B,&flg);
51: if (flg) {
52: PetscPrintf(PETSC_COMM_WORLD,"Matrices are equal\n");
53: } else {
54: PetscPrintf(PETSC_COMM_WORLD,"Matrices are not equal\n");
55: }
57: MatDestroy(&A);
58: MatDestroy(&B);
59: PetscFinalize();
60: return ierr;
61: }
64: /*TEST
66: test:
67: nsize: 3
68: requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
69: args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info
71: test:
72: suffix: 2
73: nsize: 5
74: requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
75: args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info
77: test:
78: suffix: 3
79: nsize: 7
80: requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
81: args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info
83: test:
84: suffix: 4
85: nsize: 3
86: requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
87: args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij
89: test:
90: suffix: 5
91: nsize: 5
92: requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
93: args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij
95: test:
96: suffix: 6
97: nsize: 7
98: requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
99: args: -f ${DATAFILESPATH}/matrices/cfd.2.100 -mat_view ascii::ascii_info -mat_type baij
101: TEST*/