Actual source code: ex11f.F
petsc-3.4.5 2014-06-29
1: !
2: !
3: !
4: !/*T
5: ! Concepts: vectors^norms of sub-vectors;
6: ! Processors: n
7: !T*/
9: program main
10: implicit none
12: !
13: ! The following include statements are required for Fortran programs
14: ! that use PETSc vectors:
15: ! petscsys.h - base PETSc routines
16: ! petscvec.h - vectors
17: ! Additional include statements may be needed if using additional
18: ! PETSc routines in a Fortran program, e.g.,
19: ! petscviewer.h - viewers
20: ! petscis.h - index sets
21: !
22: #include <finclude/petscsys.h>
23: #include <finclude/petscvec.h>
24: !
26: Vec x
27: PetscReal norm
28: PetscBool flg
29: PetscMPIInt rank
30: PetscInt n,bs,comp
31: PetscErrorCode ierr
32: PetscScalar one
34: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
35: call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
37: n = 20
38: one = 1.d0
39: call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-n',n,flg,ierr)
41: !
42: ! Create a vector, specifying only its global dimension.
43: ! When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
44: ! the vector format (currently parallel,
45: ! shared, or sequential) is determined at runtime. Also, the parallel
46: ! partitioning of the vector is determined by PETSc at runtime.
47: !
48: ! Routines for creating particular vector types directly are:
49: ! VecCreateSeq() - uniprocessor vector
50: ! VecCreateMPI() - distributed vector, where the user can
51: ! determine the parallel partitioning
52: ! VecCreateShared() - parallel vector that uses shared memory
53: ! (available only on the SGI); otherwise,
54: ! is the same as VecCreateMPI()
55: !
56: ! With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
57: ! -vec_type mpi or -vec_type shared causes the
58: ! particular type of vector to be formed.
60: call VecCreate(PETSC_COMM_WORLD,x,ierr)
61: call VecSetSizes(x,PETSC_DECIDE,n,ierr)
62: bs = 2
63: call VecSetBlockSize(x,bs,ierr)
64: call VecSetFromOptions(x,ierr)
66: !
67: ! Set the vectors to entries to a constant value.
68: !
69: call VecSet(x,one,ierr)
71: call VecNorm(x,NORM_2,norm,ierr)
72: if (rank .eq. 0) then
73: write (6,100) norm
74: 100 format ('Norm of entire vector ',1pe8.2)
75: endif
77: comp = 0
78: call VecStrideNorm(x,comp,NORM_2,norm,ierr)
79: if (rank .eq. 0) then
80: write (6,200) norm
81: 200 format ('Norm of subvector ',1pe8.2)
82: endif
84: comp = 1
85: call VecStrideNorm(x,comp,NORM_2,norm,ierr)
86: if (rank .eq. 0) then
87: write (6,300) norm
88: 300 format ('Norm of subvector ',1pe8.2)
89: endif
91: call VecStrideNorm(x,comp,NORM_1,norm,ierr)
92: if (rank .eq. 0) then
93: write (6,400) norm
94: 400 format ('Norm of subvector ',1pe8.2)
95: endif
97: call VecStrideNorm(x,comp,NORM_INFINITY,norm,ierr)
98: if (rank .eq. 0) then
99: write (6,500) norm
100: 500 format ('Norm of subvector ',1pe8.2)
101: endif
103: !
104: ! Free work space. All PETSc objects should be destroyed when they
105: ! are no longer needed.
107: call VecDestroy(x,ierr)
108: call PetscFinalize(ierr)
109: end