https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
19class FEProblemBase;
20
21namespace Moose::Kokkos
22{
23
24class ReducerBase : public MeshHolder, public AssemblyHolder, public FESystemHolder
25{
26public:
27 ReducerBase(const MooseObject * object);
28
32 ReducerBase(const ReducerBase & reducer);
33
38 {
39 };
40
46 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
77protected:
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
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
The Kokkos interface that holds the host reference of the Kokkos assembly and copies it to device dur...
The Kokkos object that holds thread-private data in the parallel operations of any Kokkos object.
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition KokkosMesh.h:630
const MooseObject * _reducer_object
MOOSE object.
KOKKOS_FUNCTION void reduce(Datum &, Real *) const
Default methods to prevent compile errors even when these methods were not defined in the derived cla...
KOKKOS_FUNCTION void init(Real *) const
std::unique_ptr< DispatcherBase > _reducer_dispatcher
Kokkos functor dispatcher.
ReducerBase(const MooseObject *object)
void allocateReductionBuffer(const unsigned int size)
Allocate reduction buffer.
virtual void computeReducer()
Dispatch reduction operation.
KOKKOS_FUNCTION void join(Real *, const Real *) const
ReducerBase(const ReducerBase &reducer)
Copy constructor for parallel dispatch.
static auto defaultReduce()
Function used to check if users have overriden the hook method.
::Kokkos::View< Real *, ::Kokkos::HostSpace > _reduction_buffer
Reduction buffer.
virtual ThreadID numReducerThreads() const =0
Get the number of threads.
MOOSE_KOKKOS_INDEX_TYPE ThreadID