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>

  7: int main(int argc, char **argv)
  8: {
  9:   PetscInt    n = 5, idx;
 10:   PetscReal   value, value2;
 11:   Vec         x;
 12:   PetscScalar one = 1.0;

 14:   PetscFunctionBeginUser;
 15:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
 16:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));

 18:   /* create vector */
 19:   PetscCall(VecCreate(PETSC_COMM_WORLD, &x));
 20:   PetscCall(VecSetSizes(x, PETSC_DECIDE, n));
 21:   PetscCall(VecSetFromOptions(x));

 23:   PetscCall(VecSet(x, one));
 24:   PetscCall(VecSetValue(x, 0, 0.0, INSERT_VALUES));
 25:   PetscCall(VecSetValue(x, n - 1, 2.0, INSERT_VALUES));
 26:   PetscCall(VecAssemblyBegin(x));
 27:   PetscCall(VecAssemblyEnd(x));
 28:   PetscCall(VecView(x, PETSC_VIEWER_STDOUT_WORLD));
 29:   PetscCall(VecMax(x, &idx, &value));
 30:   PetscCall(VecMax(x, NULL, &value2));
 31:   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Maximum value %g index %" PetscInt_FMT " (no index %g)\n", (double)value, idx, (double)value2));
 32:   PetscCall(VecMin(x, &idx, &value));
 33:   PetscCall(VecMin(x, NULL, &value2));
 34:   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Minimum value %g index %" PetscInt_FMT " (no index %g)\n", (double)value, idx, (double)value2));

 36:   PetscCall(VecDestroy(&x));

 38:   PetscCall(PetscFinalize());
 39:   return 0;
 40: }

 42: /*TEST

 44:    testset:
 45:       diff_args: -j
 46:       filter: grep -v type | grep -v " MPI process" | grep -v Process
 47:       output_file: output/ex21_1.out

 49:       test:
 50:          suffix: 1
 51:          args: -vec_type {{seq mpi}}

 53:       test:
 54:          requires: cuda
 55:          suffix: 1_cuda
 56:          args: -vec_type {{cuda mpicuda}}

 58:       test:
 59:          requires: kokkos_kernels
 60:          suffix: 1_kokkos
 61:          args: -vec_type {{kokkos mpikokkos}}

 63:       test:
 64:          requires: hip
 65:          suffix: 1_hip
 66:          args: -vec_type {{hip mpihip}}

 68:    testset:
 69:       diff_args: -j
 70:       filter: grep -v type
 71:       output_file: output/ex21_2.out
 72:       nsize: 2

 74:       test:
 75:          suffix: 2

 77:       test:
 78:          requires: cuda
 79:          suffix: 2_cuda
 80:          args: -vec_type cuda

 82:       test:
 83:          requires: kokkos_kernels
 84:          suffix: 2_kokkos
 85:          args: -vec_type kokkos

 87:       test:
 88:          requires: hip
 89:          suffix: 2_hip
 90:          args: -vec_type hip

 92: TEST*/