Actual source code: ex11f.F

  1: !
  2: !
  3: !

  5:       program main
  6: #include <petsc/finclude/petscvec.h>
  7:       use petscvec
  8:       implicit none

 10:       Vec               x
 11:       PetscReal         norm
 12:       PetscBool  flg
 13:       PetscMPIInt rank
 14:       PetscInt n,bs,comp
 15:       PetscErrorCode ierr
 16:       PetscScalar       one

 18:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 19:       if (ierr .ne. 0) then
 20:         print*,'Unable to initialize PETSc'
 21:         stop
 22:       endif
 23:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)

 25:       n   = 20
 26:       one = 1.0
 27:       call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,       &
 28:      &                        '-n',n,flg,ierr)

 30: !
 31: !     Create a vector, specifying only its global dimension.
 32: !     When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
 33: !     the vector format (currently parallel,
 34: !     shared, or sequential) is determined at runtime.  Also, the parallel
 35: !     partitioning of the vector is determined by PETSc at runtime.
 36: !
 37: !     Routines for creating particular vector types directly are:
 38: !        VecCreateSeq() - uniprocessor vector
 39: !        VecCreateMPI() - distributed vector, where the user can
 40: !                         determine the parallel partitioning
 41: !        VecCreateShared() - parallel vector that uses shared memory
 42: !                            (available only on the SGI); otherwise,
 43: !                            is the same as VecCreateMPI()
 44: !
 45: !     With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
 46: !     -vec_type mpi or -vec_type shared causes the
 47: !     particular type of vector to be formed.

 49:       call VecCreate(PETSC_COMM_WORLD,x,ierr)
 50:       call VecSetSizes(x,PETSC_DECIDE,n,ierr)
 51:       bs = 2
 52:       call VecSetBlockSize(x,bs,ierr)
 53:       call VecSetFromOptions(x,ierr)

 55: !
 56: !     Set the vectors to entries to a constant value.
 57: !
 58:       call VecSet(x,one,ierr)

 60:       call VecNorm(x,NORM_2,norm,ierr)
 61:       if (rank .eq. 0) then
 62:          write (6,100) norm
 63:  100     format ('L_2 Norm of entire vector ',1pe9.2)
 64:       endif

 66:       comp = 0
 67:       call VecStrideNorm(x,comp,NORM_2,norm,ierr)
 68:       if (rank .eq. 0) then
 69:          write (6,200) norm
 70:  200     format ('L_2 Norm of subvector 0',1pe9.2)
 71:       endif

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

 80:       call VecStrideNorm(x,comp,NORM_1,norm,ierr)
 81:       if (rank .eq. 0) then
 82:          write (6,400) norm
 83:  400     format ('L_1 Norm of subvector 0',1pe9.2)
 84:       endif

 86:       call VecStrideNorm(x,comp,NORM_INFINITY,norm,ierr)
 87:       if (rank .eq. 0) then
 88:          write (6,500) norm
 89:  500     format ('L_1 Norm of subvector 1',1pe9.2)
 90:       endif

 92: !
 93: !     Free work space.  All PETSc objects should be destroyed when they
 94: !     are no longer needed.

 96:       call VecDestroy(x,ierr)
 97:       call PetscFinalize(ierr)
 98:       end

100: !/*TEST
101: !
102: !     test:
103: !       nsize: 2
104: !
105: !TEST*/