MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_RepartitionInterface_def.hpp
Go to the documentation of this file.
1/*
2 * MueLu_RepartitionInterface_def.hpp
3 *
4 * Created on: 5 Sep 2013
5 * Author: wiesner
6 */
7
8#ifndef MUELU_REPARTITIONINTERFACE_DEF_HPP_
9#define MUELU_REPARTITIONINTERFACE_DEF_HPP_
10
12
13#include "MueLu_Level.hpp"
14#include "MueLu_Exceptions.hpp"
15#include "MueLu_Monitor.hpp"
16
17
18namespace MueLu {
19
20 template <class LocalOrdinal, class GlobalOrdinal, class Node>
22 RCP<ParameterList> validParamList = rcp(new ParameterList());
23 validParamList->set< RCP<const FactoryBase> >("A", Teuchos::null, "Factory of the matrix A");
24 validParamList->set< RCP<const FactoryBase> >("number of partitions", Teuchos::null, "Instance of RepartitionHeuristicFactory.");
25 validParamList->set< RCP<const FactoryBase> >("AmalgamatedPartition", Teuchos::null, "(advanced) Factory generating the AmalgamatedPartition (e.g. an IsorropiaInterface)");
26
27 return validParamList;
28 }
29
30
31 template <class LocalOrdinal, class GlobalOrdinal, class Node>
33 Input(currentLevel, "A");
34 Input(currentLevel, "number of partitions");
35 Input(currentLevel, "AmalgamatedPartition");
36 } //DeclareInput()
37
38 template <class LocalOrdinal, class GlobalOrdinal, class Node>
40 FactoryMonitor m(*this, "Build", level);
41
42 RCP<Matrix> A = Get< RCP<Matrix> > (level, "A");
43 RCP<Xpetra::Vector<GO, LO, GO, NO> > amalgPartition = Get< RCP<Xpetra::Vector<GO, LO, GO, NO> > >(level, "AmalgamatedPartition");
44 int numParts = Get<int>(level, "number of partitions");
45
46 RCP<const Map> rowMap = A->getRowMap();
47
48 // standard case: use matrix info and amalgamated rebalancing info to create "Partition" vector
49 RCP<const Teuchos::Comm< int > > comm = A->getRowMap()->getComm();
50
51 // Short cut: if we only need one partition, then create a dummy partition vector
52 if (numParts == 1 || numParts == -1) {
53 // Single processor, decomposition is trivial: all zeros
54 RCP<Xpetra::Vector<GO,LO,GO,NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap, true);
55 Set(level, "Partition", decomposition);
56 return;
57 }/* else if (numParts == -1) {
58 // No repartitioning
59 RCP<Xpetra::Vector<GO,LO,GO,NO> > decomposition = Teuchos::null; //Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap, true);
60 //decomposition->putScalar(Teuchos::as<Scalar>(comm->getRank()));
61 Set(level, "Partition", decomposition);
62 return;
63 }*/
64
65 ArrayRCP<GO> amalgPartitionData = amalgPartition->getDataNonConst(0);
66 RCP<const Map> nodeMap = amalgPartition->getMap();
67
68 // extract amalgamation information from matrix A
69 LO blockdim = 1; // block dim for fixed size blocks
70 LO blockid = -1; // block id in strided map
71 LO nStridedOffset = 0; // DOF offset for strided block id "blockid" (default = 0)
72 LO stridedblocksize = blockdim; // size of strided block id "blockid" (default = fullblocksize, only if blockid!=-1 stridedblocksize <= fullblocksize)
73
74 // 1) check for blocking/striding information
75 // fill above variables
76 if(A->IsView("stridedMaps") &&
77 Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap("stridedMaps")) != Teuchos::null) {
78 Xpetra::viewLabel_t oldView = A->SwitchToView("stridedMaps"); // note: "stridedMaps are always non-overlapping (correspond to range and domain maps!)
79 RCP<const StridedMap> strMap = Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap());
80 TEUCHOS_TEST_FOR_EXCEPTION(strMap == Teuchos::null,Exceptions::BadCast,"MueLu::RepartitionInterface::Build: cast to strided row map failed.");
81 blockdim = strMap->getFixedBlockSize();
82 blockid = strMap->getStridedBlockId();
83 if (blockid > -1) {
84 std::vector<size_t> stridingInfo = strMap->getStridingData();
85 for (size_t j = 0; j < Teuchos::as<size_t>(blockid); j++)
86 nStridedOffset += stridingInfo[j];
87 stridedblocksize = Teuchos::as<LocalOrdinal>(stridingInfo[blockid]);
88
89 } else {
90 stridedblocksize = blockdim;
91 }
92 oldView = A->SwitchToView(oldView);
93 //GetOStream(Statistics0, -1) << "RepartitionInterface::Build():" << " found blockdim=" << blockdim << " from strided maps (blockid=" << blockid << ", strided block size=" << stridedblocksize << "). offset=" << offset << std::endl;
94 } else GetOStream(Statistics0, -1) << "RepartitionInterface::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl;
95
96 // vector which stores final (unamalgamated) repartitioning
97 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap, false);
98 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
99
100 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<int>(nodeMap->getLocalNumElements())*stridedblocksize != Teuchos::as<int>(rowMap->getLocalNumElements()), Exceptions::RuntimeError, "Inconsistency between nodeMap and dofMap: we are supporting block maps only. No support for general strided maps, yet!");
101
102 //RCP<std::map<GO,std::vector<GO> > > nodegid2dofgids = amalgInfo->GetGlobalAmalgamationParams();
103
104 // fill vector with information about partitioning
105 // TODO: we assume simple block maps here
106 // TODO: adapt this to usage of nodegid2dofgids
107 for(size_t i = 0; i < nodeMap->getLocalNumElements(); i++) {
108 // not fully sure about this. We're filling local ids in the decomposition vector with
109 // the results stored in array. The decomposition vector is created using the rowMap of A
110
111 // transform local node id to global node id.
112 //GO gNodeId = nodeMap->getGlobalElement(i);
113
114 // extract global DOF ids that belong to gNodeId
115 /*std::vector<GlobalOrdinal> DOFs = (*nodegid2dofgids)[gNodeId];
116 for(size_t j=0; j<stridedblocksize; j++) {
117 decompEntries[i*stridedblocksize + j] = myRank;
118 }*/
119 for (LO j = 0; j < stridedblocksize/*DOFs.size()*/; j++) {
120 // transform global DOF ids to local DOF ids using rowMap
121 // note: The vector decomposition is based on rowMap
122 //LO lDofId = rowMap->getLocalElement(DOFs[j]); // -> i doubt that we need this!
123
124 // put the same domain id to all DOFs of the same node
125 decompEntries[i*stridedblocksize + j] = amalgPartitionData[i];
126 //decompEntries[lDofId] = amalgPartitionData[i];
127 }
128
129 }
130
131 Set(level, "Partition", decomposition);
132
133 } //Build()
134
135
136
137} //namespace MueLu
138
139
140#endif /* MUELU_REPARTITIONINTERFACE_DEF_HPP_ */
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
void Input(Level &level, const std::string &varName) const
T Get(Level &level, const std::string &varName) const
void Set(Level &level, const std::string &varName, const T &data) const
Class that holds all level-specific information.
void DeclareInput(Level &level) const
Specifies the data that this class needs, and the factories that generate that data.
void Build(Level &level) const
Build an object with this factory.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Namespace for MueLu classes and methods.
@ Statistics0
Print statistics that do not involve significant additional computation.