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
9: int main(int argc,char **argv)
10: {
12: PetscInt n = 5,idx;
13: PetscReal value;
14: Vec x;
15: PetscScalar one = 1.0;
17: PetscInitialize(&argc,&argv,(char*)0,help);
18: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
20: /* create vector */
21: VecCreate(PETSC_COMM_WORLD,&x);
22: VecSetSizes(x,PETSC_DECIDE,n);
23: VecSetFromOptions(x);
26: VecSet(x,one);
27: VecSetValue(x,0,0.0,INSERT_VALUES);
28: VecSetValue(x,n-1,2.0,INSERT_VALUES);
29: VecAssemblyBegin(x);
30: VecAssemblyEnd(x);
32: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
33: VecMax(x,&idx,&value);
34: PetscPrintf(PETSC_COMM_WORLD,"Maximum value %G index %D\n",value,idx);
35: VecMin(x,&idx,&value);
36: PetscPrintf(PETSC_COMM_WORLD,"Minimum value %G index %D\n",value,idx);
38: VecDestroy(x);
40: PetscFinalize();
41: return 0;
42: }
43: