https://mooseframework.inl.gov
KokkosReducerBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "KokkosHeader.h"
13 #include "KokkosDatum.h"
14 #include "KokkosDispatcher.h"
15 #include "KokkosFESystem.h"
16 
17 #include "MooseObject.h"
18 
19 class FEProblemBase;
20 
21 namespace Moose::Kokkos
22 {
23 
24 class ReducerBase : public MeshHolder, public AssemblyHolder, public FESystemHolder
25 {
26 public:
27  ReducerBase(const MooseObject * object);
28 
32  ReducerBase(const ReducerBase & reducer);
33 
37  struct ReducerLoop
38  {
39  };
40 
45  template <typename Derived>
47  KOKKOS_FUNCTION void reduce(Datum & /* datum */, Real * /* result */) const
48  {
49  ::Kokkos::abort("Default reduce() should never be called. Make sure you properly redefined "
50  "this method in your class without typos.");
51  }
52  template <typename Derived>
53  KOKKOS_FUNCTION void join(Real * /* result */, const Real * /* source */) const
54  {
55  ::Kokkos::abort("Default join() should never be called. Make sure you properly redefined this "
56  "method in your class without typos.");
57  }
58  template <typename Derived>
59  KOKKOS_FUNCTION void init(Real * /* result */) const
60  {
61  ::Kokkos::abort("Default init() should never be called. Make sure you properly redefined this "
62  "method in your class without typos.");
63  }
65 
70  template <typename Derived>
71  static auto defaultReduce()
72  {
73  return &ReducerBase::reduce<Derived>;
74  }
76 
77 protected:
81  virtual void computeReducer();
85  virtual ThreadID numReducerThreads() const = 0;
89  void allocateReductionBuffer(const unsigned int size)
90  {
91  ::Kokkos::realloc(_reduction_buffer, size);
92  }
93 
101  std::unique_ptr<DispatcherBase> _reducer_dispatcher;
105  ::Kokkos::View<Real *, ::Kokkos::HostSpace> _reduction_buffer;
106 };
107 
108 } // namespace Moose::Kokkos
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object...
Definition: KokkosDatum.h:245
ReducerBase(const MooseObject *object)
virtual ThreadID numReducerThreads() const =0
Get the number of threads.
KOKKOS_FUNCTION void join(Real *, const Real *) const
void allocateReductionBuffer(const unsigned int size)
Allocate reduction buffer.
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition: KokkosMesh.h:629
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
KOKKOS_FUNCTION void init(Real *) const
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
const MooseObject * _reducer_object
MOOSE object.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
The Kokkos interface that holds the host reference of the Kokkos assembly and copies it to device dur...
virtual void computeReducer()
Dispatch reduction operation.
KOKKOS_FUNCTION void reduce(Datum &, Real *) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
static auto defaultReduce()
Function used to check if users have overriden the hook method.
::Kokkos::View< Real *, ::Kokkos::HostSpace > _reduction_buffer
Reduction buffer.
std::unique_ptr< DispatcherBase > _reducer_dispatcher
Kokkos functor dispatcher.