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;

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

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

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

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

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

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

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

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

 79: /*TEST

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

 85: TEST*/