Actual source code: ex3f.F

petsc-3.11.4 2019-09-28
Report Typos and Errors
  1: !
  2: !
  3: !  Description: Displays a vector visually.
  4: !
  5: !/*T
  6: !   Concepts: vectors^drawing vectors;
  7: !   Processors: n
  8: !T*/
  9: ! -----------------------------------------------------------------------

 11:       program main
 12:  #include <petsc/finclude/petscvec.h>
 13:       use petscvec
 14:       implicit none

 16: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 17: !                 Beginning of program
 18: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 20:       Vec     x
 21:       PetscViewer  viewer
 22:       PetscScalar  v
 23:       PetscInt :: i,istart,iend
 24:       PetscInt, parameter :: ione = 1, n = 50
 25:       PetscErrorCode ierr
 26:       PetscBool  flg

 28:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 29:       if (ierr /= 0) then
 30:          print*,'PetscInitialize failed'
 31:          stop
 32:       endif
 33:       call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,      &
 34:      &                        '-n',n,flg,ierr)

 36: !  Create a vector, specifying only its global dimension.
 37: !  When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
 38: !  the vector format (currently parallel
 39: !  or sequential) is determined at runtime.  Also, the parallel
 40: !  partitioning of the vector is determined by PETSc at runtime.
 41:       call VecCreate(PETSC_COMM_WORLD,x,ierr)
 42:       call VecSetSizes(x,PETSC_DECIDE,n,ierr)
 43:       call VecSetFromOptions(x,ierr)

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

 50: !  Set the vector elements.
 51: !   - Always specify global locations of vector entries.
 52: !   - Each processor needs to insert only elements that it owns locally.
 53:       do 100 i=istart,iend-1
 54:          v = 1.0*real(i)
 55:          call VecSetValues(x,ione,i,v,INSERT_VALUES,ierr)
 56:  100  continue

 58: !  Assemble vector, using the 2-step process:
 59: !    VecAssemblyBegin(), VecAssemblyEnd()
 60: !  Computations can be done while messages are in transition
 61: !  by placing code between these two statements.
 62:       call VecAssemblyBegin(x,ierr)
 63:       call VecAssemblyEnd(x,ierr)

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

 72:       call PetscViewerDrawOpen(PETSC_COMM_WORLD,PETSC_NULL_CHARACTER,        &
 73:      &                   PETSC_NULL_CHARACTER,0,0,300,300,viewer,ierr)

 75: !  View the vector
 76:       call VecView(x,viewer,ierr)

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

 81:       call PetscViewerDestroy(viewer,ierr)
 82:       call VecDestroy(x,ierr)

 84:       call PetscFinalize(ierr)
 85:       end


 88: !/*TEST
 89: !
 90: !     test:
 91: !       nsize: 2
 92: !
 93: !TEST*/