Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_ImportExportData_def.hpp
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_IMPORTEXPORTDATA_DEF_HPP
11#define TPETRA_IMPORTEXPORTDATA_DEF_HPP
12
13#include "Tpetra_Map.hpp"
14#include "Tpetra_Details_makeValidVerboseStream.hpp"
15#include "Teuchos_FancyOStream.hpp"
16#include "Teuchos_ParameterList.hpp"
17
18namespace Tpetra {
19
20template <class LocalOrdinal, class GlobalOrdinal, class Node>
22 ImportExportData(const Teuchos::RCP<const map_type>& source,
23 const Teuchos::RCP<const map_type>& target,
24 const Teuchos::RCP<Teuchos::FancyOStream>& out,
25 const Teuchos::RCP<Teuchos::ParameterList>& plist)
26 : source_(source)
27 , // NOT allowed to be null
28 target_(target)
29 , // allowed to be null
30 out_(::Tpetra::Details::makeValidVerboseStream(out))
31 , numSameIDs_(0)
32 , // Import/Export constructor may change this
33 distributor_(source->getComm(), out_, plist)
34 , // Im/Ex ctor will init
35 isLocallyComplete_(true) // Im/Ex ctor may change this
36{
37 TEUCHOS_ASSERT(!out_.is_null());
38}
39
40template <class LocalOrdinal, class GlobalOrdinal, class Node>
42 ImportExportData(const Teuchos::RCP<const map_type>& source,
43 const Teuchos::RCP<const map_type>& target)
44 : ImportExportData(source, target, Teuchos::null, Teuchos::null) {}
45
46template <class LocalOrdinal, class GlobalOrdinal, class Node>
48 ImportExportData(const Teuchos::RCP<const map_type>& source,
49 const Teuchos::RCP<const map_type>& target,
50 const Teuchos::RCP<Teuchos::FancyOStream>& out)
51 : ImportExportData(source, target, out, Teuchos::null) {}
52
53template <class LocalOrdinal, class GlobalOrdinal, class Node>
55 ImportExportData(const Teuchos::RCP<const map_type>& source,
56 const Teuchos::RCP<const map_type>& target,
57 const Teuchos::RCP<Teuchos::ParameterList>& plist)
58 : ImportExportData(source, target, Teuchos::null, plist) {}
59
60template <class LocalOrdinal, class GlobalOrdinal, class Node>
61Teuchos::RCP<ImportExportData<LocalOrdinal, GlobalOrdinal, Node> >
64 using Teuchos::ArrayView;
66
67 auto tData = Teuchos::rcp(new data_type(target_, source_, out_));
68
69 // Things that stay the same
70 tData->numSameIDs_ = numSameIDs_;
71
72 // Things that reverse
73 tData->distributor_ = *distributor_.getReverse();
74 tData->permuteToLIDs_ = permuteFromLIDs_;
75 tData->permuteFromLIDs_ = permuteToLIDs_;
76
77 // Remotes / exports (easy part)
78 tData->exportLIDs_ = remoteLIDs_;
79 tData->remoteLIDs_ = exportLIDs_;
80 tData->exportPIDs_.resize(tData->exportLIDs_.extent(0));
81
82 // Remotes / exports (hard part) - extract the exportPIDs from the remotes of my distributor
83 const size_t NumReceives = distributor_.getNumReceives();
84 ArrayView<const int> ProcsFrom = distributor_.getProcsFrom();
85 ArrayView<const size_t> LengthsFrom = distributor_.getLengthsFrom();
86
87 // isLocallyComplete is a local predicate.
88 // It could be true in one direction but false in another.
89
90 bool isLocallyComplete = true; // by default
91 for (size_t i = 0, j = 0; i < NumReceives; ++i) {
92 const int pid = ProcsFrom[i];
93 if (pid == -1) {
94 isLocallyComplete = false;
95 }
96 for (size_t k = 0; k < LengthsFrom[i]; ++k) {
97 tData->exportPIDs_[j] = pid;
98 ++j;
99 }
100 }
101 tData->isLocallyComplete_ = isLocallyComplete;
102
103 return tData;
104}
105
106} // namespace Tpetra
107
108// Explicit instantiation macro.
109// Only invoke this when in the Tpetra namespace.
110// Most users do not need to use this.
111//
112// LO: The local ordinal type.
113// GO: The global ordinal type.
114// NODE: The Kokkos Node type.
115#define TPETRA_IMPORTEXPORTDATA_INSTANT(LO, GO, NODE) \
116 template class ImportExportData<LO, GO, NODE>;
117
118#endif // TPETRA_IMPORTEXPORTDATA_DEF_HPP
Struct that holds views of the contents of a CrsMatrix.
Implementation detail of Import and Export.
Teuchos::RCP< ImportExportData< LocalOrdinal, GlobalOrdinal, Node > > reverseClone()
Copy the data, but reverse the direction of the transfer as well as reversing the Distributor.
Teuchos::RCP< Teuchos::FancyOStream > out_
Output stream for verbose debugging output.
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.