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: int main(int argc,char **argv)
22: {
23: Vec x,y;
24: int n = 20,ierr,i,row;
25: PetscScalar 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(), VecSetSizes() and VecSetFromOptions(),
33: the vector format (currently parallel,
34: shared, or sequential) is determined at runtime. Also, the parallel
35: partitioning of the vector is determined by PETSc at runtime.
37: Routines for creating particular vector types directly are:
38: VecCreateSeq() - uniprocessor vector
39: VecCreateMPI() - distributed vector, where the user can
40: determine the parallel partitioning
41: VecCreateShared() - parallel vector that uses shared memory
42: (available only on the SGI); otherwise,
43: is the same as VecCreateMPI()
45: With VecCreate(), VecSetSizes() and VecSetFromOptions() the option
46: -vec_type mpi or -vec_type shared causes the
47: particular type of vector to be formed.
49: */
50: VecCreate(PETSC_COMM_WORLD,&x);
51: VecSetSizes(x,PETSC_DECIDE,n);
52: VecSetFromOptions(x);
54: /*
55: Duplicate some work vector (of the same format and
56: partitioning as the initial vector).
57: */
58: VecDuplicate(x,&y);
60: PetscObjectPublish((PetscObject)x);
62: for (i=0; i<1000; i++) {
64: /*
65: Set the vectors to entries to a constant value.
66: */
67: value = 1;
68: row = i % n;
69: VecSetValues(x,1,&row,&value,ADD_VALUES);
70: VecAssemblyBegin(x);
71: VecAssemblyEnd(x);
74: PetscSleep(5);
75: }
78: /*
79: Free work space. All PETSc objects should be destroyed when they
80: are no longer needed.
81: */
82: VecDestroy(x);
83: VecDestroy(y);
84: PetscFinalize();
85: return 0;
86: }
87: