Actual source code: ex1.c
1: /*$Id: ex1.c,v 1.28 2001/04/10 19:35:58 bsmith Exp $*/
3: static char help[] = "Reads a PETSc matrix and vector from a file and reorders it.n
4: -f0 <input_file> : first file to load (small system)n
5: -f1 <input_file> : second file to load (larger system)nn";
7: /*T
8: Concepts: Mat^ordering a matrix - loading a binary matrix and vector;
9: Concepts: Mat^loading a binary matrix and vector;
10: Concepts: Vectors^loading a binary vector;
11: Concepts: PetscLog^preloading executable
12: Processors: 1
13: T*/
15: /*
16: Include "petscmat.h" so that we can use matrices.
17: automatically includes:
18: petsc.h - base PETSc routines petscvec.h - vectors
19: petscsys.h - system routines petscmat.h - matrices
20: petscis.h - index sets petscviewer.h - viewers
21: */
22: #include petscmat.h
24: #undef __FUNCT__
26: int main(int argc,char **args)
27: {
28: Mat A; /* matrix */
29: PetscViewer fd; /* viewer */
30: char file[2][128]; /* input file name */
31: IS isrow,iscol; /* row and column permutations */
32: int ierr;
33: MatOrderingType rtype = MATORDERING_RCM;
34: PetscTruth flg,PreLoad = PETSC_FALSE;
36: PetscInitialize(&argc,&args,(char *)0,help);
39: /*
40: Determine files from which we read the two linear systems
41: (matrix and right-hand-side vector).
42: */
43: PetscOptionsGetString(PETSC_NULL,"-f0",file[0],127,&flg);
44: if (!flg) SETERRQ(1,"Must indicate binary file with the -f0 option");
45: PetscOptionsGetString(PETSC_NULL,"-f1",file[1],127,&flg);
46: if (flg) PreLoad = PETSC_TRUE;
48: /* -----------------------------------------------------------
49: Beginning of loop
50: ----------------------------------------------------------- */
51: /*
52: Loop through the reordering 2 times.
53: - The intention here is to preload and solve a small system;
54: then load another (larger) system and solve it as well.
55: This process preloads the instructions with the smaller
56: system so that more accurate performance monitoring (via
57: -log_summary) can be done with the larger one (that actually
58: is the system of interest).
59: */
60: PreLoadBegin(PreLoad,"Load");
62: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
63: Load system i
64: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
66: /*
67: Open binary file. Note that we use PETSC_BINARY_RDONLY to indicate
68: reading from this file.
69: */
70: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file[PreLoadIt],PETSC_BINARY_RDONLY,&fd);
72: /*
73: Load the matrix; then destroy the viewer.
74: */
75: MatLoad(fd,MATSEQAIJ,&A);
76: PetscViewerDestroy(fd);
79: /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
80: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
82: PreLoadStage("Reordering");
83: MatGetOrdering(A,rtype,&isrow,&iscol);
85: /*
86: Free work space. All PETSc objects should be destroyed when they
87: are no longer needed.
88: */
89: MatDestroy(A);
90: ISDestroy(isrow);
91: ISDestroy(iscol);
92: PreLoadEnd();
94: PetscFinalize();
95: return 0;
96: }