Actual source code: ex11.c
petsc-3.3-p7 2013-05-11
2: /* Program usage: mpiexec ex1 [-help] [all PETSc options] */
4: static char help[] = "Demonstrates VecStrideNorm().\n\n";
6: /*T
7: Concepts: vectors^norms of sub-vectors;
8: Processors: n
9: T*/
11: /*
12: Include "petscvec.h" so that we can use vectors. Note that this file
13: automatically includes:
14: petscsys.h - base PETSc routines petscis.h - index sets
15: petscviewer.h - viewers
16: */
18: #include <petscvec.h>
22: int main(int argc,char **argv)
23: {
24: Vec x; /* vectors */
25: PetscReal norm;
26: PetscInt n = 20;
28: PetscScalar one = 1.0;
30: PetscInitialize(&argc,&argv,(char*)0,help);
31: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
33: /*
34: Create a vector, specifying only its global dimension.
35: When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
36: the vector format (currently parallel,
37: shared, or sequential) is determined at runtime. Also, the parallel
38: partitioning of the vector is determined by PETSc at runtime.
40: Routines for creating particular vector types directly are:
41: VecCreateSeq() - uniprocessor vector
42: VecCreateMPI() - distributed vector, where the user can
43: determine the parallel partitioning
44: VecCreateShared() - parallel vector that uses shared memory
45: (available only on the SGI); otherwise,
46: is the same as VecCreateMPI()
48: With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
49: -vec_type mpi or -vec_type shared causes the
50: particular type of vector to be formed.
52: */
53: VecCreate(PETSC_COMM_WORLD,&x);
54: VecSetSizes(x,PETSC_DECIDE,n);
55: VecSetBlockSize(x,2);
56: VecSetFromOptions(x);
58: /*
59: Set the vectors to entries to a constant value.
60: */
61: VecSet(x,one);
63: VecNorm(x,NORM_2,&norm);
64: PetscPrintf(PETSC_COMM_WORLD,"Norm of entire vector %G\n",norm);
66: VecStrideNorm(x,0,NORM_2,&norm);
67: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %G\n",norm);
69: VecStrideNorm(x,1,NORM_2,&norm);
70: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %G\n",norm);
72: VecStrideNorm(x,1,NORM_1,&norm);
73: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %G\n",norm);
75: VecStrideNorm(x,1,NORM_INFINITY,&norm);
76: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %G\n",norm);
78: /*
79: Free work space. All PETSc objects should be destroyed when they
80: are no longer needed.
81: */
82: VecDestroy(&x);
83: PetscFinalize();
84: return 0;
85: }
86: