Actual source code: ex11f.F

petsc-3.7.3 2016-07-24
Report Typos and Errors
  1: !
  2: !
  3: !
  4: !/*T
  5: !   Concepts: vectors^norms of sub-vectors;
  6: !   Processors: n
  7: !T*/

  9:       program main
 10:       implicit none

 12: !
 13: !  The following include statements are required for Fortran programs
 14: !  that use PETSc vectors:
 15: !     petscsys.h       - base PETSc routines
 16: !     petscvec.h    - vectors
 17: !  Additional include statements may be needed if using additional
 18: !  PETSc routines in a Fortran program, e.g.,
 19: !     petscviewer.h - viewers
 20: !     petscis.h     - index sets
 21: !
 22: #include <petsc/finclude/petscsys.h>
 23: #include <petsc/finclude/petscvec.h>
 24: !

 26:       Vec               x
 27:       PetscReal         norm
 28:       PetscBool  flg
 29:       PetscMPIInt rank
 30:       PetscInt n,bs,comp
 31:       PetscErrorCode ierr
 32:       PetscScalar       one

 34:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 35:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)

 37:       n   = 20
 38:       one = 1.0
 39:       call PetscOptionsGetInt(PETSC_NULL_OBJECT,PETSC_NULL_CHARACTER,       &
 40:      &                        '-n',n,flg,ierr)

 42: !
 43: !     Create a vector, specifying only its global dimension.
 44: !     When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
 45: !     the vector format (currently parallel,
 46: !     shared, or sequential) is determined at runtime.  Also, the parallel
 47: !     partitioning of the vector is determined by PETSc at runtime.
 48: !
 49: !     Routines for creating particular vector types directly are:
 50: !        VecCreateSeq() - uniprocessor vector
 51: !        VecCreateMPI() - distributed vector, where the user can
 52: !                         determine the parallel partitioning
 53: !        VecCreateShared() - parallel vector that uses shared memory
 54: !                            (available only on the SGI); otherwise,
 55: !                            is the same as VecCreateMPI()
 56: !
 57: !     With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
 58: !     -vec_type mpi or -vec_type shared causes the
 59: !     particular type of vector to be formed.

 61:       call VecCreate(PETSC_COMM_WORLD,x,ierr)
 62:       call VecSetSizes(x,PETSC_DECIDE,n,ierr)
 63:       bs = 2
 64:       call VecSetBlockSize(x,bs,ierr)
 65:       call VecSetFromOptions(x,ierr)

 67: !
 68: !     Set the vectors to entries to a constant value.
 69: !
 70:       call VecSet(x,one,ierr)

 72:       call VecNorm(x,NORM_2,norm,ierr)
 73:       if (rank .eq. 0) then
 74:          write (6,100) norm
 75:  100     format ('Norm of entire vector ',1pe8.2)
 76:       endif

 78:       comp = 0
 79:       call VecStrideNorm(x,comp,NORM_2,norm,ierr)
 80:       if (rank .eq. 0) then
 81:          write (6,200) norm
 82:  200     format ('Norm of subvector ',1pe8.2)
 83:       endif

 85:       comp = 1
 86:       call VecStrideNorm(x,comp,NORM_2,norm,ierr)
 87:       if (rank .eq. 0) then
 88:          write (6,300) norm
 89:  300     format ('Norm of subvector ',1pe8.2)
 90:       endif

 92:       call VecStrideNorm(x,comp,NORM_1,norm,ierr)
 93:       if (rank .eq. 0) then
 94:          write (6,400) norm
 95:  400     format ('Norm of subvector ',1pe8.2)
 96:       endif

 98:       call VecStrideNorm(x,comp,NORM_INFINITY,norm,ierr)
 99:       if (rank .eq. 0) then
100:          write (6,500) norm
101:  500     format ('Norm of subvector ',1pe8.2)
102:       endif

104: !
105: !     Free work space.  All PETSc objects should be destroyed when they
106: !     are no longer needed.

108:       call VecDestroy(x,ierr)
109:       call PetscFinalize(ierr)
110:       end