Actual source code: ex10.c

      2: /* Program usage:  mpirun ex1 [-help] [all PETSc options] */

      4: static char help[] = "Demonstrates the AMS Memory Snooper viewing.\n\n";

      6: /*T
      7:    Concepts: vectors^basic routines;
      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,y;
     25:   PetscInt       n = 20,i,row;
     27:   PetscScalar    value;

     29:   PetscInitialize(&argc,&argv,(char*)0,help);
     30:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);

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

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

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

     51:   */
     52:   VecCreate(PETSC_COMM_WORLD,&x);
     53:   VecSetSizes(x,PETSC_DECIDE,n);
     54:   VecSetFromOptions(x);

     56:   /*
     57:      Duplicate some work vector (of the same format and
     58:      partitioning as the initial vector).
     59:   */
     60:   VecDuplicate(x,&y);

     62:   PetscObjectPublish((PetscObject)x);

     64:   for (i=0; i<1000; i++) {

     66:     /*
     67:        Set the vectors to entries to a constant value.
     68:     */
     69:     value = 1;
     70:     row   = i % n;
     71:     VecSetValues(x,1,&row,&value,ADD_VALUES);
     72:     VecAssemblyBegin(x);
     73:     VecAssemblyEnd(x);
     74:   }

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