Ginkgo  Generated from pipelines/1556235455 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
polymorphic_object.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_DISTRIBUTED_POLYMORPHIC_OBJECT_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_POLYMORPHIC_OBJECT_HPP_
7 
8 
9 #include <memory>
10 #include <type_traits>
11 
12 #include <ginkgo/config.hpp>
13 
14 
15 #if GINKGO_BUILD_MPI
16 
17 
18 #include <ginkgo/core/base/polymorphic_object.hpp>
19 #include <ginkgo/core/distributed/base.hpp>
20 
21 
22 namespace gko {
23 namespace experimental {
24 
25 
51 template <typename ConcreteObject, typename PolymorphicBase = PolymorphicObject>
53  : public EnableAbstractPolymorphicObject<ConcreteObject, PolymorphicBase> {
54 protected:
56  ConcreteObject, PolymorphicBase>::EnableAbstractPolymorphicObject;
57 
58  std::unique_ptr<PolymorphicObject> create_default_impl(
59  std::shared_ptr<const Executor> exec) const override
60  {
61  return std::unique_ptr<ConcreteObject>{
62  new ConcreteObject(exec, self()->get_communicator())};
63  }
64 
65  PolymorphicObject* copy_from_impl(const PolymorphicObject* other) override
66  {
67  as<ConvertibleTo<ConcreteObject>>(other)->convert_to(self());
68  return this;
69  }
70 
71  PolymorphicObject* copy_from_impl(
72  std::unique_ptr<PolymorphicObject> other) override
73  {
74  as<ConvertibleTo<ConcreteObject>>(other.get())->move_to(self());
75  return this;
76  }
77 
78  PolymorphicObject* move_from_impl(PolymorphicObject* other) override
79  {
80  as<ConvertibleTo<ConcreteObject>>(other)->move_to(self());
81  return this;
82  }
83 
84  PolymorphicObject* move_from_impl(
85  std::unique_ptr<PolymorphicObject> other) override
86  {
87  as<ConvertibleTo<ConcreteObject>>(other.get())->move_to(self());
88  return this;
89  }
90 
91  PolymorphicObject* clear_impl() override
92  {
93  *self() =
94  ConcreteObject{self()->get_executor(), self()->get_communicator()};
95  return this;
96  }
97 
98 private:
99  GKO_ENABLE_SELF(ConcreteObject);
100 };
101 
102 
103 } // namespace experimental
104 } // namespace gko
105 
106 
107 #endif // GINKGO_BUILD_MPI
108 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_POLYMORPHIC_OBJECT_HPP_
gko::experimental::EnableDistributedPolymorphicObject
This mixin does the same as EnablePolymorphicObject, but for concrete types that are derived from dis...
Definition: polymorphic_object.hpp:52
gko::PolymorphicObject
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition: polymorphic_object.hpp:43
gko::EnableAbstractPolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:345
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20