Actual source code: ex3f.F

  1: !
  2: !      "$Id: ex3f.F,v 1.16 2001/08/07 03:02:34 balay Exp $";
  3: !
  4: !  Description: Displays a vector visually.
  5: !
  6: !/*T
  7: !   Concepts: vectors^drawing vectors;
  8: !   Processors: n
  9: !T*/
 10: ! -----------------------------------------------------------------------

 12:       program main
 13:       implicit none

 15: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 16: !                    Include files
 17: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 18: !
 19: !  The following include statements are required for Fortran programs
 20: !  that use PETSc vectors:
 21: !     petsc.h       - base PETSc routines
 22: !     petscvec.h    - vectors
 23: !  Include petscviewer.h so that we can use the PETSc viewers.
 24: !
 25:  #include include/finclude/petsc.h
 26:  #include include/finclude/petscvec.h
 27:  #include include/finclude/petscviewer.h

 29: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 30: !                 Beginning of program
 31: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 33:       Vec     x
 34:       PetscViewer  viewer
 35:       PetscScalar  v
 36:       integer i,istart,iend,n,ierr,flg

 38:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 39:       n = 50
 40:       call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-n',n,flg,ierr)

 42: !  Create a vector, specifying only its global dimension.
 43: !  When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
 44: !  the vector format (currently parallel
 45: !  or sequential) is determined at runtime.  Also, the parallel
 46: !  partitioning of the vector is determined by PETSc at runtime.
 47:       call VecCreate(PETSC_COMM_WORLD,x,ierr)
 48:       call VecSetSizes(x,PETSC_DECIDE,n,ierr)
 49:       call VecSetFromOptions(x,ierr)

 51: !  Currently, all PETSc parallel vectors are partitioned by
 52: !  contiguous chunks of rows across the processors.  Determine
 53: !  which vector are locally owned.
 54:       call VecGetOwnershipRange(x,istart,iend,ierr)

 56: !  Set the vector elements.
 57: !   - Always specify global locations of vector entries.
 58: !   - Each processor needs to insert only elements that it owns locally.
 59:       do 100 i=istart,iend-1
 60:          v = dble(i)
 61:          call VecSetValues(x,1,i,v,INSERT_VALUES,ierr)
 62:  100  continue

 64: !  Assemble vector, using the 2-step process:
 65: !    VecAssemblyBegin(), VecAssemblyEnd()
 66: !  Computations can be done while messages are in transition
 67: !  by placing code between these two statements.
 68:       call VecAssemblyBegin(x,ierr)
 69:       call VecAssemblyEnd(x,ierr)

 71: !  Open an X-window viewer.  Note that we specify the same communicator
 72: !  for the viewer as we used for the distributed vector (PETSC_COMM_WORLD).
 73: !    - Helpful runtime option:
 74: !         -draw_pause <pause> : sets time (in seconds) that the
 75: !               program pauses after PetscDrawPause() has been called
 76: !              (0 is default, -1 implies until user input).

 78:       call PetscViewerDrawOpen(PETSC_COMM_WORLD,PETSC_NULL_CHARACTER,        &
 79:      &                   PETSC_NULL_CHARACTER,0,0,300,300,viewer,ierr)

 81: !  View the vector
 82:       call VecView(x,viewer,ierr)

 84: !  Free work space.  All PETSc objects should be destroyed when they
 85: !  are no longer needed.

 87:       call PetscViewerDestroy(viewer,ierr)
 88:       call VecDestroy(x,ierr)

 90:       call PetscFinalize(ierr)
 91:       end
 92: