MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_PreserveDirichletAggregationAlgorithm_def.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// MueLu: A package for multigrid based preconditioning
4//
5// Copyright 2012 NTESS and the MueLu contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef MUELU_PRESERVEDIRICHLETAGGREGATIONALGORITHM_DEF_HPP_
11#define MUELU_PRESERVEDIRICHLETAGGREGATIONALGORITHM_DEF_HPP_
12
13#include <Teuchos_Comm.hpp>
14#include <Teuchos_CommHelpers.hpp>
15
16#include <Xpetra_Vector.hpp>
17
19
20#include "MueLu_LWGraph.hpp"
21#include "MueLu_Aggregates.hpp"
22#include "MueLu_Exceptions.hpp"
23#include "MueLu_Monitor.hpp"
24
25namespace MueLu {
26
27template <class LocalOrdinal, class GlobalOrdinal, class Node>
29 Monitor m(*this, "BuildAggregatesNonKokkos");
30
31 bool preserve = params.get<bool>("aggregation: preserve Dirichlet points");
32
33 const LO numRows = graph.GetNodeNumVertices();
34 const int myRank = graph.GetComm()->getRank();
35
36 ArrayRCP<LO> vertex2AggId = aggregates.GetVertex2AggId()->getDataNonConst(0);
37 ArrayRCP<LO> procWinner = aggregates.GetProcWinner()->getDataNonConst(0);
38
39 LO numLocalAggregates = aggregates.GetNumAggregates();
40
41 for (LO i = 0; i < numRows; i++)
42 if (aggStat[i] == BOUNDARY) {
43 aggStat[i] = IGNORED;
44 numNonAggregatedNodes--;
45
46 if (preserve) {
47 aggregates.SetIsRoot(i);
48
49 vertex2AggId[i] = numLocalAggregates++;
50 procWinner[i] = myRank;
51 }
52 }
53
54 // update aggregate object
55 aggregates.SetNumAggregates(numLocalAggregates);
56}
57
58template <class LocalOrdinal, class GlobalOrdinal, class Node>
60 BuildAggregates(Teuchos::ParameterList const& params,
61 LWGraph_kokkos const& graph,
62 Aggregates& aggregates,
64 LO& numNonAggregatedNodes) const {
65 using device_type = typename LWGraph_kokkos::device_type;
66 using execution_space = typename LWGraph_kokkos::execution_space;
67
68 Monitor m(*this, "BuildAggregates");
69 using local_ordinal_type = typename LWGraph_kokkos::local_ordinal_type;
70
71 // Extract parameters and data from:
72 // 1) the parameter list
73 const bool preserve = params.get<bool>("aggregation: preserve Dirichlet points");
74
75 // 2) the amalgamated graph
76 const LO numNodes = graph.GetNodeNumVertices();
77 const int myRank = graph.GetComm()->getRank();
78
79 // 3) the aggregates
80 auto vertex2AggId = aggregates.GetVertex2AggId()->getLocalViewDevice(Tpetra::Access::ReadWrite);
81 auto procWinner = aggregates.GetProcWinner()->getLocalViewDevice(Tpetra::Access::ReadWrite);
82
83 // A view is needed to count on the fly the current number of local aggregates
84 Kokkos::View<LO, device_type> aggCount("aggCount");
85 if (preserve) {
86 Kokkos::deep_copy(aggCount, aggregates.GetNumAggregates());
87 }
88 Kokkos::parallel_for(
89 "MueLu - PreserveDirichlet: tagging ignored nodes",
90 Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numNodes),
91 KOKKOS_LAMBDA(const local_ordinal_type nodeIdx) {
92 if (aggStat(nodeIdx) == BOUNDARY) {
93 aggStat(nodeIdx) = IGNORED;
94 const LO aggIdx = Kokkos::atomic_fetch_add(&aggCount(), 1);
95
96 if (preserve) {
97 // aggregates.SetIsRoot(nodeIdx);
98
99 vertex2AggId(nodeIdx, 0) = aggIdx;
100 procWinner(nodeIdx, 0) = myRank;
101 }
102 }
103 });
104 typename Kokkos::View<LO, device_type>::host_mirror_type aggCount_h = Kokkos::create_mirror_view(aggCount);
105 Kokkos::deep_copy(aggCount_h, aggCount);
106 // In this phase the number of new aggregates is the same
107 // as the number of newly aggregated nodes.
108 numNonAggregatedNodes -= (aggCount_h() - aggregates.GetNumAggregates());
109
110 // update aggregate object
111 if (preserve) {
112 aggregates.SetNumAggregates(aggCount_h());
113 }
114}
115
116} // namespace MueLu
117
118#endif /* MUELU_PRESERVEDIRICHLETAGGREGATIONALGORITHM_DEF_HPP_ */
Container class for aggregation information.
KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const
void SetIsRoot(LO i, bool value=true)
Set root node information.
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
void SetNumAggregates(LO nAggregates)
Set number of local aggregates on current processor.
Kokkos::View< unsigned *, typename LWGraphHostType::device_type > AggStatHostType
Kokkos::View< unsigned *, typename LWGraphType::device_type > AggStatType
KOKKOS_INLINE_FUNCTION size_type GetNodeNumVertices() const
Return number of graph vertices.
typename std::conditional< OnHost, Kokkos::Device< Kokkos::Serial, Kokkos::HostSpace >, typename Node::device_type >::type device_type
const RCP< const Teuchos::Comm< int > > GetComm() const
Lightweight MueLu representation of a compressed row storage graph.
Lightweight MueLu representation of a compressed row storage graph.
Timer to be used in non-factories.
void BuildAggregatesNonKokkos(const Teuchos::ParameterList &params, const LWGraph &graph, Aggregates &aggregates, typename AggregationAlgorithmBase< LocalOrdinal, GlobalOrdinal, Node >::AggStatHostType &aggStat, LO &numNonAggregatedNodes) const
Local aggregation.
void BuildAggregates(const Teuchos::ParameterList &params, const LWGraph_kokkos &graph, Aggregates &aggregates, typename AggregationAlgorithmBase< LocalOrdinal, GlobalOrdinal, Node >::AggStatType &aggStat, LO &numNonAggregatedNodes) const
Namespace for MueLu classes and methods.