diff --git a/docs/source/API/core/builtinreducers/MinLoc.rst b/docs/source/API/core/builtinreducers/MinLoc.rst index 24434e25d..fc54245b7 100644 --- a/docs/source/API/core/builtinreducers/MinLoc.rst +++ b/docs/source/API/core/builtinreducers/MinLoc.rst @@ -108,3 +108,44 @@ Additional Information * Requires: ``Index`` has ``operator =`` defined. ``Kokkos::reduction_identity::min()`` is a valid expression. * In order to use MinLoc with a custom type of either ``Scalar`` or ``Index``, a template specialization of ``Kokkos::reduction_identity`` must be defined. See `Built-In Reducers with Custom Scalar Types <../../../ProgrammingGuide/Custom-Reductions-Built-In-Reducers-with-Custom-Scalar-Types.html>`_ for details + +Example +------- + +.. code-block:: cpp + + #include + struct Idx3D_t { + int value[3]; + int& operator[](int i) { return value[i]; } + const int& operator[](int i) const { return value[i]; } + }; + template <> + struct Kokkos::reduction_identity { + static constexpr Idx3D_t min() { return {0, 0, 0}; } + }; + int main(int argc, char* argv[]) { + Kokkos::initialize(argc, argv); + { + Kokkos::View a("A", 5, 5, 5); + Kokkos::deep_copy(a, 10); + a(2, 3, 1) = 5; + using MinLoc_t = Kokkos::MinLoc; + using MinLocVal_t = typename MinLoc_t::value_type; + MinLocVal_t result; + Kokkos::parallel_reduce( + Kokkos::MDRangePolicy>({0, 0, 0}, {5, 5, 5}), + KOKKOS_LAMBDA(int i, int j, int k, MinLocVal_t& val) { + if (a(i, j, k) < val.val) { + val.val = a(i, j, k); + val.loc[0] = i; + val.loc[1] = j; + val.loc[2] = k; + } + }, + MinLoc_t(result)); + printf("%lf %i %i %i\n", result.val, result.loc[0], result.loc[1], + result.loc[2]); + } + Kokkos::finalize(); + }