Actual source code: ex1.c
petsc-3.14.6 2021-03-30
2: static char help[] = "Reads a PETSc matrix and vector from a file and reorders it.\n\
3: -f0 <input_file> : first file to load (small system)\n\
4: -f1 <input_file> : second file to load (larger system)\n\n";
6: /*T
7: Concepts: Mat^ordering a matrix - loading a binary matrix and vector;
8: Concepts: Mat^loading a binary matrix and vector;
9: Concepts: Vectors^loading a binary vector;
10: Concepts: PetscLog^preloading executable
11: Processors: 1
12: T*/
14: /*
15: Include "petscmat.h" so that we can use matrices.
16: automatically includes:
17: petscsys.h - base PETSc routines petscvec.h - vectors
18: petscmat.h - matrices
19: petscis.h - index sets petscviewer.h - viewers
20: */
21: #include <petscmat.h>
23: int main(int argc,char **args)
24: {
25: Mat A; /* matrix */
26: PetscViewer fd; /* viewer */
27: char file[PETSC_MAX_PATH_LEN]; /* input file name */
28: IS isrow,iscol; /* row and column permutations */
29: PetscErrorCode ierr;
30: MatOrderingType rtype = MATORDERINGRCM;
31: PetscBool flg;
33: PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
34: /*
35: Determine files from which we read the two linear systems
36: (matrix and right-hand-side vector).
37: */
38: PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);
39: if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f option");
41: /* -----------------------------------------------------------
42: Beginning of loop
43: ----------------------------------------------------------- */
44: /*
45: Loop through the reordering 2 times.
46: - The intention here is to preload and solve a small system;
47: then load another (larger) system and solve it as well.
48: This process preloads the instructions with the smaller
49: system so that more accurate performance monitoring (via
50: -log_view) can be done with the larger one (that actually
51: is the system of interest).
52: */
54: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
55: Load system i
56: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
58: /*
59: Open binary file. Note that we use FILE_MODE_READ to indicate
60: reading from this file.
61: */
62: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
64: /*
65: Load the matrix; then destroy the viewer.
66: */
67: MatCreate(PETSC_COMM_WORLD,&A);
68: MatSetType(A,MATSEQAIJ);
69: MatLoad(A,fd);
70: PetscViewerDestroy(&fd);
72: MatGetOrdering(A,rtype,&isrow,&iscol);
73: ISView(isrow,PETSC_VIEWER_STDOUT_WORLD);
75: /*
76: Free work space. All PETSc objects should be destroyed when they
77: are no longer needed.
78: */
79: MatDestroy(&A);
80: ISDestroy(&isrow);
81: ISDestroy(&iscol);
83: PetscFinalize();
84: return ierr;
85: }
89: /*TEST
91: test:
92: requires: datafilespath double !complex !define(PETSC_USE_64BIT_INDICES)
93: args: -f ${DATAFILESPATH}/matrices/medium -viewer_binary_skip_info
95: TEST*/