Actual source code: ex21.c

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

  4: #include <petscvec.h>

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

 13:   PetscFunctionBeginUser;
 14:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 15:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));

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

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

 35:   PetscCall(VecDestroy(&x));

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

 41: /*TEST

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

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

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

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

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

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

 73:       test:
 74:          suffix: 2

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

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

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

 91: TEST*/