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: int main(int argc,char **args)
 25: {
 26:   Mat               A;                /* matrix */
 27:   PetscViewer       fd;               /* viewer */
 28:   char              file[2][128];     /* input file name */
 29:   IS                isrow,iscol;      /* row and column permutations */
 30:   int               ierr;
 31:   MatOrderingType   rtype = MATORDERING_RCM;
 32:   PetscTruth        flg,PreLoad = PETSC_FALSE;

 34:   PetscInitialize(&argc,&args,(char *)0,help);


 37:   /* 
 38:      Determine files from which we read the two linear systems
 39:      (matrix and right-hand-side vector).
 40:   */
 41:   PetscOptionsGetString(PETSC_NULL,"-f0",file[0],127,&flg);
 42:   if (!flg) SETERRQ(1,"Must indicate binary file with the -f0 option");
 43:   PetscOptionsGetString(PETSC_NULL,"-f1",file[1],127,&flg);
 44:   if (flg) PreLoad = PETSC_TRUE;

 46:   /* -----------------------------------------------------------
 47:                   Beginning of loop
 48:      ----------------------------------------------------------- */
 49:   /* 
 50:      Loop through the reordering 2 times.  
 51:       - The intention here is to preload and solve a small system;
 52:         then load another (larger) system and solve it as well.
 53:         This process preloads the instructions with the smaller
 54:         system so that more accurate performance monitoring (via
 55:         -log_summary) can be done with the larger one (that actually
 56:         is the system of interest). 
 57:   */
 58:   PreLoadBegin(PreLoad,"Load");

 60:     /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
 61:                            Load system i
 62:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 64:     /* 
 65:        Open binary file.  Note that we use PETSC_BINARY_RDONLY to indicate
 66:        reading from this file.
 67:     */
 68:     PetscViewerBinaryOpen(PETSC_COMM_WORLD,file[PreLoadIt],PETSC_BINARY_RDONLY,&fd);

 70:     /*
 71:        Load the matrix; then destroy the viewer.
 72:     */
 73:     MatLoad(fd,MATSEQAIJ,&A);
 74:     PetscViewerDestroy(fd);


 77:     /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
 78:      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 80:     PreLoadStage("Reordering");
 81:     MatGetOrdering(A,rtype,&isrow,&iscol);

 83:     /* 
 84:        Free work space.  All PETSc objects should be destroyed when they
 85:        are no longer needed.
 86:     */
 87:     MatDestroy(A);
 88:     ISDestroy(isrow);
 89:     ISDestroy(iscol);
 90:   PreLoadEnd();

 92:   PetscFinalize();
 93:   return 0;
 94: }