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: /*
  7:   Include "petscmat.h" so that we can use matrices.
  8:   automatically includes:
  9:      petscsys.h       - base PETSc routines   petscvec.h    - vectors
 10:      petscmat.h    - matrices
 11:      petscis.h     - index sets            petscviewer.h - viewers
 12: */
 13: #include <petscmat.h>

 15: int main(int argc,char **args)
 16: {
 17:   Mat             A;                      /* matrix */
 18:   PetscViewer     fd;                     /* viewer */
 19:   char            file[PETSC_MAX_PATH_LEN];           /* input file name */
 20:   IS              isrow,iscol;            /* row and column permutations */
 21:   MatOrderingType rtype = MATORDERINGRCM;
 22:   PetscBool       flg;

 24:   PetscInitialize(&argc,&args,(char*)0,help);
 25:   /*
 26:      Determine files from which we read the two linear systems
 27:      (matrix and right-hand-side vector).
 28:   */
 29:   PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);

 32:   /* -----------------------------------------------------------
 33:                   Beginning of loop
 34:      ----------------------------------------------------------- */
 35:   /*
 36:      Loop through the reordering 2 times.
 37:       - The intention here is to preload and solve a small system;
 38:         then load another (larger) system and solve it as well.
 39:         This process preloads the instructions with the smaller
 40:         system so that more accurate performance monitoring (via
 41:         -log_view) can be done with the larger one (that actually
 42:         is the system of interest).
 43:   */

 45:   /* - - - - - - - - - - - New Stage - - - - - - - - - - - - -
 46:                          Load system i
 47:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

 49:   /*
 50:      Open binary file.  Note that we use FILE_MODE_READ to indicate
 51:      reading from this file.
 52:   */
 53:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);

 55:   /*
 56:      Load the matrix; then destroy the viewer.
 57:   */
 58:   MatCreate(PETSC_COMM_WORLD,&A);
 59:   MatSetType(A,MATSEQAIJ);
 60:   MatLoad(A,fd);
 61:   PetscViewerDestroy(&fd);

 63:   MatGetOrdering(A,rtype,&isrow,&iscol);
 64:   ISView(isrow,PETSC_VIEWER_STDOUT_WORLD);

 66:   /*
 67:      Free work space.  All PETSc objects should be destroyed when they
 68:      are no longer needed.
 69:   */
 70:   MatDestroy(&A);
 71:   ISDestroy(&isrow);
 72:   ISDestroy(&iscol);

 74:   PetscFinalize();
 75:   return 0;
 76: }

 78: /*TEST

 80:    test:
 81:       requires: datafilespath double !complex !defined(PETSC_USE_64BIT_INDICES)
 82:       args: -f ${DATAFILESPATH}/matrices/medium -viewer_binary_skip_info

 84: TEST*/