Actual source code: ex10.c

  1: /*$Id: ex10.c,v 1.19 2001/08/07 03:02:34 balay Exp $*/

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

  5: static char help[] = "Demonstrates the AMS Memory Snooper viewing.nn";

  7: /*T
  8:    Concepts: vectors^basic routines;
  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,y;
 26:   int      n = 20,ierr,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);


 76:     PetscSleep(5);
 77:   }


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