Debian Codegraph @

packages/shylu/shylu_dd/frosch/src/Tools/FROSch_Tools_decl.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // ShyLU: Scalable Hybrid LU Preconditioner and Solver
4 //
5 // Copyright 2011 NTESS and the ShyLU contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef _FROSCH_TOOLS_DECL_HPP
11 #define _FROSCH_TOOLS_DECL_HPP
12
13 #include <ShyLU_DDFROSch_config.h>
14
15 #include <FROSch_Types.h>
16 #include <FROSch_Output.h>
17 #include <FROSch_Timers.h>
18
19 #include <Tpetra_Distributor.hpp>
20
21 #include <MatrixMarket_Tpetra.hpp>
22
23 #include <Xpetra_MatrixFactory.hpp>
24 #include <Xpetra_CrsGraphFactory.hpp>
25 #include <Xpetra_MultiVectorFactory.hpp>
26 #include <Xpetra_VectorFactory.hpp>
27 #include <Xpetra_ExportFactory.hpp>
28
29 #ifdef HAVE_SHYLU_DDFROSCH_ZOLTAN2
30 #include <Zoltan2_MatrixAdapter.hpp>
31 #include <Zoltan2_XpetraCrsMatrixAdapter.hpp>
32 #include <Zoltan2_PartitioningProblem.hpp>
33 #include <Zoltan2_XpetraCrsGraphAdapter.hpp>
34 #endif
35
36
37 namespace FROSch {
38
39 using namespace std;
40 using namespace Teuchos;
41 using namespace Xpetra;
42
43
44 template <typename LO,
45 typename GO>
46 class OverlappingData {
47
48 protected:
49
50 using IntVec = Array<int>;
51
52 using LOVec = Array<LO>;
53
54 public:
55
56 OverlappingData(GO gid,
57 int pid,
58 LO lid);
59
60 int Merge(const RCP<OverlappingData<LO,GO> > od) const;
61
62
63 GO GID_;
64
65 mutable IntVec PIDs_;
66
67 mutable LOVec LIDs_;
68
69 };
70
71 template <typename LO,typename GO>
72 int MergeList(Array<RCP<OverlappingData<LO,GO> > > &odList);
73
74 template <typename LO,
75 typename GO,
76 typename NO>
77 class LowerPIDTieBreak : public Tpetra::Details::TieBreak<LO,GO> {
78
79 protected:
80
81 using CommPtr = RCP<const Comm<int> >;
82
83 using XMap = Map<LO,GO,NO>;
84 using XMapPtr = RCP<XMap>;
85 using ConstXMapPtr = RCP<const XMap>;
86 using XMapPtrVecPtr = ArrayRCP<XMapPtr>;
87 using ConstXMapPtrVecPtr = ArrayRCP<ConstXMapPtr>;
88 using XMapPtrVecPtr2D = ArrayRCP<XMapPtrVecPtr>;
89 using ConstXMapPtrVecPtr2D = ArrayRCP<ConstXMapPtrVecPtr>;
90
91 using OverlappingDataPtr = RCP<OverlappingData<LO,GO> >;
92 using OverlappingDataPtrVec = Array<OverlappingDataPtr>;
93
94 using UN = unsigned;
95
96 using IntVec = Array<int>;
97 using IntVecVecPtr = ArrayRCP<IntVec>;
98
99 using LOVec = Array<LO>;
100
101 using GOVec = Array<GO>;
102 using GOVecPtr = ArrayRCP<GO>;
103 using GOVecVec = Array<GOVec>;
104 using GOVecVecPtr = ArrayRCP<GOVec>;
105
106 using GOView = Kokkos::View<GO*, Kokkos::HostSpace>;
107
108 public:
109 LowerPIDTieBreak(CommPtr comm,
110 ConstXMapPtr originalMap,
111 UN dimension,
112 UN levelID = 1); // This is in order to estimate the length of SendImageIDs_ and ExportEntries_ in advance
113
114 virtual bool mayHaveSideEffects() const {
115 return false;
116 }
117
118 IntVecVecPtr& getComponents()
119 {
120 return ComponentsSubdomains_;
121 }
122
123 int sendDataToOriginalMap();
124
125 virtual size_t selectedIndex(GO GID,
126 const vector<pair<int,LO> > & pid_and_lid) const;
127
128 protected:
129
130 CommPtr MpiComm_;
131
132 ConstXMapPtr OriginalMap_;
133
134 mutable LO ElementCounter_; // This is mutable such that it can be modified in selectedIndex()
135
136 mutable OverlappingDataPtrVec OverlappingDataList_; // This is mutable such that it can be modified in selectedIndex()
137
138 IntVecVecPtr ComponentsSubdomains_; // This is mutable such that it can be modified in selectedIndex()
139
140 UN LevelID_ = 1;
141 };
142
143 template <class SC, class LO, class GO, class NO>
144 void writeMM(std::string fileName, Teuchos::RCP<Xpetra::Matrix<SC,LO,GO,NO> > &matrix_);
145
146 template<class SC, class LO, class GO, class NO>
147 void writeMM(Teuchos::RCP<Xpetra::Matrix<SC,LO,GO,NO> >& matrix_,std::string fileName);
148
149 template <class SC, class LO, class GO, class NO>
150 void readMM(std::string fileName, Teuchos::RCP<Xpetra::Matrix<SC,LO,GO,NO> > &matrix_,RCP<const Comm<int> > &comm);
151
152 template <class SC,class LO,class GO,class NO>
153 RCP<Map<LO,GO,NO> > BuildRepeatedMapGaleriStruct2D(RCP<const Matrix<SC,LO,GO,NO> > matrix,int M,int Dim);
154
155
156 template <class SC,class LO,class GO,class NO>
157 RCP<Map<LO,GO,NO> > BuildRepeatedMapGaleriStruct3D(RCP<const Map<LO,GO,NO> > matrix,int M,int Dim);
158
159 template <class LO,class GO,class NO>
160 RCP<const Map<LO,GO,NO> > BuildUniqueMap(const RCP<const Map<LO,GO,NO> > map,
161 bool useCreateOneToOneMap = true,
162 RCP<Tpetra::Details::TieBreak<LO,GO> > tieBreak = null);
163
164 template <class SC,class LO,class GO,class NO>
165 ArrayRCP<RCP<const Map<LO,GO,NO> > > BuildRepeatedSubMaps(RCP<const Matrix<SC,LO,GO,NO> > matrix,
166 ArrayRCP<const RCP<Map<LO,GO,NO> > > subMaps);
167
168 template <class SC,class LO,class GO,class NO>
169 ArrayRCP<RCP<const Map<LO,GO,NO> > > BuildRepeatedSubMaps(RCP<const CrsGraph<LO,GO,NO> > graph,
170 ArrayRCP<const RCP<Map<LO,GO,NO> > > subMaps);
171
172 template <class SC,class LO,class GO,class NO>
173 RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConstOld(RCP<const Matrix<SC,LO,GO,NO> > matrix);
174
175 template <class SC,class LO,class GO,class NO>
176 RCP<const Map<LO,GO,NO> > BuildRepeatedMapOld(RCP<const Matrix<SC,LO,GO,NO> > matrix);
177
178 template <class LO,class GO,class NO>
179 RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConstOld(RCP<const CrsGraph<LO,GO,NO> > graph);
180
181 template <class LO,class GO,class NO>
182 RCP<const Map<LO,GO,NO> > BuildRepeatedMapOld(RCP<const CrsGraph<LO,GO,NO> > graph);
183
184 template <class SC,class LO,class GO,class NO>
185 RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConst(RCP<const Matrix<SC,LO,GO,NO> > matrix);
186
187 template <class SC,class LO,class GO,class NO>
188 RCP<const Map<LO,GO,NO> > BuildRepeatedMap(RCP<const Matrix<SC,LO,GO,NO> > matrix);
189
190 template <class LO,class GO,class NO>
191 RCP<Map<LO,GO,NO> > BuildRepeatedMapNonConst(RCP<const CrsGraph<LO,GO,NO> > graph);
192
193 template <class LO,class GO,class NO>
194 RCP<const Map<LO,GO,NO> > BuildRepeatedMap(RCP<const CrsGraph<LO,GO,NO> > graph);
195
196 template <class LO,class GO,class NO>
197 Teuchos::RCP<Xpetra::Map<LO,GO,NO> > BuildMapFromNodeMapRepeated(Teuchos::RCP<const Xpetra::Map<LO,GO,NO> > &nodesMap,
198 unsigned dofsPerNode,
199 unsigned dofOrdering);
200
201 template <class SC,class LO,class GO,class NO>
202 int ExtendOverlapByOneLayer_Old(RCP<const Matrix<SC,LO,GO,NO> > inputMatrix,
203 RCP<const Map<LO,GO,NO> > inputMap,
204 RCP<const Matrix<SC,LO,GO,NO> > &outputMatrix,
205 RCP<const Map<LO,GO,NO> > &outputMap);
206
207 template <class SC,class LO,class GO,class NO>
208 int ExtendOverlapByOneLayer(RCP<const Matrix<SC,LO,GO,NO> > inputMatrix,
209 RCP<const Map<LO,GO,NO> > inputMap,
210 RCP<const Matrix<SC,LO,GO,NO> > &outputMatrix,
211 RCP<const Map<LO,GO,NO> > &outputMap);
212
213 template <class LO,class GO,class NO>
214 int ExtendOverlapByOneLayer(RCP<const CrsGraph<LO,GO,NO> > inputGraph,
215 RCP<const Map<LO,GO,NO> > inputMap,
216 RCP<const CrsGraph<LO,GO,NO> > &outputGraph,
217 RCP<const Map<LO,GO,NO> > &outputMap);
218
219 /*! \brief Sort the Xpetra::Map by the global IDs \c x
220 * \param[in] inputMap Unsorted input map
221 */
222 template <class LO,class GO,class NO>
223 RCP<const Map<LO,GO,NO> > SortMapByGlobalIndex(RCP<const Map<LO,GO,NO> > inputMap);
224
225 template <class LO,class GO,class NO>
226 RCP<Map<LO,GO,NO> > AssembleMaps(ArrayView<RCP<const Map<LO,GO,NO> > > mapVector,
227 ArrayRCP<ArrayRCP<LO> > &partMappings);
228
229 template <class LO,class GO,class NO>
230 RCP<Map<LO,GO,NO> > AssembleMapsNonConst(ArrayView<RCP<Map<LO,GO,NO> > > mapVector,
231 ArrayRCP<ArrayRCP<LO> > &partMappings);
232
233 template <class LO,class GO,class NO>
234 RCP<Map<LO,GO,NO> > AssembleSubdomainMap(unsigned numberOfBlocks,
235 ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > > dofsMaps,
236 ArrayRCP<unsigned> dofsPerNode);
237
238 template <class LO,class GO,class NO>
239 RCP<Map<LO,GO,NO> > MergeMapsNonConst(ArrayRCP<RCP<const Map<LO,GO,NO> > > mapVector);
240
241 template <class LO,class GO,class NO>
242 RCP<const Map<LO,GO,NO> > MergeMaps(ArrayRCP<RCP<const Map<LO,GO,NO> > > mapVector);
243
244 template <class LO,class GO,class NO>
245 int BuildDofMaps(const RCP<const Map<LO,GO,NO> > map,
246 unsigned dofsPerNode,
247 unsigned dofOrdering,
248 RCP<const Map<LO,GO,NO> > &nodesMap,
249 ArrayRCP<RCP<const Map<LO,GO,NO> > > &dofMaps,
250 GO offset = 0);
251
252 template <class LO,class GO,class NO>
253 int BuildDofMapsVec(const ArrayRCP<RCP<const Map<LO,GO,NO> > > mapVec,
254 ArrayRCP<unsigned> dofsPerNodeVec,
255 ArrayRCP<FROSch::DofOrdering> dofOrderingVec,
256 ArrayRCP<RCP<const Map<LO,GO,NO> > > &nodesMapVec,
257 ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > >&dofMapsVec);
258
259
260 template <class LO,class GO,class NO>
261 RCP<Map<LO,GO,NO> > BuildMapFromDofMaps(const ArrayRCP<RCP<Map<LO,GO,NO> > > &dofMaps,
262 unsigned dofsPerNode,
263 unsigned dofOrdering);
264
265 template <class LO,class GO,class NO>
266 RCP<Map<LO,GO,NO> > BuildMapFromNodeMap(RCP<const Map<LO,GO,NO> > &nodesMap,
267 unsigned dofsPerNode,
268 unsigned dofOrdering);
269
270 template <class LO,class GO,class NO>
271 ArrayRCP<RCP<const Map<LO,GO,NO> > > BuildNodeMapsFromDofMaps(ArrayRCP<ArrayRCP<RCP<const Map<LO,GO,NO> > > >dofsMapsVecVec,
272 ArrayRCP<unsigned> dofsPerNodeVec,
273 ArrayRCP<DofOrdering> dofOrderingVec);
274
275 template <class LO,class GO,class NO>
276 ArrayRCP<RCP<Map<LO,GO,NO> > > BuildSubMaps(RCP<const Map<LO,GO,NO> > &fullMap,
277 ArrayRCP<GO> maxSubGIDVec);
278
279 template <class SC,class LO,class GO,class NO>
280 ArrayRCP<GO> FindOneEntryOnlyRowsGlobal(RCP<const Matrix<SC,LO,GO,NO> > matrix,
281 RCP<const Map<LO,GO,NO> > repeatedMap);
282
283 template <class LO,class GO,class NO>
284 ArrayRCP<GO> FindOneEntryOnlyRowsGlobal(RCP<const CrsGraph<LO,GO,NO> > graph,
285 RCP<const Map<LO,GO,NO> > repeatedMap);
286
287 template <class SC,class LO>
288 bool ismultiple(ArrayView<SC> A,
289 ArrayView<SC> B);
290
291 template<class T>
292 inline void sort(T &v);
293
294 template<class T>
295 inline void sortunique(T &v);
296
297 template <class SC, class LO,class GO,class NO>
298 RCP<MultiVector<SC,LO,GO,NO> > ModifiedGramSchmidt(RCP<const MultiVector<SC,LO,GO,NO> > multiVector,
299 ArrayView<unsigned> zero = ArrayView<unsigned>());
300
301 template <class SC, class LO,class GO,class NO>
302 RCP<const MultiVector<SC,LO,GO,NO> > BuildNullSpace(unsigned dimension,
303 const NullSpaceType nullSpaceType,
304 RCP<const Map<LO,GO,NO> > repeatedMap,
305 unsigned dofsPerNode,
306 ArrayRCP<RCP<const Map<LO,GO,NO> > > dofsMaps,
307 RCP<const MultiVector<SC,LO,GO,NO> > nodeList = null);
308
309 #ifdef HAVE_SHYLU_DDFROSCH_EPETRA
310 template <class SC,class LO,class GO,class NO>
311 struct ConvertToXpetra {
312
313 public:
314
315 static RCP<Map<LO,GO,NO> > ConvertMap(UnderlyingLib lib,
316 const Epetra_BlockMap &map,
317 RCP<const Comm<int> > comm);
318
319 static RCP<Matrix<SC,LO,GO,NO> > ConvertMatrix(UnderlyingLib lib,
320 Epetra_CrsMatrix &matrix,
321 RCP<const Comm<int> > comm);
322
323 static RCP<MultiVector<SC,LO,GO,NO> > ConvertMultiVector(UnderlyingLib lib,
324 Epetra_MultiVector &vector,
325 RCP<const Comm<int> > comm);
326 };
327
328 template <class SC,class LO,class NO>
329 struct ConvertToXpetra<SC,LO,int,NO> {
330
331 public:
332
333 static RCP<Map<LO,int,NO> > ConvertMap(UnderlyingLib lib,
334 const Epetra_BlockMap &map,
335 RCP<const Comm<int> > comm);
336
337 static RCP<Matrix<SC,LO,int,NO> > ConvertMatrix(UnderlyingLib lib,
338 Epetra_CrsMatrix &matrix,
339 RCP<const Comm<int> > comm);
340
341 static RCP<MultiVector<SC,LO,int,NO> > ConvertMultiVector(UnderlyingLib lib,
342 Epetra_MultiVector &vector,
343 RCP<const Comm<int> > comm);
344 };
345
346 template <class SC,class LO,class NO>
347 struct ConvertToXpetra<SC,LO,long long,NO> {
348
349 public:
350
351 static RCP<Map<LO,long long,NO> > ConvertMap(UnderlyingLib lib,
352 const Epetra_BlockMap &map,
353 RCP<const Comm<int> > comm);
354
355 static RCP<Matrix<SC,LO,long long,NO> > ConvertMatrix(UnderlyingLib lib,
356 Epetra_CrsMatrix &matrix,
357 RCP<const Comm<int> > comm);
358
359 static RCP<MultiVector<SC,LO,long long,NO> > ConvertMultiVector(UnderlyingLib lib,
360 Epetra_MultiVector &vector,
361 RCP<const Comm<int> > comm);
362 };
363 #endif
364
365 template <class Type>
366 RCP<Type> ExtractPtrFromParameterList(ParameterList& paramList,
367 string namePtr="Ptr");
368
369 template <class Type>
370 ArrayRCP<Type> ExtractVectorFromParameterList(ParameterList& paramList,
371 string nameVector="Vector");
372
373 #ifdef HAVE_SHYLU_DDFROSCH_EPETRA
374 template <class LO,class GO,class NO>
375 RCP<Epetra_Map> ConvertToEpetra(const Map<LO,GO,NO> &map,
376 RCP<Epetra_Comm> epetraComm);
377
378 template <class SC,class LO,class GO,class NO>
379 RCP<Epetra_MultiVector> ConvertToEpetra(const MultiVector<SC,LO,GO,NO> &vector,
380 RCP<Epetra_Comm> epetraComm);
381
382 template <class SC,class LO,class GO,class NO>
383 RCP<Epetra_CrsMatrix> ConvertToEpetra(const Matrix<SC,LO,GO,NO> &matrix,
384 RCP<Epetra_Comm> epetraComm);
385 #endif
386
387 template <class LO>
388 Array<LO> GetIndicesFromString(string string);
389
390 #ifdef HAVE_SHYLU_DDFROSCH_ZOLTAN2
391 template <class SC,class LO,class GO,class NO>
392 int RepartionMatrixZoltan2(RCP<Matrix<SC,LO,GO,NO> > &crsMatrix,
393 RCP<ParameterList> parameterList);
394
395 template <class LO,class GO, class NO>
396 int BuildRepMapZoltan(RCP<CrsGraph<LO,GO,NO> > Xgraph,
397 RCP<CrsGraph<LO,GO,NO> > B,
398 RCP<ParameterList> parameterList,
399 Teuchos::RCP<const Teuchos::Comm<int> > TeuchosComm,
400 RCP<Map<LO,GO,NO> > &RepeatedMap);
401 #endif
402
403 /*!
404 \brief Throw runtime error due to missing package in build configuration
405
406 As many packages are optional, we might detect only at runtime that are certain package
407 is not included into the build configuration, but still is used by FROSch.
408 Use this routine to throw a generic error message with some information for the user
409 and provide details how to fix it.
410
411 \param[in] forschObj FROSch object that is asking for the missing package
412 \param[in] packageName Name of the missing package
413 */
414 inline void ThrowErrorMissingPackage(const string& froschObj,
415 const string& packageName)
416 {
417 // Create the error message
418 stringstream errMsg;
419 errMsg << froschObj << " is asking for the Trilinos packate '"<< packageName << "', "
420 "but this package is not included in your build configuration. "
421 "Please enable '" << packageName << "' in your build configuration to be used with ShyLU_DDFROSch.";
422
423 // Throw the error
424 FROSCH_ASSERT(false, errMsg.str());
425 }
426 }
427
428 #endif