Actual source code: ex21.c
1: static char help[] = "Tests VecMax() with index and VecSetStdBasis()\n\
2: -n <length> : vector length\n\n";
4: #include <petscvec.h>
6: int main(int argc, char **argv)
7: {
8: PetscInt n = 6, idx;
9: PetscReal value, value2;
10: Vec x;
12: PetscFunctionBeginUser;
13: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
14: PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));
16: /* create vector */
17: PetscCall(VecCreate(PETSC_COMM_WORLD, &x));
18: PetscCall(VecSetSizes(x, PETSC_DECIDE, n));
19: PetscCall(VecSetFromOptions(x));
20: PetscCall(VecSetStdBasis(x, n / 2));
21: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "STD %" PetscInt_FMT "\n", n / 2));
22: PetscCall(VecView(x, PETSC_VIEWER_STDOUT_WORLD));
24: PetscCall(VecSet(x, 2.0));
25: PetscCall(VecSetValue(x, 0, 0.0, INSERT_VALUES));
26: PetscCall(VecSetValue(x, 1, -1.0, INSERT_VALUES));
27: PetscCall(VecSetValue(x, n - 2, 0.0, INSERT_VALUES));
28: PetscCall(VecSetValue(x, n - 1, -1.0, INSERT_VALUES));
29: PetscCall(VecAssemblyBegin(x));
30: PetscCall(VecAssemblyEnd(x));
31: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Vector for min/max\n"));
32: PetscCall(VecView(x, PETSC_VIEWER_STDOUT_WORLD));
33: PetscCall(VecMax(x, &idx, &value));
34: PetscCall(VecMax(x, NULL, &value2));
35: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Maximum value %g index %" PetscInt_FMT " (no index %g)\n", (double)value, idx, (double)value2));
36: PetscCall(VecMin(x, &idx, &value));
37: PetscCall(VecMin(x, NULL, &value2));
38: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Minimum value %g index %" PetscInt_FMT " (no index %g)\n", (double)value, idx, (double)value2));
40: PetscCall(VecDestroy(&x));
42: PetscCall(PetscFinalize());
43: return 0;
44: }
46: /*TEST
48: testset:
49: diff_args: -j
50: filter: grep -v type | grep -v " MPI process" | grep -v Process
51: output_file: output/ex21_1.out
53: test:
54: suffix: 1
55: args: -vec_type {{seq mpi}}
57: test:
58: requires: cuda
59: suffix: 1_cuda
60: args: -vec_type {{cuda mpicuda}}
62: test:
63: requires: kokkos_kernels
64: suffix: 1_kokkos
65: args: -vec_type {{kokkos mpikokkos}}
67: test:
68: requires: hip
69: suffix: 1_hip
70: args: -vec_type {{hip mpihip}}
72: testset:
73: diff_args: -j
74: filter: grep -v type
75: output_file: output/ex21_2.out
76: nsize: 2
78: test:
79: suffix: 2
81: test:
82: requires: cuda
83: suffix: 2_cuda
84: args: -vec_type cuda
86: test:
87: requires: kokkos_kernels
88: suffix: 2_kokkos
89: args: -vec_type kokkos
91: test:
92: requires: hip
93: suffix: 2_hip
94: args: -vec_type hip
96: TEST*/