Actual source code: ex11f.F

  1: !
  2: !
  3: ! Program usage:  mpirun ex1 [-help] [all PETSc options]
  4: !
  5: !
  6: !/*T
  7: !   Concepts: vectors^norms of sub-vectors;
  8: !   Processors: n
  9: !T*/

 11:       program main
 12:       implicit none

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

 28:       Vec               x
 29:       PetscReal         norm
 30:       PetscTruth flg
 31:       PetscMPIInt rank
 32:       PetscInt n,bs,comp
 33:       PetscErrorCode ierr
 34:       PetscScalar       one

 36:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 37:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)

 39:       n   = 20
 40:       one = 1.d0
 41:       call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-n',n,flg,ierr)

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

 62:       call VecCreate(PETSC_COMM_WORLD,x,ierr)
 63:       call VecSetSizes(x,PETSC_DECIDE,n,ierr)
 64:       call VecSetFromOptions(x,ierr)

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

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

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

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

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

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

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

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