10 #ifndef STOKHOS_TPETRA_UTILITIES_MP_VECTOR_HPP
11 #define STOKHOS_TPETRA_UTILITIES_MP_VECTOR_HPP
14 #include "Tpetra_Map.hpp"
15 #include "Tpetra_MultiVector.hpp"
16 #include "Tpetra_CrsGraph.hpp"
17 #include "Tpetra_CrsMatrix.hpp"
23 template <
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
27 using Tpetra::global_size_t;
33 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Map;
36 const global_size_t num_global_entries = map.getGlobalNumElements();
37 const size_t num_local_entries = map.getLocalNumElements();
40 map.getLocalElementList();
43 const global_size_t flat_num_global_entries = num_global_entries*block_size;
44 const size_t flat_num_local_entries = num_local_entries * block_size;
47 for (
size_t i=0; i<num_local_entries; ++i)
49 flat_element_list[i*block_size+
j] = element_list[i]*block_size+
j;
53 rcp(
new Map(flat_num_global_entries, flat_element_list(),
54 flat_index_base, map.getComm()));
63 template <
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
66 const Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node >& graph,
67 Teuchos::RCP<
const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node > >& flat_domain_map,
68 Teuchos::RCP<
const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node > >& flat_range_map,
74 typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Map;
75 typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Graph;
76 typedef typename Graph::local_graph_device_type::row_map_type::non_const_type RowPtrs;
77 typedef typename Graph::local_graph_device_type::entries_type::non_const_type LocalIndices;
95 if (graph.getRangeMap() == graph.getRowMap())
96 flat_row_map = flat_range_map;
101 auto row_offsets = graph.getLocalRowPtrsHost();
102 auto col_indices = graph.getLocalIndicesHost();
103 const size_t num_row = graph.getLocalNumRows();
104 const size_t num_col_indices = col_indices.size();
105 RowPtrs flat_row_offsets(
"row_ptrs", num_row*block_size+1);
106 LocalIndices flat_col_indices(
"col_indices", num_col_indices * block_size);
109 for (
size_t row=0; row<num_row; ++row) {
110 const size_t row_beg = row_offsets[row];
111 const size_t row_end = row_offsets[row+1];
112 const size_t num_col = row_end - row_beg;
114 const size_t flat_row = row*block_size +
j;
115 const size_t flat_row_beg = row_beg*block_size + j*num_col;
116 flat_row_offsets_host[flat_row] = flat_row_beg;
117 for (
size_t entry=0; entry<num_col; ++entry) {
120 flat_col_indices_host[flat_row_beg+entry] = flat_col;
124 flat_row_offsets_host[num_row*block_size] = num_col_indices*block_size;
130 rcp(
new Graph(flat_row_map, flat_col_map,
131 flat_row_offsets, flat_col_indices));
132 flat_graph->fillComplete(flat_domain_map, flat_range_map);
139 template <
typename Storage,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
143 const Teuchos::RCP<
const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& flat_map
146 using FlatVector = Tpetra::MultiVector<BaseScalar, LocalOrdinal, GlobalOrdinal, Node>;
149 typename FlatVector::wrapped_dual_view_type flat_vals(vec.getWrappedDualView());
152 return Teuchos::make_rcp<FlatVector>(flat_map, flat_vals);
156 template <
typename Storage,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
160 Teuchos::RCP<
const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& flat_map
170 template <
typename Storage,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
174 const Teuchos::RCP<
const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& flat_map
179 )->getVectorNonConst(0);
182 template <
typename Storage,
typename LocalOrdinal,
typename GlobalOrdinal,
typename Node>
186 Teuchos::RCP<
const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>& flat_map
205 const Teuchos::RCP<
const Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >& flat_graph,
214 typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Matrix;
215 typedef Tpetra::CrsMatrix<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> FlatMatrix;
221 const size_t num_rows = mat.getLocalNumRows();
222 const size_t max_cols = mat.getLocalMaxNumRowEntries();
223 typename Matrix::local_inds_host_view_type indices, flat_indices;
224 typename Matrix::values_host_view_type values;
226 for (
size_t row=0; row<num_rows; ++row) {
227 mat.getLocalRowView(row, indices, values);
228 const size_t num_col = mat.getNumEntriesInLocalRow(row);
231 for (
size_t j=0;
j<num_col; ++
j)
232 flat_values[
j] = values[
j].coeff(i);
233 flat_graph->getLocalRowView(flat_row, flat_indices);
234 flat_mat->replaceLocalValues(flat_row, Kokkos::Compat::getConstArrayView(flat_indices),
235 flat_values(0, num_col));
238 flat_mat->fillComplete(flat_graph->getDomainMap(),
239 flat_graph->getRangeMap());
246 #endif // STOKHOS_TPETRA_UTILITIES_MP_VECTOR_HPP
Teuchos::RCP< Tpetra::CrsMatrix< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_matrix(const Tpetra::CrsMatrix< Sacado::UQ::PCE< Storage >, LocalOrdinal, GlobalOrdinal, Node > &mat, const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &flat_graph, const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &cijk_graph, const CijkType &cijk_dev)
Stokhos::StandardStorage< int, double > Storage
Teuchos::RCP< const Tpetra::MultiVector< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_vector_view(const Tpetra::MultiVector< Sacado::UQ::PCE< Storage >, LocalOrdinal, GlobalOrdinal, Node > &vec, const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_map)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > create_flat_mp_graph(const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_domain_map, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_range_map, const LocalOrdinal block_size)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node
Teuchos::RCP< Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > create_flat_map(const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map, const LocalOrdinal block_size)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror_view(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)