Interface Documentation
Version: invalid
reduction_wrapper.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #if !defined(__FLECSI_PRIVATE__)
19 #error Do not include this file directly!
20 #endif
21 
22 #include "flecsi/run/backend.hh"
23 #include "flecsi/util/demangle.hh"
25 #include <flecsi/flog.hh>
26 
27 #include <type_traits>
28 
29 namespace flecsi {
30 
31 inline log::devel_tag reduction_wrapper_tag("reduction_wrapper");
32 
33 namespace exec {
34 
35 namespace detail {
36 template<class>
37 void register_reduction();
38 }
39 
40 // NB: The real initialization is in the callback.
41 template<class R>
42 inline MPI_Op reduction_op = (run::context::instance().register_init(
43  detail::register_reduction<R>),
44  MPI_Op());
45 
50 template<typename TYPE>
51 void
52 detail::register_reduction() {
53  using value_type = typename TYPE::LHS;
54  // MPI does not have support for mixed-type reductions
55  static_assert(std::is_same_v<value_type, typename TYPE::RHS>,
56  "type mismatch: LHS != RHS");
57 
58  {
59  log::devel_guard guard(reduction_wrapper_tag);
60  flog(info) << "Executing reduction wrapper callback for "
61  << util::type<TYPE>() << std::endl;
62  } // scope
63 
64  // Create the operator and register it with the runtime
65  MPI_Op_create(
66  [](void * in, void * inout, int * len, MPI_Datatype *) {
67  const auto lhs = static_cast<value_type *>(inout);
68  const auto rhs = static_cast<const value_type *>(in);
69 
70  for(size_t i{0}; i < *len; ++i) {
71  TYPE::template apply<true>(lhs[i], rhs[i]);
72  } // for
73  },
74  true,
75  &reduction_op<TYPE>);
76 }
77 
78 } // namespace exec
79 } // namespace flecsi
#define flog(severity)
Definition: flog.hh:136
void register_reduction()
Definition: reduction_wrapper.hh:54
Definition: control.hh:31