Actual source code: ex11f.F90

  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:       PetscCallA(PetscInitialize(ierr))

 20:       PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr))

 22:       n   = 20
 23:       one = 1.0
 24:       PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr))

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

 45:       PetscCallA(VecCreate(PETSC_COMM_WORLD,x,ierr))
 46:       PetscCallA(VecSetSizes(x,PETSC_DECIDE,n,ierr))
 47:       bs = 2
 48:       PetscCallA(VecSetBlockSize(x,bs,ierr))
 49:       PetscCallA(VecSetFromOptions(x,ierr))

 51: !
 52: !     Set the vectors to entries to a constant value.
 53: !
 54:       PetscCallA(VecSet(x,one,ierr))

 56:       PetscCallA(VecNorm(x,NORM_2,norm,ierr))
 57:       if (rank .eq. 0) then
 58:          write (6,100) norm
 59:  100     format ('L_2 Norm of entire vector ',1pe9.2)
 60:       endif

 62:       comp = 0
 63:       PetscCallA(VecStrideNorm(x,comp,NORM_2,norm,ierr))
 64:       if (rank .eq. 0) then
 65:          write (6,200) norm
 66:  200     format ('L_2 Norm of subvector 0',1pe9.2)
 67:       endif

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

 76:       PetscCallA(VecStrideNorm(x,comp,NORM_1,norm,ierr))
 77:       if (rank .eq. 0) then
 78:          write (6,400) norm
 79:  400     format ('L_1 Norm of subvector 0',1pe9.2)
 80:       endif

 82:       PetscCallA(VecStrideNorm(x,comp,NORM_INFINITY,norm,ierr))
 83:       if (rank .eq. 0) then
 84:          write (6,500) norm
 85:  500     format ('L_1 Norm of subvector 1',1pe9.2)
 86:       endif

 88: !
 89: !     Free work space.  All PETSc objects should be destroyed when they
 90: !     are no longer needed.

 92:       PetscCallA(VecDestroy(x,ierr))
 93:       PetscCallA(PetscFinalize(ierr))
 94:       end

 96: !/*TEST
 97: !
 98: !     test:
 99: !       nsize: 2
100: !
101: !TEST*/