Actual source code: ex11.c

  2: /* Program usage:  mpirun 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:      petsc.h       - base PETSc routines   petscis.h     - index sets
 15:      petscsys.h    - system routines       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);

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

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

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

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

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

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

 76:   VecStrideNorm(x,1,NORM_INFINITY,&norm);
 77:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %G\n",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: