MueLu
Version of the Day
Toggle main menu visibility
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
18
#include "
MueLu_PreserveDirichletAggregationAlgorithm_decl.hpp
"
19
20
#include "MueLu_LWGraph.hpp"
21
#include "MueLu_Aggregates.hpp"
22
#include "
MueLu_Exceptions.hpp
"
23
#include "
MueLu_Monitor.hpp
"
24
25
namespace
MueLu
{
26
27
template
<
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
28
void
PreserveDirichletAggregationAlgorithm<LocalOrdinal, GlobalOrdinal, Node>::BuildAggregatesNonKokkos
(Teuchos::ParameterList
const
& params,
LWGraph
const
& graph,
Aggregates
& aggregates,
typename
AggregationAlgorithmBase<LocalOrdinal, GlobalOrdinal, Node>::AggStatHostType
& aggStat, LO& numNonAggregatedNodes)
const
{
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
58
template
<
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
59
void
PreserveDirichletAggregationAlgorithm<LocalOrdinal, GlobalOrdinal, Node>::
60
BuildAggregates
(Teuchos::ParameterList
const
& params,
61
LWGraph_kokkos
const
& graph,
62
Aggregates
& aggregates,
63
typename
AggregationAlgorithmBase<LocalOrdinal, GlobalOrdinal, Node>::AggStatType
& aggStat,
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_ */
MueLu_Exceptions.hpp
MueLu_Monitor.hpp
MueLu_PreserveDirichletAggregationAlgorithm_decl.hpp
MueLu::Aggregates
Container class for aggregation information.
Definition
MueLu_Aggregates_decl.hpp:67
MueLu::Aggregates::GetNumAggregates
KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const
Definition
MueLu_Aggregates_decl.hpp:175
MueLu::Aggregates::SetIsRoot
void SetIsRoot(LO i, bool value=true)
Set root node information.
Definition
MueLu_Aggregates_decl.hpp:222
MueLu::Aggregates::GetVertex2AggId
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
Definition
MueLu_Aggregates_decl.hpp:207
MueLu::Aggregates::GetProcWinner
const RCP< LOVector > & GetProcWinner() const
Returns constant vector that maps local node IDs to owning processor IDs.
Definition
MueLu_Aggregates_decl.hpp:213
MueLu::Aggregates::SetNumAggregates
void SetNumAggregates(LO nAggregates)
Set number of local aggregates on current processor.
Definition
MueLu_Aggregates_decl.hpp:166
MueLu::AggregationAlgorithmBase::AggStatHostType
Kokkos::View< unsigned *, typename LWGraphHostType::device_type > AggStatHostType
Definition
MueLu_AggregationAlgorithmBase.hpp:37
MueLu::AggregationAlgorithmBase::AggStatType
Kokkos::View< unsigned *, typename LWGraphType::device_type > AggStatType
Definition
MueLu_AggregationAlgorithmBase.hpp:40
MueLu::LWGraph_kokkos
Lightweight MueLu representation of a compressed row storage graph.
Definition
MueLu_LWGraph_kokkos_decl.hpp:30
MueLu::LWGraphBase::GetNodeNumVertices
KOKKOS_INLINE_FUNCTION size_type GetNodeNumVertices() const
Return number of graph vertices.
Definition
MueLu_LWGraphBase.hpp:188
MueLu::LWGraphBase< LocalOrdinal, GlobalOrdinal, Node, false >::execution_space
typename device_type::execution_space execution_space
Definition
MueLu_LWGraphBase.hpp:83
MueLu::LWGraphBase< LocalOrdinal, GlobalOrdinal, Node, false >::device_type
typename std::conditional< OnHost, Kokkos::Device< Kokkos::Serial, Kokkos::HostSpace >, typename Node::device_type >::type device_type
Definition
MueLu_LWGraphBase.hpp:80
MueLu::LWGraphBase::GetComm
const RCP< const Teuchos::Comm< int > > GetComm() const
Definition
MueLu_LWGraphBase.hpp:176
MueLu::LWGraphBase< LocalOrdinal, GlobalOrdinal, Node, false >::local_ordinal_type
LocalOrdinal local_ordinal_type
Definition
MueLu_LWGraphBase.hpp:74
MueLu::LWGraph
Lightweight MueLu representation of a compressed row storage graph.
Definition
MueLu_LWGraph_decl.hpp:33
MueLu::Monitor
Timer to be used in non-factories.
Definition
MueLu_Monitor.hpp:68
MueLu::PreserveDirichletAggregationAlgorithm::BuildAggregatesNonKokkos
void BuildAggregatesNonKokkos(const Teuchos::ParameterList ¶ms, const LWGraph &graph, Aggregates &aggregates, typename AggregationAlgorithmBase< LocalOrdinal, GlobalOrdinal, Node >::AggStatHostType &aggStat, LO &numNonAggregatedNodes) const
Local aggregation.
Definition
MueLu_PreserveDirichletAggregationAlgorithm_def.hpp:28
MueLu::PreserveDirichletAggregationAlgorithm::BuildAggregates
void BuildAggregates(const Teuchos::ParameterList ¶ms, const LWGraph_kokkos &graph, Aggregates &aggregates, typename AggregationAlgorithmBase< LocalOrdinal, GlobalOrdinal, Node >::AggStatType &aggStat, LO &numNonAggregatedNodes) const
Definition
MueLu_PreserveDirichletAggregationAlgorithm_def.hpp:60
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:42
MueLu::BOUNDARY
@ BOUNDARY
Definition
MueLu_DroppingCommon.hpp:36
MueLu::IGNORED
@ IGNORED
Definition
MueLu_Types.hpp:43
src
Graph
UncoupledAggregation
MueLu_PreserveDirichletAggregationAlgorithm_def.hpp
Generated by
1.17.0