Actual source code: ex21.c

  1: /*$Id: ex21.c,v 1.11 2001/04/10 19:35:02 bsmith Exp $*/

  3: static char help[] = "Tests VecMax() with index.n
  4:   -n <length> : vector lengthnn";

  6: #include "petscvec.h"
  7: #include "petscsys.h"

  9: int main(int argc,char **argv)
 10: {
 11:   int           n = 5,ierr,idx;
 12:   Scalar        value;
 13:   Vec           x;
 14:   PetscRandom   rand;

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

 19:   /* create vector */
 20:   VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,n,&x);

 22:   PetscRandomCreate(PETSC_COMM_WORLD,RANDOM_DEFAULT_REAL,&rand);
 23:   VecSetRandom(rand,x);
 24:   PetscRandomDestroy(rand);

 26:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 28:   VecMax(x,&idx,&value);
 29:   PetscPrintf(PETSC_COMM_WORLD,"Maximum value %g index %dn",value,idx);
 30:   VecMin(x,&idx,&value);
 31:   PetscPrintf(PETSC_COMM_WORLD,"Minimum value %g index %dn",value,idx);

 33:   VecDestroy(x);

 35:   PetscFinalize();
 36:   return 0;
 37: }
 38: