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