Actual source code: ex10.c

  1: /*$Id: ex10.c,v 1.18 2001/03/23 23:21:37 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: int main(int argc,char **argv)
 22: {
 23:   Vec      x,y;
 24:   int      n = 20,ierr,i,row;
 25:   Scalar   value;

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

 30:   /* 
 31:      Create a vector, specifying only its global dimension.
 32:      When using VecCreate() and VecSetFromOptions(), 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() and VecSetFromOptions() the option -vec_type mpi or -vec_type shared causes the 
 45:      particular type of vector to be formed.

 47:   */
 48:   VecCreate(PETSC_COMM_WORLD,PETSC_DECIDE,n,&x);
 49:   VecSetFromOptions(x);

 51:   /*
 52:      Duplicate some work vector (of the same format and
 53:      partitioning as the initial vector).
 54:   */
 55:   VecDuplicate(x,&y);

 57:   PetscObjectPublish((PetscObject)x);

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

 61:     /*
 62:        Set the vectors to entries to a constant value.
 63:     */
 64:     value = 1;
 65:     row   = i % n;
 66:     VecSetValues(x,1,&row,&value,ADD_VALUES);
 67:     VecAssemblyBegin(x);
 68:     VecAssemblyEnd(x);


 71:     PetscSleep(5);
 72:   }


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