MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_Aggregates_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// Andrey Prokopenko (aprokop@sandia.gov)
41// Ray Tuminaro (rstumin@sandia.gov)
42//
43// ***********************************************************************
44//
45// @HEADER
46#ifndef MUELU_AGGREGATES_DECL_HPP
47#define MUELU_AGGREGATES_DECL_HPP
48
50
51#include <Kokkos_StaticCrsGraph.hpp>
52#include <Tpetra_KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
53
55
56#include <Xpetra_Map_fwd.hpp>
57#include <Xpetra_Vector_fwd.hpp>
58#include <Xpetra_VectorFactory_fwd.hpp>
59#include <Xpetra_MultiVector_fwd.hpp>
60
61#include "MueLu_BaseClass.hpp"
62
63#include "MueLu_LWGraph_kokkos.hpp"
64#include "MueLu_Graph.hpp"
65#include "MueLu_GraphBase.hpp"
66#include "MueLu_IndexManager.hpp"
67#include "MueLu_IndexManager_kokkos.hpp"
68
69#define MUELU_UNAGGREGATED -1 /* indicates that a node is unassigned to */
70 /* any aggregate. */
71
72#define MUELU_UNASSIGNED -1 /* indicates a vertex is not yet claimed */
73 /* by a processor during aggregation. */
74 /* Note, it is possible at */
75 /* this stage that some processors may have*/
76 /* claimed their copy of a vertex for one */
77 /* of their aggregates. However, some */
78 /* arbitration still needs to occur. */
79 /* The corresponding procWinner[]'s remain */
80 /* as MUELU_UNASSIGNED until */
81 /* ArbitrateAndCommunicate() is */
82 /* invoked to arbitrate. */
83
84/*****************************************************************************
85
86****************************************************************************/
87
88namespace MueLu {
89
105 template <class LocalOrdinal, class GlobalOrdinal, class Node>
107
108 template <class LocalOrdinal, class GlobalOrdinal, class DeviceType>
109 class Aggregates<LocalOrdinal, GlobalOrdinal, Tpetra::KokkosCompat::KokkosDeviceWrapperNode<DeviceType> > : public BaseClass {
110 public:
113 using execution_space = typename DeviceType::execution_space;
114 using node_type = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<DeviceType>;
115 using device_type = DeviceType;
116 using range_type = Kokkos::RangePolicy<local_ordinal_type, execution_space>;
117 using LO_view = Kokkos::View<local_ordinal_type*, device_type>;
118
119 using aggregates_sizes_type = Kokkos::View<LocalOrdinal*, device_type>;
120
121 private:
122 // For compatibility
124#undef MUELU_AGGREGATES_SHORT
126
127 public:
128
129 // Defining types that require the short names included above
130 using local_graph_type = typename LWGraph_kokkos::local_graph_type;
131 using colors_view_type = Kokkos::View<typename local_graph_type::entries_type::data_type,
132 typename local_graph_type::device_type::memory_space>;
133
141 Aggregates(const GraphBase & graph);
142
151
157 Aggregates(const RCP<const Map>& map);
158
162 virtual ~Aggregates() { }
163
165
166
170 RCP<IndexManager_kokkos>& GetIndexManagerKokkos() { return geoDataKokkos_; }
171
175 void SetIndexManagerKokkos(RCP<IndexManager_kokkos> & geoDataKokkos) { geoDataKokkos_ = geoDataKokkos; }
176
180 RCP<IndexManager>& GetIndexManager() { return geoData_; }
181
185 void SetIndexManager(RCP<IndexManager> & geoData) { geoData_ = geoData; }
186
191
195 void SetGraphColors(colors_view_type graphColors) { graphColors_ = graphColors; }
196
200
203 void SetGraphNumColors(const LO graphNumColors) { graphNumColors_ = graphNumColors; }
204
206
211 void SetNumAggregates(LO nAggregates) { numAggregates_ = nAggregates; }
212
217 void SetNumGlobalAggregates(GO nGlobalAggregates) { numGlobalAggregates_ = nGlobalAggregates; }
218
220 KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const {
221 return numAggregates_;
222 }
223
225 KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool& flag) {
227 }
228
233 KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const {
235 }
236
241 RCP<LOMultiVector>& GetVertex2AggIdNonConst() { return vertex2AggId_; }
242
247 RCP<LOVector>& GetProcWinnerNonConst() { return procWinner_; }
252 const RCP<LOMultiVector>& GetVertex2AggId() const { return vertex2AggId_; }
253
258 const RCP<LOVector>& GetProcWinner() const { return procWinner_; }
259
261 inline bool IsRoot(LO i) const { return isRoot_[i]; }
262
267 inline void SetIsRoot(LO i, bool value = true) { isRoot_[i] = value; }
268
269 const RCP<const Map> GetMap() const;
270
280 typename aggregates_sizes_type::const_type ComputeAggregateSizes(bool forceRecompute = false) const;
281
291 Teuchos::ArrayRCP<LocalOrdinal> ComputeAggregateSizesArrayRCP(bool forceRecompute = false) const;
292
293 local_graph_type GetGraph() const;
294
299 void ComputeNodesInAggregate(LO_view & aggPtr, LO_view & aggNodes, LO_view & unaggregated) const;
300
302 // If # of global aggregates is unknown, this method does coummunication and internally record the value
303 GO GetNumGlobalAggregatesComputeIfNeeded();
304
306
307
309 std::string description() const;
310
312 //using MueLu::Describable::describe; // overloading, not hiding
313 void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const;
314
315 private:
318
323 RCP<LOMultiVector> vertex2AggId_;
324
329 RCP<LOVector> procWinner_;
330
334 RCP<IndexManager_kokkos> geoDataKokkos_;
335
339 RCP<IndexManager> geoData_;
340
345
350
352 Teuchos::ArrayRCP<bool> isRoot_;
353
356
358 mutable
360
365 mutable
366 typename aggregates_sizes_type::HostMirror aggregateSizesHost_;
367
369 mutable
371 };
372
373} //namespace MueLu
374
375#define MUELU_AGGREGATES_SHORT
376#endif // MUELU_AGGREGATES_DECL_HPP
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultGlobalOrdinal GlobalOrdinal
void SetIndexManager(RCP< IndexManager > &geoData)
Set the index manager used by various aggregation algorithms. This has to be done by the aggregation ...
KOKKOS_INLINE_FUNCTION bool AggregatesCrossProcessors() const
Return false if and only if no aggregates include DOFs from other processes.
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
KOKKOS_INLINE_FUNCTION void AggregatesCrossProcessors(const bool &flag)
Record whether aggregates include DOFs from other processes.
RCP< IndexManager > & GetIndexManager()
Get the index manager used by various aggregation algorithms. This has to be done by the aggregation ...
bool aggregatesIncludeGhosts_
Set to false iff aggregates do not include any DOFs belong to other processes.
Kokkos::View< typename local_graph_type::entries_type::data_type, typename local_graph_type::device_type::memory_space > colors_view_type
void SetGraphColors(colors_view_type graphColors)
Set a distance 2 coloring of the underlying graph. The coloring is computed and set during Phase1 of ...
void SetGraphNumColors(const LO graphNumColors)
Set the number of colors needed by the distance 2 coloring.
RCP< LOMultiVector > & GetVertex2AggIdNonConst()
Returns a nonconstant vector that maps local node IDs to local aggregates IDs.
Teuchos::ArrayRCP< bool > isRoot_
An ArrayRCP of booleans specifying if a local entry is an aggregate root.
void SetIndexManagerKokkos(RCP< IndexManager_kokkos > &geoDataKokkos)
Set the index manager used by structured aggregation algorithms. This has to be done by the aggregati...
RCP< IndexManager_kokkos > & GetIndexManagerKokkos()
Get the index manager used by structured aggregation algorithms. This has to be done by the aggregati...
RCP< LOVector > & GetProcWinnerNonConst()
Returns nonconstant vector that maps local node IDs to owning processor IDs.
colors_view_type & GetGraphColors()
Get a distance 2 coloring of the underlying graph. The coloring is computed and set during Phase1 of ...
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
void SetNumGlobalAggregates(GO nGlobalAggregates)
Set number of global aggregates on current processor.
bool IsRoot(LO i) const
Returns true if node with given local node id is marked to be a root node.
Container class for aggregation information.
Base class for MueLu classes.
Lightweight MueLu representation of a compressed row storage graph.
Namespace for MueLu classes and methods.