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);
34: VecMax(x,&idx,&value);
35: PetscPrintf(PETSC_COMM_WORLD,"Maximum value %G index %D\n",value,idx);
36: VecMin(x,&idx,&value);
37: PetscPrintf(PETSC_COMM_WORLD,"Minimum value %G index %D\n",value,idx);
39: VecDestroy(x);
41: PetscFinalize();
42: return 0;
43: }
44: