Actual source code: ex21.c

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

 5:  #include petscvec.h
 6:  #include petscsys.h

 10: int main(int argc,char **argv)
 11: {
 13:   PetscInt       n = 5,idx;
 14:   PetscReal      value;
 15:   Vec            x;
 16:   PetscScalar    one = 1.0;

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

 21:   /* create vector */
 22:   VecCreate(PETSC_COMM_WORLD,&x);
 23:   VecSetSizes(x,PETSC_DECIDE,n);
 24:   VecSetFromOptions(x);


 27:   VecSet(x,one);
 28:   VecSetValue(x,0,0.0,INSERT_VALUES);
 29:   VecSetValue(x,n-1,2.0,INSERT_VALUES);
 30:   VecAssemblyBegin(x);
 31:   VecAssemblyEnd(x);

 33:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 35:   VecMax(x,&idx,&value);
 36:   PetscPrintf(PETSC_COMM_WORLD,"Maximum value %g index %D\n",value,idx);
 37:   VecMin(x,&idx,&value);
 38:   PetscPrintf(PETSC_COMM_WORLD,"Minimum value %g index %D\n",value,idx);

 40:   VecDestroy(x);

 42:   PetscFinalize();
 43:   return 0;
 44: }
 45: