A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://kokkos.github.io/kokkos-core-wiki/API/core/parallel-dispatch/parallel_reduce.html below:

parallel_reduce - Kokkos documentation

parallel_reduce

Header File: <Kokkos_Core.hpp>

Usage
Kokkos::parallel_reduce(name, policy, functor, reducer...);
Kokkos::parallel_reduce(name, policy, functor, result...);
Kokkos::parallel_reduce(name, policy, functor);
Kokkos::parallel_reduce(policy, functor, reducer...);
Kokkos::parallel_reduce(policy, functor, result...);
Kokkos::parallel_reduce(policy, functor);

Dispatches parallel work defined by functor according to the ExecutionPolicy and performs a reduction of the contributions provided by workers as defined by the execution policy. The optional label name is used by profiling and debugging tools. The reduction type is either a sum, is defined by the reducer or is deduced from an optional join operator on the functor. The reduction result is stored in result, or through the reducer handle. It is also provided to the functor.final() function if such a function exists. Multiple reducers can be used in a single parallel_reduce and thus, it is possible to compute the min and the max values in a single parallel_reduce.

Interface
template <class ExecPolicy, class FunctorType>
Kokkos::parallel_reduce(const std::string& name,
                        const ExecPolicy& policy,
                        const FunctorType& functor);
template <class ExecPolicy, class FunctorType>
Kokkos::parallel_reduce(const ExecPolicy& policy,
                        const FunctorType& functor);
template <class ExecPolicy, class FunctorType, class... ReducerArgument>
Kokkos::parallel_reduce(const std::string& name,
                        const ExecPolicy& policy,
                        const FunctorType& functor,
                        const ReducerArgument&... reducer);
template <class ExecPolicy, class FunctorType, class... ReducerArgument>
Kokkos::parallel_reduce(const ExecPolicy& policy,
                        const FunctorType& functor,
                        const ReducerArgument&... reducer);
template <class ExecPolicy, class FunctorType, class... ReducerArgumentNonConst>
Kokkos::parallel_reduce(const std::string& name,
                        const ExecPolicy& policy,
                        const FunctorType& functor,
                        ReducerArgumentNonConst&... reducer);
template <class ExecPolicy, class FunctorType, class... ReducerArgumentNonConst>
Kokkos::parallel_reduce(const ExecPolicy& policy,
                        const FunctorType& functor,
                        ReducerArgumentNonConst&... reducer);
Parameters: Requirements: Semantics Examples

Further examples are provided in the Custom Reductions and ExecutionPolicy documentation.

#include <Kokkos_Core.hpp>
#include <cstdio>

int main(int argc, char* argv[]) {
    Kokkos::initialize(argc, argv);

    int N = atoi(argv[1]);
    double result;
    Kokkos::parallel_reduce("Loop1", N, KOKKOS_LAMBDA (const int& i, double& lsum) {
        lsum += 1.0*i;
    }, result);

    printf("Result: %i %lf\n", N, result);
    Kokkos::finalize();
}
#include <Kokkos_Core.hpp>
#include <cstdio>

int main(int argc, char* argv[]) {
    Kokkos::initialize(argc, argv);

    int N = atoi(argv[1]);
    double sum, min;
    Kokkos::parallel_reduce("Loop1", N, KOKKOS_LAMBDA (const int& i, double& lsum, double& lmin) {
        lsum += 1.0*i;
        lmin = lmin < 1.0*i ? lmin : 1.0*i;
    }, sum, Kokkos::Min<double>(min));

    printf("Result: %i %lf %lf\n", N, sum, min);
    Kokkos::finalize();
}
#include <Kokkos_Core.hpp>
#include <cstdio>

struct TagMax {};
struct TagMin {};

struct Foo {
    KOKKOS_INLINE_FUNCTION
    void operator() (const TagMax, const Kokkos::TeamPolicy<>::member_type& team, double& lmax) const {
        if (team.league_rank() % 17 + team.team_rank() % 13 > lmax)
            lmax = team.league_rank() % 17 + team.team_rank() % 13;
    }
    KOKKOS_INLINE_FUNCTION
    void operator() (const TagMin, const Kokkos::TeamPolicy<>::member_type& team, double& lmin) const {
        if (team.league_rank() % 17 + team.team_rank() % 13 < lmin)
            lmin = team.league_rank() % 17 + team.team_rank() % 13;
    }
};

int main(int argc, char* argv[]) {
    Kokkos::initialize(argc, argv);

    int N = atoi(argv[1]);

    Foo foo;
    double max, min;
    Kokkos::parallel_reduce(Kokkos::TeamPolicy<TagMax>(N,Kokkos::AUTO), foo, Kokkos::Max<double>(max));
    Kokkos::parallel_reduce("Loop2", Kokkos::TeamPolicy<TagMin>(N,Kokkos::AUTO), foo, Kokkos::Min<double>(min));
    Kokkos::fence();

    printf("Result: %lf %lf\n", min, max);

    Kokkos::finalize();
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4