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
45namespace Tpetra {
46 template<class LocalOrdinal, class GlobalOrdinal, class Node>
47 void
49 pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
50 Teuchos::Array<GlobalOrdinal>& exports,
51 const Teuchos::ArrayView<size_t>& numPacketsPerLID,
52 size_t& constantNumPackets) const
53 {
54 using Teuchos::Array;
55 typedef LocalOrdinal LO;
56 typedef GlobalOrdinal GO;
57 typedef Map<LO, GO, Node> map_type;
58 const char tfecfFuncName[] = "packAndPrepare";
59
60 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
61 exportLIDs.size() != numPacketsPerLID.size(), std::runtime_error,
62 ": exportLIDs and numPacketsPerLID must have the same size.");
63
64 const map_type& srcMap = * (this->getRowMap ());
65 constantNumPackets = 0;
66
67 // Set numPacketsPerLID[i] to the number of entries owned by the
68 // calling process in (local) row exportLIDs[i] of the graph, that
69 // the caller wants us to send out. Compute the total number of
70 // packets (that is, entries) owned by this process in all the
71 // rows that the caller wants us to send out.
72 size_t totalNumPackets = 0;
73 nonconst_global_inds_host_view_type row;
74 for (LO i = 0; i < exportLIDs.size (); ++i) {
75 const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
76 size_t row_length = this->getNumEntriesInGlobalRow (GID);
77 numPacketsPerLID[i] = row_length;
78 totalNumPackets += row_length;
79 }
80
81 exports.resize (totalNumPackets);
82
83 // Loop again over the rows to export, and pack rows of indices
84 // into the output buffer.
85 size_t exportsOffset = 0;
86 for (LO i = 0; i < exportLIDs.size (); ++i) {
87 const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
88 size_t row_length = this->getNumEntriesInGlobalRow (GID);
89 Kokkos::resize(row,row_length);
90 size_t check_row_length = 0;
91 this->getGlobalRowCopy (GID, row, check_row_length);
92
93 for (size_t j=0; j<row_length; ++j) {
94 exports[exportsOffset+j] = row[j];
95 }
96 exportsOffset += row.extent(0);
97 }
98 }
99
100#ifdef TPETRA_ENABLE_DEPRECATED_CODE
101 template<class LocalOrdinal, class GlobalOrdinal, class Node>
102 void
104 getLocalRowView (const LocalOrdinal /* lclRow */,
105 Teuchos::ArrayView<const LocalOrdinal>& /* lclColInds */) const
106 {
107 const char prefix[] = "Tpetra::RowGraph::getLocalRowView: ";
108
109 // Subclasses are expected to implement this method. We would
110 // have made this method pure virtual, but that would have broken
111 // backwards compatibility, since we added the method at least one
112 // major release after introducing this class.
113 TEUCHOS_TEST_FOR_EXCEPTION
114 (! this->supportsRowViews (), std::runtime_error,
115 prefix << "This object does not support row views.");
116 TEUCHOS_TEST_FOR_EXCEPTION
117 (this->supportsRowViews (), std::runtime_error,
118 prefix << "This object claims to support row views, "
119 "but this method is not implemented.");
120 }
121
122 template<class LocalOrdinal, class GlobalOrdinal, class Node>
123 void
125 getGlobalRowView (const GlobalOrdinal /* gblRow */,
126 Teuchos::ArrayView<const GlobalOrdinal>& /* gblColInds */) const
127 {
128 const char prefix[] = "Tpetra::RowGraph::getGlobalRowView: ";
129
130 // Subclasses are expected to implement this method. We would
131 // have made this method pure virtual, but that would have broken
132 // backwards compatibility, since we added the method at least one
133 // major release after introducing this class.
134 TEUCHOS_TEST_FOR_EXCEPTION
135 (! this->supportsRowViews (), std::runtime_error,
136 prefix << "This object does not support row views.");
137 TEUCHOS_TEST_FOR_EXCEPTION
138 (this->supportsRowViews (), std::runtime_error,
139 prefix << "This object claims to support row views, "
140 "but this method is not implemented.");
141 }
142#endif // TPETRA_ENABLE_DEPRECATED_CODE
143
144} // namespace Tpetra
145
146//
147// Explicit instantiation macro
148//
149// Must be expanded from within the Tpetra namespace!
150//
151
152#define TPETRA_ROWGRAPH_INSTANT(LO,GO,NODE) \
153 template class RowGraph< LO , GO , NODE >;
154
155#endif // TPETRA_ROWGRAPH_DEF_HPP
virtual void pack(const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< GlobalOrdinal > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets) const
Pack this object's data for Import or Export.
virtual void getGlobalRowView(const GlobalOrdinal gblRow, global_inds_host_view_type &gblColInds) const =0
Get a const, non-persisting view of the given global row's global column indices, as a Teuchos::Array...
virtual void getLocalRowView(const LocalOrdinal lclRow, local_inds_host_view_type &lclColInds) const =0
Get a constant, nonpersisting, locally indexed view of the given row of the graph.
Namespace Tpetra contains the class and methods constituting the Tpetra library.