15#ifdef DEAL_II_TRILINOS_WITH_TPETRA
25# include <Teuchos_FancyOStream.hpp>
34#ifdef DEAL_II_TRILINOS_WITH_TPETRA
43 template <
typename MemorySpace>
60 std::make_shared<std::vector<::types::signed_global_dof_index>>(
85 template <
typename MemorySpace>
97 graph->fillComplete();
102 template <
typename MemorySpace>
108 reinit(m, n, n_entries_per_row);
113 template <
typename MemorySpace>
117 const std::vector<size_type> &n_entries_per_row)
119 reinit(m, n, n_entries_per_row);
124 template <
typename MemorySpace>
129 ,
graph(std::move(other.graph))
136 template <
typename MemorySpace>
144 Utilities::Trilinos::tpetra_comm_self()))
150 (void)input_sparsity;
153 "Copy constructor only works for empty sparsity patterns."));
158 template <
typename MemorySpace>
160 const IndexSet ¶llel_partitioning,
164 reinit(parallel_partitioning,
165 parallel_partitioning,
172 template <
typename MemorySpace>
174 const IndexSet ¶llel_partitioning,
176 const std::vector<size_type> &n_entries_per_row)
178 reinit(parallel_partitioning,
179 parallel_partitioning,
186 template <
typename MemorySpace>
188 const IndexSet &row_parallel_partitioning,
189 const IndexSet &col_parallel_partitioning,
193 reinit(row_parallel_partitioning,
194 col_parallel_partitioning,
201 template <
typename MemorySpace>
203 const IndexSet &row_parallel_partitioning,
204 const IndexSet &col_parallel_partitioning,
206 const std::vector<size_type> &n_entries_per_row)
208 reinit(row_parallel_partitioning,
209 col_parallel_partitioning,
216 template <
typename MemorySpace>
218 const IndexSet &row_parallel_partitioning,
219 const IndexSet &col_parallel_partitioning,
224 reinit(row_parallel_partitioning,
225 col_parallel_partitioning,
228 n_max_entries_per_row);
233 template <
typename MemorySpace>
247 template <
typename MemorySpace>
252 const std::vector<size_type> &n_entries_per_row)
264 template <
typename MemorySpace>
267 template <
typename MemorySpace>
277 Assert(row_map->isOneToOne(),
278 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
279 "the maps of different processors."));
280 Assert(col_map->isOneToOne(),
281 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
282 "the maps of different processors."));
284 nonlocal_graph.reset();
286 column_space_map = col_map;
304 template <
typename MemorySpace>
314 Assert(row_map->isOneToOne(),
315 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
316 "the maps of different processors."));
317 Assert(col_map->isOneToOne(),
318 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
319 "the maps of different processors."));
325 row_map->getGlobalNumElements());
331 Kokkos::DualView<size_t *, typename MemorySpace::kokkos_space>
332 local_entries_per_row(
"local_entries_per_row",
333 row_map->getMaxGlobalIndex() -
334 row_map->getMinGlobalIndex());
336 auto local_entries_per_row_host =
337 local_entries_per_row
338 .template view<Kokkos::DefaultHostExecutionSpace>();
340 std::uint64_t total_size = 0;
341 for (
unsigned int i = 0; i < local_entries_per_row.extent(0); ++i)
343 local_entries_per_row_host(i) =
344 n_entries_per_row[row_map->getMinGlobalIndex() + i];
345 total_size += local_entries_per_row_host[i];
347 local_entries_per_row
348 .template modify<Kokkos::DefaultHostExecutionSpace>();
349 local_entries_per_row
350 .template sync<typename MemorySpace::kokkos_space>();
353 total_size <
static_cast<std::uint64_t
>(
357 "You are requesting to store more elements than global ordinal type allows."));
362 local_entries_per_row);
367 template <
typename SparsityPatternType,
typename MemorySpace>
372 const SparsityPatternType &sp,
373 [[maybe_unused]]
const bool exchange_data,
378 nonlocal_graph.reset();
387 Assert(row_map->isContiguous() ==
true,
389 "This function only works if the row map is contiguous."));
393 row_map->getMaxGlobalIndex() + 1;
394 Teuchos::Array<size_t> n_entries_per_row(last_row - first_row);
397 n_entries_per_row[row - first_row] = sp.row_length(row);
400 std::accumulate(n_entries_per_row.begin(),
401 n_entries_per_row.end(),
403 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
405 "The TrilinosWrappers use Tpetra internally, and "
406 "Trilinos/Tpetra was compiled with 'local ordinate = int'. "
407 "Therefore, 'signed int' is used to represent local indices, "
408 "and only 2,147,483,647 nonzero matrix entries can be stored "
409 "on a single process, but you are requesting more than "
410 "that. Either use more MPI processes or recompile Trilinos "
411 "with 'local ordinate = long long' "));
413 if (row_map->getComm()->getSize() > 1)
427 std::vector<TrilinosWrappers::types::int_type> row_indices;
438 typename SparsityPatternType::iterator p = sp.begin(row);
443 row_indices[col++] = p->column();
448 graph->insertGlobalIndices(row, row_length, row_indices.data());
451 graph->globalAssemble();
456 template <
typename MemorySpace>
463 parallel_partitioning.
size());
464 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> map =
465 parallel_partitioning
466 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
467 communicator,
false);
474 template <
typename MemorySpace>
477 const IndexSet ¶llel_partitioning,
479 const std::vector<size_type> &n_entries_per_row)
482 parallel_partitioning.
size());
483 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> map =
484 parallel_partitioning
485 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
486 communicator,
false);
493 template <
typename MemorySpace>
496 const IndexSet &row_parallel_partitioning,
497 const IndexSet &col_parallel_partitioning,
502 col_parallel_partitioning.
size());
503 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> row_map =
504 row_parallel_partitioning
505 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
506 communicator,
false);
507 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> col_map =
508 col_parallel_partitioning
509 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
510 communicator,
false);
521 template <
typename MemorySpace>
524 const IndexSet &row_parallel_partitioning,
525 const IndexSet &col_parallel_partitioning,
527 const std::vector<size_type> &n_entries_per_row)
530 col_parallel_partitioning.
size());
531 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> row_map =
532 row_parallel_partitioning
533 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
534 communicator,
false);
535 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> col_map =
536 col_parallel_partitioning
537 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
538 communicator,
false);
549 template <
typename MemorySpace>
552 const IndexSet &row_parallel_partitioning,
553 const IndexSet &col_parallel_partitioning,
559 col_parallel_partitioning.
size());
560 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> row_map =
561 row_parallel_partitioning
562 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
563 communicator,
false);
564 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> col_map =
565 col_parallel_partitioning
566 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
567 communicator,
false);
575 IndexSet nonlocal_partitioner = writable_rows;
577 row_parallel_partitioning.
size());
581 IndexSet tmp = writable_rows & row_parallel_partitioning;
582 Assert(tmp == row_parallel_partitioning,
584 "The set of writable rows passed to this method does not "
585 "contain the locally owned rows, which is not allowed."));
588 nonlocal_partitioner.
subtract_set(row_parallel_partitioning);
591 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> nonlocal_map =
593 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
604 template <
typename MemorySpace>
605 template <
typename SparsityPatternType>
608 const IndexSet &row_parallel_partitioning,
609 const IndexSet &col_parallel_partitioning,
610 const SparsityPatternType &nontrilinos_sparsity_pattern,
612 const bool exchange_data)
615 col_parallel_partitioning.
size());
616 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> row_map =
617 row_parallel_partitioning
618 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
619 communicator,
false);
620 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> col_map =
621 col_parallel_partitioning
622 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
623 communicator,
false);
627 nontrilinos_sparsity_pattern,
636 template <
typename MemorySpace>
637 template <
typename SparsityPatternType>
640 const IndexSet ¶llel_partitioning,
641 const SparsityPatternType &nontrilinos_sparsity_pattern,
643 const bool exchange_data)
646 parallel_partitioning.
size());
648 parallel_partitioning.
size());
650 parallel_partitioning.
size());
651 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> map =
652 parallel_partitioning
653 .template make_tpetra_map_rcp<TpetraTypes::NodeType<MemorySpace>>(
654 communicator,
false);
658 nontrilinos_sparsity_pattern,
667 template <
typename MemorySpace>
678 template <
typename MemorySpace>
698 template <
typename MemorySpace>
699 template <
typename SparsityPatternType>
704 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>>
rows =
710 Teuchos::RCP<TpetraTypes::MapType<MemorySpace>> columns =
723 template <
typename MemorySpace>
740 graph->fillComplete();
747 template <
typename MemorySpace>
754# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
771 graph->getRangeMap()->getGlobalNumElements())
777# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
785# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
786 Assert(nonlocal_graph->getRowMap()->getLocalNumElements() == 0 ||
787 column_space_map->getGlobalNumElements() == 0,
790 Assert(nonlocal_graph->getRowMap()->getNodeNumElements() == 0 ||
791 column_space_map->getGlobalNumElements() == 0,
795 nonlocal_graph->fillComplete(column_space_map, graph->getRowMap());
797 graph->fillComplete(column_space_map, graph->getRowMap());
808 template <
typename MemorySpace>
812 return graph->getRowMap()->getLocalElement(i) !=
813 Teuchos::OrdinalTraits<int>::invalid();
818 template <
typename MemorySpace>
827 const auto trilinos_i =
graph->getRowMap()->getLocalElement(i);
828 const auto trilinos_j =
graph->getColMap()->getLocalElement(j);
834 graph->getLocalRowView(trilinos_i, col_indices);
838 std::find(col_indices.data(),
839 col_indices.data() + col_indices.size(),
843 return static_cast<std::size_t
>(local_col_index) != col_indices.size();
848 template <
typename MemorySpace>
853 for (
int i = 0; i < static_cast<int>(
local_size()); ++i)
858 graph->getLocalRowView(i, indices);
859 const auto num_entries = indices.size();
860 for (
unsigned int j = 0; j < static_cast<unsigned int>(num_entries);
877 template <
typename MemorySpace>
881# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
882 return graph->getLocalNumRows();
884 return graph->getNodeNumRows();
890 template <
typename MemorySpace>
891 std::pair<typename SparsityPattern<MemorySpace>::size_type,
903 template <
typename MemorySpace>
907 return graph->getGlobalNumEntries();
912 template <
typename MemorySpace>
916# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
917 return graph->getLocalMaxNumRowEntries();
919 return graph->getNodeMaxNumRowEntries();
925 template <
typename MemorySpace>
934 graph->getRowMap()->getLocalElement(row);
939 return graph->getNumEntriesInLocalRow(local_row);
946 template <
typename MemorySpace>
949 const ::types::global_dof_index &row,
951 const bool indices_are_sorted)
958 template <
typename MemorySpace>
959 Teuchos::RCP<const typename TpetraTypes::MapType<MemorySpace>>
962 return graph->getDomainMap();
967 template <
typename MemorySpace>
968 Teuchos::RCP<const typename TpetraTypes::MapType<MemorySpace>>
971 return graph->getRangeMap();
976 template <
typename MemorySpace>
981 graph->getRangeMap()->getComm());
986 template <
typename MemorySpace>
987 Teuchos::RCP<const Teuchos::Comm<int>>
990 return graph->getRangeMap()->getComm();
998 template <
typename MemorySpace>
1002 const bool write_extended_trilinos_info)
const
1004 if (write_extended_trilinos_info)
1007 Teuchos::getFancyOStream(Teuchos::RCP(&out,
false));
1008 graph->describe(*fancy_stream);
1012# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1013 for (
unsigned int i = 0; i <
graph->getLocalNumRows(); ++i)
1015 for (
unsigned int i = 0; i <
graph->getNodeNumRows(); ++i)
1020 graph->getLocalRowView(i, indices);
1021 int num_entries = indices.size();
1022 for (
int j = 0; j < num_entries; ++j)
1023 out <<
"(" <<
graph->getRowMap()->getGlobalElement(i) <<
","
1024 <<
graph->getColMap()->getGlobalElement(indices[j]) <<
") "
1034 template <
typename MemorySpace>
1040 for (
unsigned int row = 0; row <
local_size(); ++row)
1045 graph->getLocalRowView(row, indices);
1046 int num_entries = indices.size();
1050 const ::types::signed_global_dof_index num_entries_ =
1059 out <<
static_cast<int>(
1060 graph->getColMap()->getGlobalElement(indices[j]))
1062 << -
static_cast<int>(
graph->getRowMap()->getGlobalElement(row))
1070 template <
typename MemorySpace>
1085 const ::SparsityPattern &);
1088 const ::DynamicSparsityPattern &);
1093 const ::SparsityPattern &,
1099 const ::DynamicSparsityPattern &,
1108 const ::SparsityPattern &,
1115 const ::DynamicSparsityPattern &,
1124 const ::SparsityPattern &);
1127 const ::DynamicSparsityPattern &);
1132 const ::SparsityPattern &,
1138 const ::DynamicSparsityPattern &,
1147 const ::SparsityPattern &,
1154 const ::DynamicSparsityPattern &,
size_type n_elements() const
void subtract_set(const IndexSet &other)
std::shared_ptr< std::vector<::types::signed_global_dof_index > > colnum_cache
SparsityPattern< MemorySpace > * sparsity_pattern
Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > graph
Teuchos::RCP< const Teuchos::Comm< int > > get_teuchos_mpi_communicator() const
std::pair< size_type, size_type > local_range() const
Teuchos::RCP< const TpetraTypes::MapType< MemorySpace > > range_partitioner() const
void copy_from(const SparsityPattern< MemorySpace > &input_sparsity_pattern)
SparsityPattern< MemorySpace > & operator=(const SparsityPattern< MemorySpace > &input_sparsity_pattern)
::types::global_dof_index size_type
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
unsigned int max_entries_per_row() const
Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > nonlocal_graph
const_iterator end() const
void print_gnuplot(std::ostream &out) const
MPI_Comm get_mpi_communicator() const
Teuchos::RCP< const TpetraTypes::MapType< MemorySpace > > domain_partitioner() const
std::uint64_t n_nonzero_elements() const
size_type bandwidth() const
bool exists(const size_type i, const size_type j) const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > column_space_map
void reinit(const size_type m, const size_type n, const size_type n_entries_per_row)
unsigned int local_size() const
virtual void add_row_entries(const ::types::global_dof_index &row, const ArrayView< const ::types::global_dof_index > &columns, const bool indices_are_sorted=false) override
const_iterator begin() const
size_type row_length(const size_type row) const
std::size_t memory_consumption() const
bool row_is_stored_locally(const size_type i) const
virtual void resize(const size_type rows, const size_type cols)
#define DEAL_II_NAMESPACE_OPEN
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NOT_IMPLEMENTED()
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
IndexSet complete_index_set(const IndexSet::size_type N)
void reinit_sp(const Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > &row_map, const Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > &col_map, const size_type< MemorySpace > n_entries_per_row, Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > &column_space_map, Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > &graph, Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > &nonlocal_graph)
typename SparsityPattern< MemorySpace >::size_type size_type
Tpetra::CrsGraph< LO, GO, NodeType< MemorySpace > > GraphType
Tpetra::Map< LO, GO, NodeType< MemorySpace > > MapType
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
Teuchos::RCP< T > make_rcp(Args &&...args)
MPI_Comm teuchos_comm_to_mpi_comm(const Teuchos::RCP< const Teuchos::Comm< int > > &teuchos_comm)
const Teuchos::RCP< const Teuchos::Comm< int > > & tpetra_comm_self()
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
int signed_global_dof_index