Actual source code: ex11.c

  1: /*$Id: ex11.c,v 1.20 2001/09/11 16:32:18 bsmith 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:   PetscReal   norm;
 25:   int         n = 20,ierr;
 26:   PetscScalar 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(), 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);

 54:   VecSetBlockSize(x,2);
 55:   VecSetFromOptions(x);

 57:   /*
 58:      Set the vectors to entries to a constant value.
 59:   */
 60:   VecSet(&one,x);

 62:   VecNorm(x,NORM_2,&norm);
 63:   PetscPrintf(PETSC_COMM_WORLD,"Norm of entire vector %gn",norm);

 65:   VecStrideNorm(x,0,NORM_2,&norm);
 66:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);

 68:   VecStrideNorm(x,1,NORM_2,&norm);
 69:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);

 71:   VecStrideNorm(x,1,NORM_1,&norm);
 72:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);

 74:   VecStrideNorm(x,1,NORM_INFINITY,&norm);
 75:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %gn",norm);

 77:   /* 
 78:      Free work space.  All PETSc objects should be destroyed when they
 79:      are no longer needed.
 80:   */
 81:   VecDestroy(x);
 82:   PetscFinalize();
 83:   return 0;
 84: }
 85: