Tpetra parallel linear algebra  Version of the Day
Tpetra_ImportExportData_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_IMPORTEXPORTDATA_DEF_HPP
43 #define TPETRA_IMPORTEXPORTDATA_DEF_HPP
44 
45 #include "Tpetra_Map.hpp"
46 #include "Teuchos_FancyOStream.hpp"
47 #include "Teuchos_ParameterList.hpp"
48 
49 namespace Tpetra {
50 namespace Classes {
51  template <class LocalOrdinal, class GlobalOrdinal, class Node>
53  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
54  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target) :
55  source_ (source),
56  target_ (target),
57  out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr))),
58  numSameIDs_ (0),
59  distributor_ (source->getComm (), out_),
60  isLocallyComplete_ (true) // Import/Export constructor may change this
61  {}
62 
63  template <class LocalOrdinal, class GlobalOrdinal, class Node>
65  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
66  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
67  const Teuchos::RCP<Teuchos::FancyOStream>& out) :
68  source_ (source),
69  target_ (target),
70  out_ (out),
71  numSameIDs_ (0),
72  distributor_ (source->getComm (), out_),
73  isLocallyComplete_ (true) // Import/Export constructor may change this
74  {}
75 
76  template <class LocalOrdinal, class GlobalOrdinal, class Node>
78  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
79  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
80  const Teuchos::RCP<Teuchos::ParameterList>& plist) :
81  source_ (source),
82  target_ (target),
83  out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr))),
84  numSameIDs_ (0),
85  distributor_ (source->getComm (), out_, plist),
86  isLocallyComplete_ (true) // Import/Export constructor may change this
87  {}
88 
89  template <class LocalOrdinal, class GlobalOrdinal, class Node>
91  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
92  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
93  const Teuchos::RCP<Teuchos::FancyOStream>& out,
94  const Teuchos::RCP<Teuchos::ParameterList>& plist) :
95  source_ (source),
96  target_ (target),
97  out_ (out),
98  numSameIDs_ (0),
99  distributor_ (source->getComm (), out_, plist),
100  isLocallyComplete_ (true) // Import/Export constructor may change this
101  {}
102 
103  template <class LocalOrdinal, class GlobalOrdinal, class Node>
104  Teuchos::RCP<ImportExportData<LocalOrdinal, GlobalOrdinal, Node> >
106  {
107  using Teuchos::ArrayView;
108 
109  Teuchos::RCP<ImportExportData<LocalOrdinal,GlobalOrdinal,Node> > tData =
110  Teuchos::rcp (new ImportExportData<LocalOrdinal,GlobalOrdinal,Node> (target_, source_));
111 
112  // Things that stay the same
113  tData->numSameIDs_ = numSameIDs_;
114 
115  // Things that reverse
116  tData->distributor_ = *distributor_.getReverse();
117  tData->permuteToLIDs_ = permuteFromLIDs_;
118  tData->permuteFromLIDs_ = permuteToLIDs_;
119 
120  // Remotes / exports (easy part)
121  tData->exportLIDs_ = remoteLIDs_;
122  tData->remoteLIDs_ = exportLIDs_;
123  tData->exportPIDs_.resize(tData->exportLIDs_.size());
124 
125  // Remotes / exports (hard part) - extract the exportPIDs from the remotes of my distributor
126  size_t NumReceives = distributor_.getNumReceives();
127  ArrayView<const int> ProcsFrom = distributor_.getProcsFrom();
128  ArrayView<const size_t> LengthsFrom = distributor_.getLengthsFrom();
129 
130  // isLocallyComplete is a local predicate.
131  // It could be true in one direction but false in another.
132 
133  bool isLocallyComplete = true; // by default
134  for (size_t i = 0, j = 0; i < NumReceives; ++i) {
135  const int pid = ProcsFrom[i];
136  if (pid == -1) {
137  isLocallyComplete = false;
138  }
139  for (size_t k = 0; k < LengthsFrom[i]; ++k) {
140  tData->exportPIDs_[j] = pid;
141  ++j;
142  }
143  }
144  tData->isLocallyComplete_ = isLocallyComplete;
145 
146  return tData;
147  }
148 
149 
150  template <class LocalOrdinal, class GlobalOrdinal, class Node>
152  {}
153 
154 } // namespace Classes
155 } // namespace Tpetra
156 
157 // Explicit instantiation macro.
158 // Only invoke this when in the Tpetra namespace.
159 // Most users do not need to use this.
160 //
161 // LO: The local ordinal type.
162 // GO: The global ordinal type.
163 // NODE: The Kokkos Node type.
164 #define TPETRA_IMPORTEXPORTDATA_INSTANT(LO, GO, NODE) \
165  \
166  namespace Classes { template class ImportExportData< LO , GO , NODE >; }
167 
168 #endif // TPETRA_IMPORTEXPORTDATA_DEF_HPP
Tpetra::Classes::ImportExportData
Implementation detail of Import and Export.
Definition: Tpetra_ImportExportData_decl.hpp:84
Tpetra::Classes::ImportExportData::reverseClone
Teuchos::RCP< ImportExportData< LocalOrdinal, GlobalOrdinal, Node > > reverseClone()
Copy the data, but reverse the direction of the transfer as well as reversing the Distributor.
Definition: Tpetra_ImportExportData_def.hpp:105
Tpetra::Classes::ImportExportData::ImportExportData
ImportExportData(const Teuchos::RCP< const map_type > &source, const Teuchos::RCP< const map_type > &target)
Constructor.
Definition: Tpetra_ImportExportData_def.hpp:53
Tpetra::Classes::ImportExportData::~ImportExportData
~ImportExportData()
Destructor.
Definition: Tpetra_ImportExportData_def.hpp:151
Tpetra::Classes::Map
A parallel distribution of indices over processes.
Definition: Tpetra_Map_decl.hpp:247
Tpetra
Namespace Tpetra contains the class and methods constituting the Tpetra library.