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_ImportExportData_decl.hpp>
46 
47 #include <Tpetra_Map.hpp>
48 
49 namespace Tpetra {
50  template <class LocalOrdinal, class GlobalOrdinal, class Node>
52  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
53  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target)
54  : out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr)))
55  , numSameIDs_ (0)
56  , source_ (source)
57  , target_ (target)
58  , comm_ (source->getComm())
59  , distributor_ (comm_, out_)
60  {}
61 
62  template <class LocalOrdinal, class GlobalOrdinal, class Node>
64  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
65  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
66  const Teuchos::RCP<Teuchos::FancyOStream>& out)
67  : out_ (out)
68  , numSameIDs_ (0)
69  , source_ (source)
70  , target_ (target)
71  , comm_ (source->getComm())
73  {}
74 
75  template <class LocalOrdinal, class GlobalOrdinal, class Node>
77  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
78  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
79  const Teuchos::RCP<Teuchos::ParameterList>& plist)
80  : out_ (Teuchos::getFancyOStream (Teuchos::rcpFromRef (std::cerr)))
81  , numSameIDs_ (0)
82  , source_ (source)
83  , target_ (target)
84  , comm_ (source->getComm())
85  , distributor_ (comm_, out_, plist)
86  {}
87 
88  template <class LocalOrdinal, class GlobalOrdinal, class Node>
90  ImportExportData (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& source,
91  const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& target,
92  const Teuchos::RCP<Teuchos::FancyOStream>& out,
93  const Teuchos::RCP<Teuchos::ParameterList>& plist)
94  : out_ (out)
95  , numSameIDs_ (0)
96  , source_ (source)
97  , target_ (target)
98  , comm_ (source->getComm())
99  , distributor_ (comm_, out_, plist)
100  {}
101 
102  template <class LocalOrdinal, class GlobalOrdinal, class Node>
103  RCP<ImportExportData<LocalOrdinal, GlobalOrdinal, Node> >
105  {
106  Teuchos::RCP<ImportExportData<LocalOrdinal,GlobalOrdinal,Node> > tData =
108 
109  // Things that stay the same
110  tData->comm_ = comm_;
111  tData->numSameIDs_ = numSameIDs_;
112 
113  // Things that reverse
114  tData->distributor_ = *distributor_.getReverse();
115  tData->permuteToLIDs_ = permuteFromLIDs_;
116  tData->permuteFromLIDs_ = permuteToLIDs_;
117 
118  // Remotes / exports (easy part)
119  tData->exportLIDs_ = remoteLIDs_;
120  tData->remoteLIDs_ = exportLIDs_;
121  tData->exportPIDs_.resize(tData->exportLIDs_.size());
122 
123  // Remotes / exports (hard part) - extract the exportPIDs from the remotes of my distributor
124  size_t NumReceives = distributor_.getNumReceives();
125  ArrayView<const int> ProcsFrom = distributor_.getImagesFrom();
126  ArrayView<const size_t> LengthsFrom = distributor_.getLengthsFrom();
127 
128  for (size_t i = 0, j = 0; i < NumReceives; ++i) {
129  const int pid = ProcsFrom[i];
130  for (size_t k = 0; k < LengthsFrom[i]; ++k) {
131  tData->exportPIDs_[j] = pid;
132  ++j;
133  }
134  }
135  return tData;
136  }
137 
138 
139  template <class LocalOrdinal, class GlobalOrdinal, class Node>
141  {}
142 
143 } // namespace Tpetra
144 
145 // Explicit instantiation macro.
146 // Only invoke this when in the Tpetra namespace.
147 // Most users do not need to use this.
148 //
149 // LO: The local ordinal type.
150 // GO: The global ordinal type.
151 // NODE: The Kokkos Node type.
152 #define TPETRA_IMPORTEXPORTDATA_INSTANT(LO, GO, NODE) \
153  \
154  template class ImportExportData< LO , GO , NODE >;
155 
156 #endif // TPETRA_IMPORTEXPORTDATA_DEF_HPP
size_t numSameIDs_
Number of initial identical indices.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Teuchos::RCP< const Teuchos::Comm< int > > comm_
Communicator over which the source and target objects are distributed.
size_t getNumReceives() const
The number of processes from which we will receive data.
Teuchos::Array< LocalOrdinal > permuteToLIDs_
Index of target Map LIDs to which to permute.
ImportExportData(const Teuchos::RCP< const map_type > &source, const Teuchos::RCP< const map_type > &target)
Constructor.
ArrayView< const size_t > getLengthsFrom() const
Number of values this process will receive from each process.
Teuchos::Array< LocalOrdinal > exportLIDs_
"Outgoing" local indices.
Implementation detail of Import and Export.
Teuchos::Array< LocalOrdinal > permuteFromLIDs_
Index of source Map LIDs from which to permute.
Teuchos::RCP< Teuchos::FancyOStream > out_
Output stream for debug output.
Describes a parallel distribution of objects over processes.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > target_
Target Map of the Import or Export.
Distributor distributor_
Object that actually distributes (sends and receives) data.
ArrayView< const int > getImagesFrom() const
Ranks of the processes sending values to this process.
Teuchos::RCP< ImportExportData< LocalOrdinal, GlobalOrdinal, Node > > reverseClone()
Copy the data, but reverse the direction of the transfer as well as reversing the Distributor...
Teuchos::Array< LocalOrdinal > remoteLIDs_
"Incoming" indices.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > source_
Source Map of the Import or Export.
RCP< Distributor > getReverse() const
A reverse communication plan Distributor.