Actual source code: ex11f90.F90

petsc-3.11.2 2019-05-18
Report Typos and Errors
  1:    !Concepts: vectors^norms of sub-vectors
  2:    !Processors: n
  3: 
  4:   program main
  5:  #include <petsc/finclude/petscvec.h>
  6:   use petscvec
  7:   implicit none

  9:   Vec        ::   x
 10:   PetscReal  :: norm
 11:   PetscMPIInt :: rank
 12:   PetscInt,parameter :: n = 20
 13:   PetscErrorCode :: ierr
 14:   PetscScalar,parameter :: one = 1.0
 15:   PetscBool :: flg
 16:   character(len=256) :: outputString
 17: 

 19: 
 20:   call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 21:   if (ierr /= 0) then
 22:    print*,'PetscInitialize failed'
 23:    stop
 24:   endif
 25: 
 26:   call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
 27: 
 28:   call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,"-n",n,flg,ierr);CHKERRA(ierr)


 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.

 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()

 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);CHKERRA(ierr)
 50: 
 51:   call VecSetSizes(x,PETSC_DECIDE,n,ierr);CHKERRA(ierr)
 52:   !
 53:   call VecSetBlockSize(x,2,ierr);CHKERRA(ierr)
 54:   call VecSetFromOptions(x,ierr);CHKERRA(ierr)


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

 61:   call VecNorm(x,NORM_2,norm,ierr);CHKERRA(ierr)
 62:   write(outputString,*) norm
 63:   call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
 64: 
 65:   call VecNorm(x,NORM_1,norm,ierr);CHKERRA(ierr)
 66:   write(outputString,*) norm
 67:   call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
 68: 
 69:   call VecNorm(x,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
 70:   write(outputString,*) norm
 71:   call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
 72: 
 73:   call VecStrideNorm(x,0,NORM_2,norm,ierr);CHKERRA(ierr)
 74:   write(outputString,*) norm
 75:   call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)

 77:   call VecStrideNorm(x,0,NORM_1,norm,ierr);CHKERRA(ierr)
 78:   write(outputString,*) norm
 79:   call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)

 81:   call VecStrideNorm(x,0,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
 82:   write(outputString,*) norm
 83:   call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)

 85:   call VecStrideNorm(x,1,NORM_2,norm,ierr);CHKERRA(ierr)
 86:   write(outputString,*) norm
 87:   call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)

 89:   call VecStrideNorm(x,1,NORM_1,norm,ierr);CHKERRA(ierr)
 90:   write(outputString,*) norm
 91:   call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)

 93:   call VecStrideNorm(x,1,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
 94:   write(outputString,*) norm
 95:   call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
 96: 
 97: 
 98:      !Free work space.  All PETSc objects should be destroyed when they
 99:      !are no longer needed.
100:   call VecDestroy(x,ierr);CHKERRA(ierr)
101:   call PetscFinalize(ierr);CHKERRA(ierr)
102: 
103: end program