Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_ExecutionSpacesSlot.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_DETAILS_EXEUTIONSPACESSLOT_HPP
11 #define TPETRA_DETAILS_EXEUTIONSPACESSLOT_HPP
12 
13 #include <iostream>
14 #include <sstream>
15 #include <vector>
16 
17 #include "Teuchos_RCP.hpp"
20 #include <Kokkos_Core.hpp>
21 
22 namespace Tpetra {
23 namespace Details {
24 namespace Spaces {
25 
31 template <typename ExecSpace> class Slot {
32 public:
33  using execution_space = ExecSpace;
34 
39  Slot() {
40  for (int i = 0; i < static_cast<int>(Spaces::Priority::NUM_LEVELS); ++i) {
41  // retrieve an RCP from the global instance manager
42  instances_[i] = Spaces::space_instance<execution_space>(
43  static_cast<Spaces::Priority>(i));
44  }
45  }
46 
58  template <Spaces::Priority priority = Spaces::Priority::medium>
59  Teuchos::RCP<const execution_space> space_instance() const {
60  return instances_[static_cast<int>(priority)];
61  }
62 
75  Teuchos::RCP<const execution_space>
76  space_instance(const Spaces::Priority &priority) const {
77  switch (priority) {
78  case Spaces::Priority::high:
79  return space_instance<Spaces::Priority::high>();
80  case Spaces::Priority::medium:
81  return space_instance<Spaces::Priority::medium>();
82  case Spaces::Priority::low:
83  return space_instance<Spaces::Priority::low>();
84  default:
85  throw std::runtime_error("unexpected Tpetra Space priority");
86  }
87  }
88 
89 private:
94  Teuchos::RCP<const execution_space>
95  instances_[static_cast<int>(Spaces::Priority::NUM_LEVELS)];
96 }; // Slot
97 
98 } // namespace Spaces
99 } // namespace Details
100 } // namespace Tpetra
101 
102 #endif // TPETRA_DETAILS_EXEUTIONSPACESSLOT_HPP
Teuchos::RCP< const execution_space > space_instance() const
Get a specific execution space instance based on the given priority level.
Teuchos::RCP< const execution_space > space_instance(const Spaces::Priority &priority) const
Get a specific execution space instance based on the given priority level.
Slot()
Default constructor that creates instances for each possible space priority level.
Lazily acquires and stores Kokkos Execution Spaces.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra&#39;s behavior.