Tpetra parallel linear algebra  Version of the Day
Tpetra_RowGraph_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_ROWGRAPH_DEF_HPP
43 #define TPETRA_ROWGRAPH_DEF_HPP
44 
45 #include <Tpetra_RowGraph_decl.hpp>
46 #include <Tpetra_Distributor.hpp> // avoid error C2027: use of undefined type 'Tpetra::Distributor' at (void) distor below
47 
48 namespace Tpetra {
49  template<class LocalOrdinal, class GlobalOrdinal, class Node>
50  void
52  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
53  Teuchos::Array<GlobalOrdinal>& exports,
54  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
55  size_t& constantNumPackets,
56  Distributor& distor) const
57  {
58  using Teuchos::Array;
59  typedef LocalOrdinal LO;
60  typedef GlobalOrdinal GO;
61  typedef Map<LO, GO, Node> map_type;
62  const char tfecfFuncName[] = "packAndPrepare";
63  (void) distor; // forestall "unused argument" compiler warning
64 
65  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
66  exportLIDs.size() != numPacketsPerLID.size(), std::runtime_error,
67  ": exportLIDs and numPacketsPerLID must have the same size.");
68 
69  const map_type& srcMap = * (this->getRowMap ());
70  constantNumPackets = 0;
71 
72  // Set numPacketsPerLID[i] to the number of entries owned by the
73  // calling process in (local) row exportLIDs[i] of the graph, that
74  // the caller wants us to send out. Compute the total number of
75  // packets (that is, entries) owned by this process in all the
76  // rows that the caller wants us to send out.
77  size_t totalNumPackets = 0;
78  Array<GO> row;
79  for (LO i = 0; i < exportLIDs.size (); ++i) {
80  const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
81  size_t row_length = this->getNumEntriesInGlobalRow (GID);
82  numPacketsPerLID[i] = row_length;
83  totalNumPackets += row_length;
84  }
85 
86  exports.resize (totalNumPackets);
87 
88  // Loop again over the rows to export, and pack rows of indices
89  // into the output buffer.
90  size_t exportsOffset = 0;
91  for (LO i = 0; i < exportLIDs.size (); ++i) {
92  const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
93  size_t row_length = this->getNumEntriesInGlobalRow (GID);
94  row.resize (row_length);
95  size_t check_row_length = 0;
96  this->getGlobalRowCopy (GID, row (), check_row_length);
97  typename Array<GO>::const_iterator row_iter = row.begin();
98  typename Array<GO>::const_iterator row_end = row.end();
99  size_t j = 0;
100  for (; row_iter != row_end; ++row_iter, ++j) {
101  exports[exportsOffset+j] = *row_iter;
102  }
103  exportsOffset += row.size ();
104  }
105  }
106 } // namespace Tpetra
107 
108 //
109 // Explicit instantiation macro
110 //
111 // Must be expanded from within the Tpetra namespace!
112 //
113 
114 #define TPETRA_ROWGRAPH_INSTANT(LO,GO,NODE) \
115  \
116  template class RowGraph< LO , GO , NODE >; \
117 
118 #endif // TPETRA_ROWGRAPH_DEF_HPP
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Sets up and executes a communication plan for a Tpetra DistObject.
virtual void pack(const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< GlobalOrdinal > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor) const
Pack this object&#39;s data for Import or Export.