18#ifdef DEAL_II_WITH_TRILINOS
27# include <Epetra_Export.h>
68 AssertThrow(
static_cast<std::vector<size_type>::size_type
>(ncols) ==
93 graph = std::make_unique<Epetra_FECrsGraph>(View,
97 graph->FillComplete();
106 reinit(m, n, n_entries_per_row);
114 const std::vector<size_type> &n_entries_per_row)
116 reinit(m, n, n_entries_per_row);
124 ,
graph(std::move(other.graph))
142 "Copy constructor only works for empty sparsity patterns."));
151 reinit(parallel_partitioning,
152 parallel_partitioning,
160 const IndexSet ¶llel_partitioning,
162 const std::vector<size_type> &n_entries_per_row)
164 reinit(parallel_partitioning,
165 parallel_partitioning,
173 const IndexSet &col_parallel_partitioning,
177 reinit(row_parallel_partitioning,
178 col_parallel_partitioning,
186 const IndexSet &row_parallel_partitioning,
187 const IndexSet &col_parallel_partitioning,
189 const std::vector<size_type> &n_entries_per_row)
191 reinit(row_parallel_partitioning,
192 col_parallel_partitioning,
200 const IndexSet &col_parallel_partitioning,
205 reinit(row_parallel_partitioning,
206 col_parallel_partitioning,
209 n_max_entries_per_row);
230 const std::vector<size_type> &n_entries_per_row)
245 reinit_sp(
const Epetra_Map &row_map,
246 const Epetra_Map &col_map,
247 const size_type n_entries_per_row,
248 std::unique_ptr<Epetra_Map> &column_space_map,
249 std::unique_ptr<Epetra_FECrsGraph> &graph,
250 std::unique_ptr<Epetra_CrsGraph> &nonlocal_graph)
252 Assert(row_map.IsOneToOne(),
253 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
254 "the maps of different processors."));
255 Assert(col_map.IsOneToOne(),
256 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
257 "the maps of different processors."));
259 nonlocal_graph.reset();
261 column_space_map = std::make_unique<Epetra_Map>(col_map);
265 std::uint64_t(n_entries_per_row) <
266 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
267 ExcMessage(
"The TrilinosWrappers use Epetra internally which "
268 "uses 'signed int' to represent local indices. "
269 "Therefore, only 2,147,483,647 nonzero matrix "
270 "entries can be stored on a single process, "
271 "but you are requesting more than that. "
272 "If possible, use more MPI processes."));
283 if (row_map.Comm().NumProc() > 1)
284 graph = std::make_unique<Epetra_FECrsGraph>(
285 Copy, row_map, n_entries_per_row,
false
293 graph = std::make_unique<Epetra_FECrsGraph>(
294 Copy, row_map, col_map, n_entries_per_row,
false);
300 reinit_sp(
const Epetra_Map &row_map,
301 const Epetra_Map &col_map,
302 const std::vector<size_type> &n_entries_per_row,
303 std::unique_ptr<Epetra_Map> &column_space_map,
304 std::unique_ptr<Epetra_FECrsGraph> &graph,
305 std::unique_ptr<Epetra_CrsGraph> &nonlocal_graph)
307 Assert(row_map.IsOneToOne(),
308 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
309 "the maps of different processors."));
310 Assert(col_map.IsOneToOne(),
311 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
312 "the maps of different processors."));
315 nonlocal_graph.reset();
320 column_space_map = std::make_unique<Epetra_Map>(col_map);
324 std::vector<int> local_entries_per_row(
327 for (
unsigned int i = 0; i < local_entries_per_row.size(); ++i)
328 local_entries_per_row[i] =
331 AssertThrow(std::accumulate(local_entries_per_row.begin(),
332 local_entries_per_row.end(),
334 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
335 ExcMessage(
"The TrilinosWrappers use Epetra internally which "
336 "uses 'signed int' to represent local indices. "
337 "Therefore, only 2,147,483,647 nonzero matrix "
338 "entries can be stored on a single process, "
339 "but you are requesting more than that. "
340 "If possible, use more MPI processes."));
342 if (row_map.Comm().NumProc() > 1)
343 graph = std::make_unique<Epetra_FECrsGraph>(
344 Copy, row_map, local_entries_per_row.data(),
false
352 graph = std::make_unique<Epetra_FECrsGraph>(
353 Copy, row_map, col_map, local_entries_per_row.data(),
false);
358 template <
typename SparsityPatternType>
361 const Epetra_Map &col_map,
362 const SparsityPatternType &sp,
363 const bool exchange_data,
364 std::unique_ptr<Epetra_Map> &column_space_map,
365 std::unique_ptr<Epetra_FECrsGraph> &graph,
366 std::unique_ptr<Epetra_CrsGraph> &nonlocal_graph)
368 nonlocal_graph.reset();
376 column_space_map = std::make_unique<Epetra_Map>(col_map);
378 Assert(row_map.LinearMap() ==
true,
380 "This function only works if the row map is contiguous."));
384 std::vector<int> n_entries_per_row(last_row - first_row);
388 for (size_type row = first_row; row < last_row; ++row)
389 n_entries_per_row[row - first_row] =
390 static_cast<int>(sp.row_length(row));
392 AssertThrow(std::accumulate(n_entries_per_row.begin(),
393 n_entries_per_row.end(),
395 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
396 ExcMessage(
"The TrilinosWrappers use Epetra internally which "
397 "uses 'signed int' to represent local indices. "
398 "Therefore, only 2,147,483,647 nonzero matrix "
399 "entries can be stored on a single process, "
400 "but you are requesting more than that. "
401 "If possible, use more MPI processes."));
403 if (row_map.Comm().NumProc() > 1)
404 graph = std::make_unique<Epetra_FECrsGraph>(Copy,
406 n_entries_per_row.data(),
409 graph = std::make_unique<Epetra_FECrsGraph>(
410 Copy, row_map, col_map, n_entries_per_row.data(),
false);
414 std::vector<TrilinosWrappers::types::int_type> row_indices;
416 for (size_type row = first_row; row < last_row; ++row)
423 row_indices.resize(row_length, -1);
425 typename SparsityPatternType::iterator p = sp.begin(row);
428 for (
int col = 0; col < row_length;)
430 row_indices[col++] = p->column();
431 if (col < row_length)
435 if (exchange_data ==
false)
436 graph->Epetra_CrsGraph::InsertGlobalIndices(row,
444 graph->InsertGlobalIndices(1,
452 const auto &range_map =
453 static_cast<const Epetra_Map &
>(graph->RangeMap());
454 int ierr = graph->GlobalAssemble(*column_space_map, range_map,
true);
457 ierr = graph->OptimizeStorage();
470 parallel_partitioning.
size());
482 const std::vector<size_type> &n_entries_per_row)
485 parallel_partitioning.
size());
496 const IndexSet &col_parallel_partitioning,
501 col_parallel_partitioning.
size());
518 const IndexSet &col_parallel_partitioning,
520 const std::vector<size_type> &n_entries_per_row)
523 col_parallel_partitioning.
size());
540 const IndexSet &col_parallel_partitioning,
546 col_parallel_partitioning.
size());
558 IndexSet nonlocal_partitioner = writable_rows;
560 row_parallel_partitioning.
size());
564 IndexSet tmp = writable_rows & row_parallel_partitioning;
565 Assert(tmp == row_parallel_partitioning,
567 "The set of writable rows passed to this method does not "
568 "contain the locally owned rows, which is not allowed."));
571 nonlocal_partitioner.
subtract_set(row_parallel_partitioning);
574 Epetra_Map nonlocal_map =
577 std::make_unique<Epetra_CrsGraph>(Copy, nonlocal_map, 0);
585 template <
typename SparsityPatternType>
588 const IndexSet &row_parallel_partitioning,
589 const IndexSet &col_parallel_partitioning,
590 const SparsityPatternType &nontrilinos_sparsity_pattern,
592 const bool exchange_data)
595 col_parallel_partitioning.
size());
602 nontrilinos_sparsity_pattern,
611 template <
typename SparsityPatternType>
614 const IndexSet ¶llel_partitioning,
615 const SparsityPatternType &nontrilinos_sparsity_pattern,
617 const bool exchange_data)
620 parallel_partitioning.
size());
622 parallel_partitioning.
size());
624 parallel_partitioning.
size());
629 nontrilinos_sparsity_pattern,
652 graph = std::make_unique<Epetra_FECrsGraph>(*sp.
graph);
662 template <
typename SparsityPatternType>
691 graph = std::make_unique<Epetra_FECrsGraph>(View,
695 graph->FillComplete();
751 const auto &range_map =
752 static_cast<const Epetra_Map &
>(
graph->RangeMap());
759 ierr =
graph->OptimizeStorage();
761 catch (
const int error_code)
766 "The Epetra_CrsGraph::OptimizeStorage() function "
767 "has thrown an error with code " +
768 std::to_string(error_code) +
769 ". You will have to look up the exact meaning of this error "
770 "in the Trilinos source code, but oftentimes, this function "
771 "throwing an error indicates that you are trying to allocate "
772 "more than 2,147,483,647 nonzero entries in the sparsity "
773 "pattern on the local process; this will not work because "
774 "Epetra indexes entries with a simple 'signed int'."));
792 return graph->RowMap().LID(
817 if (
graph->Filled() ==
false)
819 int nnz_present =
graph->NumGlobalIndices(i);
829 int ierr =
graph->ExtractGlobalRowView(trilinos_i,
833 Assert(nnz_present == nnz_extracted,
837 const std::ptrdiff_t local_col_index =
838 std::find(col_indices, col_indices + nnz_present, trilinos_j) -
841 if (local_col_index == nnz_present)
848 int nnz_present =
graph->NumGlobalIndices(i);
856 graph->ExtractMyRowView(trilinos_i, nnz_extracted, col_indices);
859 Assert(nnz_present == nnz_extracted,
863 const std::ptrdiff_t local_col_index =
864 std::find(col_indices, col_indices + nnz_present, trilinos_j) -
867 if (local_col_index == nnz_present)
881 for (
int i = 0; i < static_cast<int>(
local_size()); ++i)
885 graph->ExtractMyRowView(i, num_entries, indices);
886 for (
unsigned int j = 0; j < static_cast<unsigned int>(num_entries);
907 return graph->NumMyRows();
912 std::pair<SparsityPattern::size_type, SparsityPattern::size_type>
934 return graph->MaxNumIndices();
952 return graph->NumMyIndices(local_row);
962 const bool indices_are_sorted)
973 const auto &domain_map =
974 static_cast<const Epetra_Map &
>(
graph->DomainMap());
984 const auto &range_map =
985 static_cast<const Epetra_Map &
>(
graph->RangeMap());
994 const Epetra_MpiComm *mpi_comm =
995 dynamic_cast<const Epetra_MpiComm *
>(&
graph->RangeMap().Comm());
997 return mpi_comm->Comm();
1015 const bool write_extended_trilinos_info)
const
1017 if (write_extended_trilinos_info)
1024 for (
int i = 0; i <
graph->NumMyRows(); ++i)
1026 graph->ExtractMyRowView(i, num_entries, indices);
1027 for (
int j = 0; j < num_entries; ++j)
1031 <<
") " << std::endl;
1048 graph->ExtractMyRowView(row, num_entries, indices);
1052 const ::types::global_dof_index num_entries_ = num_entries;
1059 out <<
static_cast<int>(
1062 << -
static_cast<int>(
1089 const ::SparsityPattern &,
1094 const ::DynamicSparsityPattern &,
1102 const ::SparsityPattern &,
1108 const ::DynamicSparsityPattern &,
size_type n_elements() const
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
void subtract_set(const IndexSet &other)
virtual void resize(const size_type rows, const size_type cols)
std::shared_ptr< const std::vector< size_type > > colnum_cache
::types::global_dof_index size_type
SparsityPattern * sparsity_pattern
size_type row_length(const size_type row) const
std::unique_ptr< Epetra_FECrsGraph > graph
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
unsigned int max_entries_per_row() const
size_type bandwidth() const
void print_gnuplot(std::ostream &out) const
const_iterator end() const
MPI_Comm get_mpi_communicator() const
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
std::uint64_t n_nonzero_elements() const
std::unique_ptr< Epetra_CrsGraph > nonlocal_graph
bool exists(const size_type i, const size_type j) const
const Epetra_Map & domain_partitioner() const
std::pair< size_type, size_type > local_range() const
::types::global_dof_index size_type
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
unsigned int local_size() const
void copy_from(const SparsityPattern &input_sparsity_pattern)
std::unique_ptr< Epetra_Map > column_space_map
const Epetra_Map & range_partitioner() const
const_iterator begin() const
std::size_t memory_consumption() const
SparsityPattern & operator=(const SparsityPattern &input_sparsity_pattern)
bool row_is_stored_locally(const size_type i) const
void reinit(const size_type m, const size_type n, const size_type n_entries_per_row=0)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NOT_IMPLEMENTED()
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
IndexSet complete_index_set(const IndexSet::size_type N)
types::global_dof_index size_type
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)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
TrilinosWrappers::types::int_type n_global_rows(const Epetra_CrsGraph &graph)
TrilinosWrappers::types::int_type min_my_gid(const Epetra_BlockMap &map)
TrilinosWrappers::types::int64_type n_global_entries(const Epetra_CrsGraph &graph)
TrilinosWrappers::types::int64_type n_global_elements(const Epetra_BlockMap &map)
TrilinosWrappers::types::int_type max_my_gid(const Epetra_BlockMap &map)
TrilinosWrappers::types::int_type n_global_cols(const Epetra_CrsGraph &graph)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
const Epetra_Comm & comm_self()
constexpr bool compare_for_equality(const T &t, const U &u)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index