Actual source code: ex11f90.F90
1: !Concepts: vectors^norms of sub-vectors
2: !Processors: n
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 :: sone = 1.0
15: PetscBool :: flg
16: character(len=PETSC_MAX_PATH_LEN) :: outputString
17: PetscInt,parameter :: zero = 0, one = 1, two = 2
19: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
20: if (ierr /= 0) then
21: print*,'PetscInitialize failed'
22: stop
23: endif
25: call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
27: call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,"-n",n,flg,ierr);CHKERRA(ierr)
29: !Create a vector, specifying only its global dimension.
30: !When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
31: !the vector format (currently parallel,
32: !shared, or sequential) is determined at runtime. Also, the parallel
33: !partitioning of the vector is determined by PETSc at runtime.
35: !Routines for creating particular vector types directly are:
36: !VecCreateSeq() - uniprocessor vector
37: !VecCreateMPI() - distributed vector, where the user can
38: !determine the parallel partitioning
39: !VecCreateShared() - parallel vector that uses shared memory
40: !(available only on the SGI) otherwise,
41: !is the same as VecCreateMPI()
43: !With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
44: !-vec_type mpi or -vec_type shared causes the
45: !particular type of vector to be formed.
47: call VecCreate(PETSC_COMM_WORLD,x,ierr);CHKERRA(ierr)
49: call VecSetSizes(x,PETSC_DECIDE,n,ierr);CHKERRA(ierr)
50: !
51: call VecSetBlockSize(x,two,ierr);CHKERRA(ierr)
52: call VecSetFromOptions(x,ierr);CHKERRA(ierr)
54: !Set the vectors to entries to a constant value.
56: call VecSet(x,sone,ierr);CHKERRA(ierr)
58: call VecNorm(x,NORM_2,norm,ierr);CHKERRA(ierr)
59: write(outputString,*) norm
60: call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
62: call VecNorm(x,NORM_1,norm,ierr);CHKERRA(ierr)
63: write(outputString,*) norm
64: call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
66: call VecNorm(x,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
67: write(outputString,*) norm
68: call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
70: call VecStrideNorm(x,zero,NORM_2,norm,ierr);CHKERRA(ierr)
71: write(outputString,*) norm
72: call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
74: call VecStrideNorm(x,zero,NORM_1,norm,ierr);CHKERRA(ierr)
75: write(outputString,*) norm
76: call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
78: call VecStrideNorm(x,zero,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
79: write(outputString,*) norm
80: call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
82: call VecStrideNorm(x,one,NORM_2,norm,ierr);CHKERRA(ierr)
83: write(outputString,*) norm
84: call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
86: call VecStrideNorm(x,one,NORM_1,norm,ierr);CHKERRA(ierr)
87: write(outputString,*) norm
88: call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
90: call VecStrideNorm(x,one,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
91: write(outputString,*) norm
92: call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
94: !Free work space. All PETSc objects should be destroyed when they
95: !are no longer needed.
96: call VecDestroy(x,ierr);CHKERRA(ierr)
97: call PetscFinalize(ierr);CHKERRA(ierr)
99: end program
101: !/*TEST
102: !
103: ! test:
104: ! nsize: 2
105: !
106: !TEST*/