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: 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: MatOrderingType rtype = MATORDERINGRCM;
30: PetscBool flg;
32: PetscInitialize(&argc,&args,(char*)0,help);
33: /*
34: Determine files from which we read the two linear systems
35: (matrix and right-hand-side vector).
36: */
37: PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);
40: /* -----------------------------------------------------------
41: Beginning of loop
42: ----------------------------------------------------------- */
43: /*
44: Loop through the reordering 2 times.
45: - The intention here is to preload and solve a small system;
46: then load another (larger) system and solve it as well.
47: This process preloads the instructions with the smaller
48: system so that more accurate performance monitoring (via
49: -log_view) can be done with the larger one (that actually
50: is the system of interest).
51: */
53: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
54: Load system i
55: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
57: /*
58: Open binary file. Note that we use FILE_MODE_READ to indicate
59: reading from this file.
60: */
61: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
63: /*
64: Load the matrix; then destroy the viewer.
65: */
66: MatCreate(PETSC_COMM_WORLD,&A);
67: MatSetType(A,MATSEQAIJ);
68: MatLoad(A,fd);
69: PetscViewerDestroy(&fd);
71: MatGetOrdering(A,rtype,&isrow,&iscol);
72: ISView(isrow,PETSC_VIEWER_STDOUT_WORLD);
74: /*
75: Free work space. All PETSc objects should be destroyed when they
76: are no longer needed.
77: */
78: MatDestroy(&A);
79: ISDestroy(&isrow);
80: ISDestroy(&iscol);
82: PetscFinalize();
83: return 0;
84: }
86: /*TEST
88: test:
89: requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
90: args: -f ${DATAFILESPATH}/matrices/medium -viewer_binary_skip_info
92: TEST*/