MueLu  Version of the Day
MueLu_IndexManager_kokkos_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Ray Tuminaro (rstumin@sandia.gov)
41 // Luc Berger-Vergiat (lberge@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_INDEXMANAGER_KOKKOS_DECL_HPP
47 #define MUELU_INDEXMANAGER_KOKKOS_DECL_HPP
48 
49 #include "MueLu_ConfigDefs.hpp"
50 #include "MueLu_Types.hpp"
51 
52 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
53 #include <KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
54 #include <Kokkos_View.hpp>
55 
56 #include "Teuchos_OrdinalTraits.hpp"
57 
58 #include <Xpetra_Map_fwd.hpp>
59 #include <Xpetra_Vector_fwd.hpp>
60 #include <Xpetra_VectorFactory_fwd.hpp>
61 
62 #include "MueLu_BaseClass.hpp"
64 
65 /*****************************************************************************
66 
67 ****************************************************************************/
68 
69 namespace MueLu {
70 
82  template <class LocalOrdinal, class GlobalOrdinal, class Node>
83  class IndexManager_kokkos : public BaseClass {
84 #undef MUELU_INDEXMANAGER_KOKKOS_SHORT
86 
87  public:
88  using execution_space = typename Node::execution_space;
89  using memory_space = typename Node::memory_space;
90  using device_type = Kokkos::Device<execution_space, memory_space>;
91  using intTupleView = typename Kokkos::View<int[3], device_type>;
92  using LOTupleView = typename Kokkos::View<LO[3], device_type>;
93 
94  private:
95 
96  const int meshLayout = UNCOUPLED;
97  int myRank = -1;
98  int numDimensions;
99  int interpolationOrder_;
100  intTupleView coarseRate;
101  intTupleView endRate;
102 
103  LO lNumFineNodes;
104  LO lNumFineNodes10;
105  LOTupleView lFineNodesPerDir;
106 
107  LO numCoarseNodes;
108  LO numCoarseNodes10;
109  LOTupleView coarseNodesPerDir;
110 
111  public:
112 
114  IndexManager_kokkos() = default;
115 
117  IndexManager_kokkos(const int NumDimensions,
118  const int interpolationOrder,
119  const int MyRank,
120  const ArrayView<const LO> LFineNodesPerDir,
121  const ArrayView<const int> CoarseRate);
122 
123  virtual ~IndexManager_kokkos() {}
124 
126  void setupIM(const int NumDimensions,
127  const int interpolationOrder,
128  const ArrayView<const int> coarseRate,
129  const ArrayView<const LO> LFineNodesPerDir);
130 
133  void computeMeshParameters();
134 
135  int getNumDimensions() const {return numDimensions;}
136 
137  int getInterpolationOrder() const {return interpolationOrder_;}
138 
139  LO getNumLocalFineNodes() const {return lNumFineNodes;}
140 
141  LO getNumCoarseNodes() const {return numCoarseNodes;}
142 
143  KOKKOS_INLINE_FUNCTION
144  intTupleView getCoarseningRates() const {return coarseRate;}
145 
146  KOKKOS_INLINE_FUNCTION
147  intTupleView getCoarseningEndRates() const {return endRate;}
148 
149  KOKKOS_INLINE_FUNCTION
150  LOTupleView getLocalFineNodesPerDir() const {return lFineNodesPerDir;}
151 
152  KOKKOS_INLINE_FUNCTION
153  LOTupleView getCoarseNodesPerDir() const {return coarseNodesPerDir;}
154 
155  Array<LO> getCoarseNodesPerDirArray() const;
156 
157  KOKKOS_INLINE_FUNCTION
158  void getFineLID2FineTuple(const LO myLID, LO (&tuple)[3]) const {
159  LO tmp;
160  tuple[2] = myLID / (lFineNodesPerDir(1)*lFineNodesPerDir(0));
161  tmp = myLID % (lFineNodesPerDir(1)*lFineNodesPerDir(0));
162  tuple[1] = tmp / lFineNodesPerDir(0);
163  tuple[0] = tmp % lFineNodesPerDir(0);
164  } // getFineNodeLocalTuple
165 
166  KOKKOS_INLINE_FUNCTION
167  void getFineTuple2FineLID(const LO tuple[3], LO& myLID) const {
168  myLID = tuple[2]*lNumFineNodes10 + tuple[1]*lFineNodesPerDir[0] + tuple[0];
169  } // getFineNodeLID
170 
171  KOKKOS_INLINE_FUNCTION
172  void getCoarseLID2CoarseTuple(const LO myLID, LO (&tuple)[3]) const {
173  LO tmp;
174  tuple[2] = myLID / numCoarseNodes10;
175  tmp = myLID % numCoarseNodes10;
176  tuple[1] = tmp / coarseNodesPerDir[0];
177  tuple[0] = tmp % coarseNodesPerDir[0];
178  } // getCoarseNodeLocalTuple
179 
180  KOKKOS_INLINE_FUNCTION
181  void getCoarseTuple2CoarseLID(const LO i, const LO j, const LO k, LO& myLID) const {
182  myLID = k*numCoarseNodes10 + j*coarseNodesPerDir[0] + i;
183  } // getCoarseNodeLID
184 
185  };
186 
187 } //namespace MueLu
188 
189 #define MUELU_INDEXMANAGER_KOKKOS_SHORT
190 #endif // HAVE_MUELU_KOKKOS_REFACTOR
191 #endif // MUELU_INDEXMANAGER_KOKKOS_DECL_HPP
Namespace for MueLu classes and methods.