Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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_Distributor.hpp" // avoid error C2027: use of undefined type 'Tpetra::Distributor' at (void) distor below
46 
47 namespace Tpetra {
48  template<class LocalOrdinal, class GlobalOrdinal, class Node>
49  void
51  pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
52  Teuchos::Array<GlobalOrdinal>& exports,
53  const Teuchos::ArrayView<size_t>& numPacketsPerLID,
54  size_t& constantNumPackets,
55  Distributor& distor) const
56  {
57  using Teuchos::Array;
58  typedef LocalOrdinal LO;
59  typedef GlobalOrdinal GO;
60  typedef Map<LO, GO, Node> map_type;
61  const char tfecfFuncName[] = "packAndPrepare";
62  (void) distor; // forestall "unused argument" compiler warning
63 
64  TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
65  exportLIDs.size() != numPacketsPerLID.size(), std::runtime_error,
66  ": exportLIDs and numPacketsPerLID must have the same size.");
67 
68  const map_type& srcMap = * (this->getRowMap ());
69  constantNumPackets = 0;
70 
71  // Set numPacketsPerLID[i] to the number of entries owned by the
72  // calling process in (local) row exportLIDs[i] of the graph, that
73  // the caller wants us to send out. Compute the total number of
74  // packets (that is, entries) owned by this process in all the
75  // rows that the caller wants us to send out.
76  size_t totalNumPackets = 0;
77  Array<GO> row;
78  for (LO i = 0; i < exportLIDs.size (); ++i) {
79  const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
80  size_t row_length = this->getNumEntriesInGlobalRow (GID);
81  numPacketsPerLID[i] = row_length;
82  totalNumPackets += row_length;
83  }
84 
85  exports.resize (totalNumPackets);
86 
87  // Loop again over the rows to export, and pack rows of indices
88  // into the output buffer.
89  size_t exportsOffset = 0;
90  for (LO i = 0; i < exportLIDs.size (); ++i) {
91  const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
92  size_t row_length = this->getNumEntriesInGlobalRow (GID);
93  row.resize (row_length);
94  size_t check_row_length = 0;
95  this->getGlobalRowCopy (GID, row (), check_row_length);
96  typename Array<GO>::const_iterator row_iter = row.begin();
97  typename Array<GO>::const_iterator row_end = row.end();
98  size_t j = 0;
99  for (; row_iter != row_end; ++row_iter, ++j) {
100  exports[exportsOffset+j] = *row_iter;
101  }
102  exportsOffset += row.size ();
103  }
104  }
105 
106  template<class LocalOrdinal, class GlobalOrdinal, class Node>
107  void
109  getLocalRowView (const LocalOrdinal /* lclRow */,
110  Teuchos::ArrayView<const LocalOrdinal>& /* lclColInds */) const
111  {
112  const char prefix[] = "Tpetra::RowGraph::getLocalRowView: ";
113 
114  // Subclasses are expected to implement this method. We would
115  // have made this method pure virtual, but that would have broken
116  // backwards compatibility, since we added the method at least one
117  // major release after introducing this class.
118  TEUCHOS_TEST_FOR_EXCEPTION
119  (! this->supportsRowViews (), std::runtime_error,
120  prefix << "This object does not support row views.");
121  TEUCHOS_TEST_FOR_EXCEPTION
122  (this->supportsRowViews (), std::runtime_error,
123  prefix << "This object claims to support row views, "
124  "but this method is not implemented.");
125  }
126 
127  template<class LocalOrdinal, class GlobalOrdinal, class Node>
128  void
130  getGlobalRowView (const GlobalOrdinal /* gblRow */,
131  Teuchos::ArrayView<const GlobalOrdinal>& /* gblColInds */) const
132  {
133  const char prefix[] = "Tpetra::RowGraph::getGlobalRowView: ";
134 
135  // Subclasses are expected to implement this method. We would
136  // have made this method pure virtual, but that would have broken
137  // backwards compatibility, since we added the method at least one
138  // major release after introducing this class.
139  TEUCHOS_TEST_FOR_EXCEPTION
140  (! this->supportsRowViews (), std::runtime_error,
141  prefix << "This object does not support row views.");
142  TEUCHOS_TEST_FOR_EXCEPTION
143  (this->supportsRowViews (), std::runtime_error,
144  prefix << "This object claims to support row views, "
145  "but this method is not implemented.");
146  }
147 } // namespace Tpetra
148 
149 //
150 // Explicit instantiation macro
151 //
152 // Must be expanded from within the Tpetra namespace!
153 //
154 
155 #define TPETRA_ROWGRAPH_INSTANT(LO,GO,NODE) \
156  template class RowGraph< LO , GO , NODE >;
157 
158 #endif // TPETRA_ROWGRAPH_DEF_HPP
virtual void getGlobalRowView(const GlobalOrdinal gblRow, Teuchos::ArrayView< const GlobalOrdinal > &gblColInds) const
Get a const, non-persisting view of the given global row&#39;s global column indices, as a Teuchos::Array...
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.
Sets up and executes a communication plan for a Tpetra DistObject.
virtual void getLocalRowView(const LocalOrdinal lclRow, Teuchos::ArrayView< const LocalOrdinal > &lclColInds) const
Get a constant, nonpersisting, locally indexed view of the given row of the graph.