MueLu  Version of the Day
MueLu_Aggregates_def.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_DEF_HPP
47 #define MUELU_AGGREGATES_DEF_HPP
48 
49 #include <Xpetra_Map.hpp>
50 #include <Xpetra_Vector.hpp>
51 #include <Xpetra_BlockedMultiVector.hpp>
52 #include <Xpetra_BlockedVector.hpp>
53 #include <Xpetra_VectorFactory.hpp>
54 
56 #include "MueLu_Graph.hpp"
57 #include "MueLu_Utilities_decl.hpp" // MueLu_sumAll
58 
59 namespace MueLu {
60 
62  template <class LocalOrdinal, class GlobalOrdinal, class Node>
64  nAggregates_ = 0;
65 
66  vertex2AggId_ = LOVectorFactory::Build(graph.GetImportMap());
67  vertex2AggId_->putScalar(MUELU_UNAGGREGATED);
68 
69  procWinner_ = LOVectorFactory::Build(graph.GetImportMap());
70  procWinner_->putScalar(MUELU_UNASSIGNED);
71 
72  isRoot_ = Teuchos::ArrayRCP<bool>(graph.GetImportMap()->getNodeNumElements(), false);
73 
74  // slow but safe, force TentativePFactory to build column map for P itself
75  aggregatesIncludeGhosts_ = true;
76  }
77 
79  template <class LocalOrdinal, class GlobalOrdinal, class Node>
81  nAggregates_ = 0;
82 
83  vertex2AggId_ = LOVectorFactory::Build(map);
84  vertex2AggId_->putScalar(MUELU_UNAGGREGATED);
85 
86  procWinner_ = LOVectorFactory::Build(map);
87  procWinner_->putScalar(MUELU_UNASSIGNED);
88 
89  isRoot_ = Teuchos::ArrayRCP<bool>(map->getNodeNumElements(), false);
90 
91  // slow but safe, force TentativePFactory to build column map for P itself
92  aggregatesIncludeGhosts_ = true;
93  }
94 
96  template <class LocalOrdinal, class GlobalOrdinal, class Node>
97  Teuchos::ArrayRCP<LocalOrdinal> Aggregates<LocalOrdinal, GlobalOrdinal, Node>::ComputeAggregateSizes(bool forceRecompute, bool cacheSizes) const {
98 
99  if (aggregateSizes_ != Teuchos::null && !forceRecompute) {
100 
101  return aggregateSizes_;
102 
103  } else {
104 
105  //invalidate previous sizes.
106  aggregateSizes_ = Teuchos::null;
107 
108  Teuchos::ArrayRCP<LO> aggregateSizes;
109  aggregateSizes = Teuchos::ArrayRCP<LO>(nAggregates_,0);
110  int myPid = vertex2AggId_->getMap()->getComm()->getRank();
111  Teuchos::ArrayRCP<LO> procWinner = procWinner_->getDataNonConst(0);
112  Teuchos::ArrayRCP<LO> vertex2AggId = vertex2AggId_->getDataNonConst(0);
113  LO size = procWinner.size();
114 
115  //for (LO i = 0; i < nAggregates_; ++i) aggregateSizes[i] = 0;
116  for (LO k = 0; k < size; ++k ) {
117  if (procWinner[k] == myPid) aggregateSizes[vertex2AggId[k]]++;
118  }
119 
120  if (cacheSizes)
121  aggregateSizes_ = aggregateSizes;
122 
123  return aggregateSizes;
124  }
125 
126  } //ComputeAggSizesNodes
127 
128  template <class LocalOrdinal, class GlobalOrdinal, class Node>
130  std::ostringstream out;
131  out << BaseClass::description();
132  out << "{nGlobalAggregates = " << GetNumGlobalAggregates() << "}";
133  return out.str();
134  }
135 
136  template <class LocalOrdinal, class GlobalOrdinal, class Node>
137  void Aggregates<LocalOrdinal, GlobalOrdinal, Node>::print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const {
139 
140  if (verbLevel & Statistics1)
141  out0 << "Global number of aggregates: " << GetNumGlobalAggregates() << std::endl;
142  }
143 
144  template <class LocalOrdinal, class GlobalOrdinal, class Node>
146  LO nAggregates = GetNumAggregates();
147  GO nGlobalAggregates; MueLu_sumAll(vertex2AggId_->getMap()->getComm(), (GO)nAggregates, nGlobalAggregates);
148  return nGlobalAggregates;
149  }
150 
151  template <class LocalOrdinal, class GlobalOrdinal, class Node>
152  const RCP<const Xpetra::Map<LocalOrdinal,GlobalOrdinal, Node> > Aggregates<LocalOrdinal, GlobalOrdinal, Node>::GetMap() const {
153  return vertex2AggId_->getMap();
154  }
155 
156 } //namespace MueLu
157 
158 #endif // MUELU_AGGREGATES_DEF_HPP
#define MUELU_UNASSIGNED
std::string description() const
Return a simple one-line description of this object.
#define MueLu_sumAll(rcpComm, in, out)
void print(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
Print more statistics.
Namespace for MueLu classes and methods.
Aggregates(const GraphBase &graph)
Standard constructor for Aggregates structure.
GO GetNumGlobalAggregates() const
Get global number of aggregates.
#define MUELU_UNAGGREGATED
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
const RCP< const Map > GetMap() const
returns (overlapping) map of aggregate/node distribution
MueLu representation of a graph.
virtual const RCP< const Map > GetImportMap() const =0
virtual std::string description() const
Return a simple one-line description of this object.
Teuchos::ArrayRCP< LO > ComputeAggregateSizes(bool forceRecompute=true, bool cacheSizes=false) const
Compute sizes of aggregates.