Actual source code: ex11f90.F90
1: program main
2: #include <petsc/finclude/petscvec.h>
3: use petscvec
4: implicit none
6: Vec :: x
7: PetscReal :: norm
8: PetscMPIInt :: rank
9: PetscInt,parameter :: n = 20
10: PetscErrorCode :: ierr
11: PetscScalar,parameter :: sone = 1.0
12: PetscBool :: flg
13: character(len=PETSC_MAX_PATH_LEN) :: outputString
14: PetscInt,parameter :: zero = 0, one = 1, two = 2
16: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
17: if (ierr /= 0) then
18: print*,'PetscInitialize failed'
19: stop
20: endif
22: call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
24: call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,"-n",n,flg,ierr);CHKERRA(ierr)
26: !Create a vector, specifying only its global dimension.
27: !When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
28: !the vector format (currently parallel,
29: !shared, or sequential) is determined at runtime. Also, the parallel
30: !partitioning of the vector is determined by PETSc at runtime.
32: !Routines for creating particular vector types directly are:
33: !VecCreateSeq() - uniprocessor vector
34: !VecCreateMPI() - distributed vector, where the user can
35: !determine the parallel partitioning
36: !VecCreateShared() - parallel vector that uses shared memory
37: !(available only on the SGI) otherwise,
38: !is the same as VecCreateMPI()
40: !With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
41: !-vec_type mpi or -vec_type shared causes the
42: !particular type of vector to be formed.
44: call VecCreate(PETSC_COMM_WORLD,x,ierr);CHKERRA(ierr)
46: call VecSetSizes(x,PETSC_DECIDE,n,ierr);CHKERRA(ierr)
47: !
48: call VecSetBlockSize(x,two,ierr);CHKERRA(ierr)
49: call VecSetFromOptions(x,ierr);CHKERRA(ierr)
51: !Set the vectors to entries to a constant value.
53: call VecSet(x,sone,ierr);CHKERRA(ierr)
55: call VecNorm(x,NORM_2,norm,ierr);CHKERRA(ierr)
56: write(outputString,*) norm
57: call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
59: call VecNorm(x,NORM_1,norm,ierr);CHKERRA(ierr)
60: write(outputString,*) norm
61: call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
63: call VecNorm(x,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
64: write(outputString,*) norm
65: call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of entire vector: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
67: call VecStrideNorm(x,zero,NORM_2,norm,ierr);CHKERRA(ierr)
68: write(outputString,*) norm
69: call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
71: call VecStrideNorm(x,zero,NORM_1,norm,ierr);CHKERRA(ierr)
72: write(outputString,*) norm
73: call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
75: call VecStrideNorm(x,zero,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
76: write(outputString,*) norm
77: call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of sub-vector 0: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
79: call VecStrideNorm(x,one,NORM_2,norm,ierr);CHKERRA(ierr)
80: write(outputString,*) norm
81: call PetscPrintf(PETSC_COMM_WORLD,"L_2 Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
83: call VecStrideNorm(x,one,NORM_1,norm,ierr);CHKERRA(ierr)
84: write(outputString,*) norm
85: call PetscPrintf(PETSC_COMM_WORLD,"L_1 Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
87: call VecStrideNorm(x,one,NORM_INFINITY,norm,ierr);CHKERRA(ierr)
88: write(outputString,*) norm
89: call PetscPrintf(PETSC_COMM_WORLD,"L_inf Norm of sub-vector 1: "//trim(outputString)//"\n",ierr);CHKERRA(ierr)
91: !Free work space. All PETSc objects should be destroyed when they
92: !are no longer needed.
93: call VecDestroy(x,ierr);CHKERRA(ierr)
94: call PetscFinalize(ierr);CHKERRA(ierr)
96: end program
98: !/*TEST
99: !
100: ! test:
101: ! nsize: 2
102: !
103: !TEST*/