Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
18 namespace Tpetra {
19 
20  template <class LocalOrdinal, class GlobalOrdinal, class Node>
21  ImportExportData<LocalOrdinal, GlobalOrdinal, 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), // NOT allowed to be null
27  target_ (target), // allowed to be null
28  out_ (::Tpetra::Details::makeValidVerboseStream (out)),
29  numSameIDs_ (0), // Import/Export constructor may change this
30  distributor_ (source->getComm (), out_, plist), // Im/Ex ctor will init
31  isLocallyComplete_ (true) // Im/Ex ctor may change this
32  {
33  TEUCHOS_ASSERT( ! out_.is_null () );
34  }
35 
36  template <class LocalOrdinal, class GlobalOrdinal, class Node>
38  ImportExportData (const Teuchos::RCP<const map_type>& source,
39  const Teuchos::RCP<const map_type>& target) :
40  ImportExportData (source, target, Teuchos::null, Teuchos::null)
41  {}
42 
43  template <class LocalOrdinal, class GlobalOrdinal, class Node>
45  ImportExportData (const Teuchos::RCP<const map_type>& source,
46  const Teuchos::RCP<const map_type>& target,
47  const Teuchos::RCP<Teuchos::FancyOStream>& out) :
48  ImportExportData (source, target, out, Teuchos::null)
49  {}
50 
51  template <class LocalOrdinal, class GlobalOrdinal, class Node>
53  ImportExportData (const Teuchos::RCP<const map_type>& source,
54  const Teuchos::RCP<const map_type>& target,
55  const Teuchos::RCP<Teuchos::ParameterList>& plist) :
56  ImportExportData (source, target, Teuchos::null, plist)
57  {}
58 
59  template <class LocalOrdinal, class GlobalOrdinal, class Node>
60  Teuchos::RCP<ImportExportData<LocalOrdinal, GlobalOrdinal, Node> >
63  {
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
Implementation detail of Import and Export.
Teuchos::RCP< Teuchos::FancyOStream > out_
Output stream for verbose debugging output.
Teuchos::RCP< ImportExportData< LocalOrdinal, GlobalOrdinal, Node > > reverseClone()
Copy the data, but reverse the direction of the transfer as well as reversing the Distributor...