Actual source code: ex11f.F90
1: !
2: #include <petsc/finclude/petscvec.h>
3: program main
4: use petscvec
5: implicit none
7: Vec x
8: PetscReal norm
9: PetscBool flg
10: PetscMPIInt rank
11: PetscInt, parameter :: bs = 2 ! block size
12: PetscInt n, comp
13: PetscErrorCode ierr
14: PetscScalar, parameter :: one = 1.0
16: PetscCallA(PetscInitialize(ierr))
17: PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr))
19: n = 20
20: PetscCallA(PetscOptionsGetInt(PETSC_NULL_OPTIONS, PETSC_NULL_CHARACTER, '-n', n, flg, ierr))
22: !
23: ! Create a vector, specifying only its global dimension.
24: ! When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
25: ! the vector format (currently parallel,
26: ! shared, or sequential) is determined at runtime. Also, the parallel
27: ! partitioning of the vector is determined by PETSc at runtime.
29: PetscCallA(VecCreate(PETSC_COMM_WORLD, x, ierr))
30: PetscCallA(VecSetSizes(x, PETSC_DECIDE, n, ierr))
31: PetscCallA(VecSetBlockSize(x, bs, ierr))
32: PetscCallA(VecSetFromOptions(x, ierr))
34: !
35: ! Set the vectors to entries to a constant value.
36: !
37: PetscCallA(VecSet(x, one, ierr))
39: PetscCallA(VecNorm(x, NORM_2, norm, ierr))
40: if (rank == 0) then
41: write (6, 100) norm
42: 100 format('L_2 Norm of entire vector ', 1pe9.2)
43: end if
45: comp = 0
46: PetscCallA(VecStrideNorm(x, comp, NORM_2, norm, ierr))
47: if (rank == 0) then
48: write (6, 200) norm
49: 200 format('L_2 Norm of subvector 0', 1pe9.2)
50: end if
52: comp = 1
53: PetscCallA(VecStrideNorm(x, comp, NORM_2, norm, ierr))
54: if (rank == 0) then
55: write (6, 300) norm
56: 300 format('L_2 Norm of subvector 1', 1pe9.2)
57: end if
59: PetscCallA(VecStrideNorm(x, comp, NORM_1, norm, ierr))
60: if (rank == 0) then
61: write (6, 400) norm
62: 400 format('L_1 Norm of subvector 0', 1pe9.2)
63: end if
65: PetscCallA(VecStrideNorm(x, comp, NORM_INFINITY, norm, ierr))
66: if (rank == 0) then
67: write (6, 500) norm
68: 500 format('L_1 Norm of subvector 1', 1pe9.2)
69: end if
71: !
72: ! Free work space. All PETSc objects should be destroyed when they
73: ! are no longer needed.
75: PetscCallA(VecDestroy(x, ierr))
76: PetscCallA(PetscFinalize(ierr))
77: end
79: !/*TEST
80: !
81: ! test:
82: ! nsize: 2
83: !
84: !TEST*/