Actual source code: ex1.c
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: petsc.h - base PETSc routines petscvec.h - vectors
18: petscsys.h - system routines petscmat.h - matrices
19: petscis.h - index sets petscviewer.h - viewers
20: */
21: #include petscmat.h
25: int main(int argc,char **args)
26: {
27: Mat A; /* matrix */
28: PetscViewer fd; /* viewer */
29: char file[2][PETSC_MAX_PATH_LEN]; /* input file name */
30: IS isrow,iscol; /* row and column permutations */
31: PetscErrorCode ierr;
32: const MatOrderingType rtype = MATORDERING_RCM;
33: PetscTruth flg,PreLoad = PETSC_FALSE;
35: PetscInitialize(&argc,&args,(char *)0,help);
38: /*
39: Determine files from which we read the two linear systems
40: (matrix and right-hand-side vector).
41: */
42: PetscOptionsGetString(PETSC_NULL,"-f0",file[0],PETSC_MAX_PATH_LEN-1,&flg);
43: if (!flg) SETERRQ(1,"Must indicate binary file with the -f0 option");
44: PetscOptionsGetString(PETSC_NULL,"-f1",file[1],PETSC_MAX_PATH_LEN-1,&flg);
45: if (flg) PreLoad = PETSC_TRUE;
47: /* -----------------------------------------------------------
48: Beginning of loop
49: ----------------------------------------------------------- */
50: /*
51: Loop through the reordering 2 times.
52: - The intention here is to preload and solve a small system;
53: then load another (larger) system and solve it as well.
54: This process preloads the instructions with the smaller
55: system so that more accurate performance monitoring (via
56: -log_summary) can be done with the larger one (that actually
57: is the system of interest).
58: */
59: PreLoadBegin(PreLoad,"Load");
61: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
62: Load system i
63: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
65: /*
66: Open binary file. Note that we use FILE_MODE_READ to indicate
67: reading from this file.
68: */
69: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file[PreLoadIt],FILE_MODE_READ,&fd);
71: /*
72: Load the matrix; then destroy the viewer.
73: */
74: MatLoad(fd,MATSEQAIJ,&A);
75: PetscViewerDestroy(fd);
78: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
79: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
81: PreLoadStage("Reordering");
82: MatGetOrdering(A,rtype,&isrow,&iscol);
84: /*
85: Free work space. All PETSc objects should be destroyed when they
86: are no longer needed.
87: */
88: MatDestroy(A);
89: ISDestroy(isrow);
90: ISDestroy(iscol);
91: PreLoadEnd();
93: PetscFinalize();
94: return 0;
95: }