Actual source code: ex11f.F

  1: !
  2: ! "$Id: ex11f.F,v 1.9 2001/01/15 21:45:20 bsmith Exp $";
  3: !
  4: !
  5: ! Program usage:  mpirun ex1 [-help] [all PETSc options]
  6: !
  7: !
  8: !/*T
  9: !   Concepts: vectors^norms of sub-vectors;
 10: !   Processors: n
 11: !T*/

 13:       program main
 14:       implicit none

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

 30:       Vec      x
 31:       double precision  norm
 32:       integer           n,ierr,flg,rank
 33:       Scalar            one

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

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

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

 59:       call VecCreate(PETSC_COMM_WORLD,PETSC_DECIDE,n,x,ierr)
 60:       call VecSetFromOptions(x,ierr)

 62: !
 63: !     Set the vectors to entries to a constant value.
 64: !
 65:       call VecSet(one,x,ierr)

 67:       call VecNorm(x,NORM_2,norm,ierr)
 68:       if (rank .eq. 0) then
 69:          write (6,100) norm
 70:  100     format ('Norm of entire vector ',1pe8.2)
 71:       endif

 73:       call VecSetBlockSize(x,2,ierr)
 74:       call VecStrideNorm(x,0,NORM_2,norm,ierr)
 75:       if (rank .eq. 0) then
 76:          write (6,200) norm
 77:  200     format ('Norm of subvector ',1pe8.2)
 78:       endif


 81:       call VecStrideNorm(x,1,NORM_2,norm,ierr)
 82:       if (rank .eq. 0) then
 83:          write (6,300) norm
 84:  300     format ('Norm of subvector ',1pe8.2)
 85:       endif

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

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

 99: !
100: !     Free work space.  All PETSc objects should be destroyed when they
101: !     are no longer needed.

103:       call VecDestroy(x,ierr)
104:       call PetscFinalize(ierr)
105:       end
106: