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: #undef __FUNCT__
 23: int main(int argc,char **argv)
 24: {
 25:   Vec         x;               /* vectors */
 26:   PetscReal   norm;
 27:   int         n = 20,ierr;
 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);

 56:   VecSetBlockSize(x,2);
 57:   VecSetFromOptions(x);

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

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

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

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

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

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

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