Actual source code: ex11f.F

petsc-3.10.5 2019-03-28
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:  #include <petsc/finclude/petscvec.h>
 11:       use petscvec
 12:       implicit none

 14:       Vec               x
 15:       PetscReal         norm
 16:       PetscBool  flg
 17:       PetscMPIInt rank
 18:       PetscInt n,bs,comp
 19:       PetscErrorCode ierr
 20:       PetscScalar       one

 22:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 23:       if (ierr .ne. 0) then
 24:         print*,'Unable to initialize PETSc'
 25:         stop
 26:       endif
 27:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)

 29:       n   = 20
 30:       one = 1.0
 31:       call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,       &
 32:      &                        '-n',n,flg,ierr)

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

 53:       call VecCreate(PETSC_COMM_WORLD,x,ierr)
 54:       call VecSetSizes(x,PETSC_DECIDE,n,ierr)
 55:       bs = 2
 56:       call VecSetBlockSize(x,bs,ierr)
 57:       call VecSetFromOptions(x,ierr)

 59: !
 60: !     Set the vectors to entries to a constant value.
 61: !
 62:       call VecSet(x,one,ierr)

 64:       call VecNorm(x,NORM_2,norm,ierr)
 65:       if (rank .eq. 0) then
 66:          write (6,100) norm
 67:  100     format ('Norm of entire vector ',1pe9.2)
 68:       endif

 70:       comp = 0
 71:       call VecStrideNorm(x,comp,NORM_2,norm,ierr)
 72:       if (rank .eq. 0) then
 73:          write (6,200) norm
 74:  200     format ('Norm of subvector ',1pe9.2)
 75:       endif

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

 84:       call VecStrideNorm(x,comp,NORM_1,norm,ierr)
 85:       if (rank .eq. 0) then
 86:          write (6,400) norm
 87:  400     format ('Norm of subvector ',1pe9.2)
 88:       endif

 90:       call VecStrideNorm(x,comp,NORM_INFINITY,norm,ierr)
 91:       if (rank .eq. 0) then
 92:          write (6,500) norm
 93:  500     format ('Norm of subvector ',1pe9.2)
 94:       endif

 96: !
 97: !     Free work space.  All PETSc objects should be destroyed when they
 98: !     are no longer needed.

100:       call VecDestroy(x,ierr)
101:       call PetscFinalize(ierr)
102:       end


105: !/*TEST
106: !
107: !     test:
108: !       nsize: 2
109: !
110: !TEST*/