Actual source code: ex11.c
1: /*$Id: ex11.c,v 1.17 2001/03/23 23:21:37 balay Exp $*/
3: /* Program usage: mpirun ex1 [-help] [all PETSc options] */
5: static char help[] = "Demonstrates VecStrideNorm().nn";
7: /*T
8: Concepts: vectors^norms of sub-vectors;
9: Processors: n
10: T*/
12: /*
13: Include "petscvec.h" so that we can use vectors. Note that this file
14: automatically includes:
15: petsc.h - base PETSc routines petscis.h - index sets
16: petscsys.h - system routines petscviewer.h - viewers
17: */
19: #include petscvec.h
21: int main(int argc,char **argv)
22: {
23: Vec x; /* vectors */
24: double norm;
25: int n = 20,ierr;
26: Scalar one = 1.0;
28: PetscInitialize(&argc,&argv,(char*)0,help);
29: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
31: /*
32: Create a vector, specifying only its global dimension.
33: When using VecCreate() and VecSetFromOptions(), the vector format (currently parallel,
34: shared, or sequential) is determined at runtime. Also, the parallel
35: partitioning of the vector is determined by PETSc at runtime.
37: Routines for creating particular vector types directly are:
38: VecCreateSeq() - uniprocessor vector
39: VecCreateMPI() - distributed vector, where the user can
40: determine the parallel partitioning
41: VecCreateShared() - parallel vector that uses shared memory
42: (available only on the SGI); otherwise,
43: is the same as VecCreateMPI()
45: With VecCreate() and VecSetFromOptions() the option -vec_type mpi or -vec_type shared causes the
46: particular type of vector to be formed.
48: */
49: VecCreate(PETSC_COMM_WORLD,PETSC_DECIDE,n,&x);
50: VecSetFromOptions(x);
52: /*
53: Set the vectors to entries to a constant value.
54: */
55: VecSet(&one,x);
57: VecNorm(x,NORM_2,&norm);
58: PetscPrintf(PETSC_COMM_WORLD,"Norm of entire vector %gn",norm);
60: VecSetBlockSize(x,2);
61: VecStrideNorm(x,0,NORM_2,&norm);
62: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);
64: VecStrideNorm(x,1,NORM_2,&norm);
65: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);
67: VecStrideNorm(x,1,NORM_1,&norm);
68: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);
70: VecStrideNorm(x,1,NORM_INFINITY,&norm);
71: PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);
73: /*
74: Free work space. All PETSc objects should be destroyed when they
75: are no longer needed.
76: */
77: VecDestroy(x);
78: PetscFinalize();
79: return 0;
80: }
81: