Actual source code: ex11.c

petsc-3.9.4 2018-09-11
Report Typos and Errors

  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>

 18: int main(int argc,char **argv)
 19: {
 20:   Vec            x;               /* vectors */
 21:   PetscReal      norm;
 22:   PetscInt       n = 20;
 24:   PetscScalar    one = 1.0;

 26:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 27:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);

 29:   /*
 30:      Create a vector, specifying only its global dimension.
 31:      When using VecCreate(), VecSetSizes() and VecSetFromOptions(),
 32:      the vector format (currently parallel,
 33:      shared, or sequential) is determined at runtime.  Also, the parallel
 34:      partitioning of the vector is determined by PETSc at runtime.

 36:      Routines for creating particular vector types directly are:
 37:         VecCreateSeq() - uniprocessor vector
 38:         VecCreateMPI() - distributed vector, where the user can
 39:                          determine the parallel partitioning
 40:         VecCreateShared() - parallel vector that uses shared memory
 41:                             (available only on the SGI); otherwise,
 42:                             is the same as VecCreateMPI()

 44:      With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
 45:      -vec_type mpi or -vec_type shared causes the
 46:      particular type of vector to be formed.

 48:   */
 49:   VecCreate(PETSC_COMM_WORLD,&x);
 50:   VecSetSizes(x,PETSC_DECIDE,n);
 51:   VecSetBlockSize(x,2);
 52:   VecSetFromOptions(x);

 54:   /*
 55:      Set the vectors to entries to a constant value.
 56:   */
 57:   VecSet(x,one);

 59:   VecNorm(x,NORM_2,&norm);
 60:   PetscPrintf(PETSC_COMM_WORLD,"Norm of entire vector %g\n",(double)norm);

 62:   VecStrideNorm(x,0,NORM_2,&norm);
 63:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %g\n",(double)norm);

 65:   VecStrideNorm(x,1,NORM_2,&norm);
 66:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %g\n",(double)norm);

 68:   VecStrideNorm(x,1,NORM_1,&norm);
 69:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %g\n",(double)norm);

 71:   VecStrideNorm(x,1,NORM_INFINITY,&norm);
 72:   PetscPrintf(PETSC_COMM_WORLD,"Norm of sub-vector %g\n",(double)norm);

 74:   /*
 75:      Free work space.  All PETSc objects should be destroyed when they
 76:      are no longer needed.
 77:   */
 78:   VecDestroy(&x);
 79:   PetscFinalize();
 80:   return ierr;
 81: }

 83: /*TEST

 85:      test:
 86:        nsize: 2

 88: TEST*/