18#ifdef DEAL_II_WITH_TRILINOS
26# include <Epetra_Export.h>
66 AssertThrow(
static_cast<std::vector<size_type>::size_type
>(ncols) ==
91 graph = std::make_unique<Epetra_FECrsGraph>(View,
95 graph->FillComplete();
104 reinit(m, n, n_entries_per_row);
112 const std::vector<size_type> &n_entries_per_row)
114 reinit(m, n, n_entries_per_row);
121 , column_space_map(std::move(other.column_space_map))
122 , graph(std::move(other.graph))
123 , nonlocal_graph(std::move(other.nonlocal_graph))
136 new Epetra_FECrsGraph(View, *column_space_map, *column_space_map, 0))
138 (void)input_sparsity;
141 "Copy constructor only works for empty sparsity patterns."));
150 reinit(parallel_partitioning,
151 parallel_partitioning,
159 const IndexSet ¶llel_partitioning,
161 const std::vector<size_type> &n_entries_per_row)
163 reinit(parallel_partitioning,
164 parallel_partitioning,
172 const IndexSet &col_parallel_partitioning,
176 reinit(row_parallel_partitioning,
177 col_parallel_partitioning,
185 const IndexSet &row_parallel_partitioning,
186 const IndexSet &col_parallel_partitioning,
188 const std::vector<size_type> &n_entries_per_row)
190 reinit(row_parallel_partitioning,
191 col_parallel_partitioning,
199 const IndexSet &col_parallel_partitioning,
204 reinit(row_parallel_partitioning,
205 col_parallel_partitioning,
208 n_max_entries_per_row);
229 const std::vector<size_type> &n_entries_per_row)
244 reinit_sp(
const Epetra_Map &row_map,
245 const Epetra_Map &col_map,
246 const size_type n_entries_per_row,
247 std::unique_ptr<Epetra_Map> &column_space_map,
248 std::unique_ptr<Epetra_FECrsGraph> &graph,
249 std::unique_ptr<Epetra_CrsGraph> &nonlocal_graph)
251 Assert(row_map.IsOneToOne(),
252 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
253 "the maps of different processors."));
254 Assert(col_map.IsOneToOne(),
255 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
256 "the maps of different processors."));
258 nonlocal_graph.reset();
260 column_space_map = std::make_unique<Epetra_Map>(col_map);
264 std::uint64_t(n_entries_per_row) <
265 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
266 ExcMessage(
"The TrilinosWrappers use Epetra internally which "
267 "uses 'signed int' to represent local indices. "
268 "Therefore, only 2,147,483,647 nonzero matrix "
269 "entries can be stored on a single process, "
270 "but you are requesting more than that. "
271 "If possible, use more MPI processes."));
282 if (row_map.Comm().NumProc() > 1)
283 graph = std::make_unique<Epetra_FECrsGraph>(
284 Copy, row_map, n_entries_per_row,
false
292 graph = std::make_unique<Epetra_FECrsGraph>(
293 Copy, row_map, col_map, n_entries_per_row,
false);
299 reinit_sp(
const Epetra_Map &row_map,
300 const Epetra_Map &col_map,
301 const std::vector<size_type> &n_entries_per_row,
302 std::unique_ptr<Epetra_Map> &column_space_map,
303 std::unique_ptr<Epetra_FECrsGraph> &graph,
304 std::unique_ptr<Epetra_CrsGraph> &nonlocal_graph)
306 Assert(row_map.IsOneToOne(),
307 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
308 "the maps of different processors."));
309 Assert(col_map.IsOneToOne(),
310 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
311 "the maps of different processors."));
314 nonlocal_graph.reset();
319 column_space_map = std::make_unique<Epetra_Map>(col_map);
323 std::vector<int> local_entries_per_row(
326 for (
unsigned int i = 0; i < local_entries_per_row.size(); ++i)
327 local_entries_per_row[i] =
330 AssertThrow(std::accumulate(local_entries_per_row.begin(),
331 local_entries_per_row.end(),
333 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
334 ExcMessage(
"The TrilinosWrappers use Epetra internally which "
335 "uses 'signed int' to represent local indices. "
336 "Therefore, only 2,147,483,647 nonzero matrix "
337 "entries can be stored on a single process, "
338 "but you are requesting more than that. "
339 "If possible, use more MPI processes."));
341 if (row_map.Comm().NumProc() > 1)
342 graph = std::make_unique<Epetra_FECrsGraph>(
343 Copy, row_map, local_entries_per_row.data(),
false
351 graph = std::make_unique<Epetra_FECrsGraph>(
352 Copy, row_map, col_map, local_entries_per_row.data(),
false);
357 template <
typename SparsityPatternType>
360 const Epetra_Map &col_map,
361 const SparsityPatternType &sp,
362 const bool exchange_data,
363 std::unique_ptr<Epetra_Map> &column_space_map,
364 std::unique_ptr<Epetra_FECrsGraph> &graph,
365 std::unique_ptr<Epetra_CrsGraph> &nonlocal_graph)
367 nonlocal_graph.reset();
375 column_space_map = std::make_unique<Epetra_Map>(col_map);
377 Assert(row_map.LinearMap() ==
true,
379 "This function only works if the row map is contiguous."));
383 std::vector<int> n_entries_per_row(last_row - first_row);
387 for (size_type row = first_row; row < last_row; ++row)
388 n_entries_per_row[row - first_row] =
389 static_cast<int>(sp.row_length(row));
391 AssertThrow(std::accumulate(n_entries_per_row.begin(),
392 n_entries_per_row.end(),
394 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
395 ExcMessage(
"The TrilinosWrappers use Epetra internally which "
396 "uses 'signed int' to represent local indices. "
397 "Therefore, only 2,147,483,647 nonzero matrix "
398 "entries can be stored on a single process, "
399 "but you are requesting more than that. "
400 "If possible, use more MPI processes."));
402 if (row_map.Comm().NumProc() > 1)
403 graph = std::make_unique<Epetra_FECrsGraph>(Copy,
405 n_entries_per_row.data(),
408 graph = std::make_unique<Epetra_FECrsGraph>(
409 Copy, row_map, col_map, n_entries_per_row.data(),
false);
413 std::vector<TrilinosWrappers::types::int_type> row_indices;
415 for (size_type row = first_row; row < last_row; ++row)
422 row_indices.resize(row_length, -1);
424 typename SparsityPatternType::iterator p = sp.begin(row);
427 for (
int col = 0; col < row_length;)
429 row_indices[col++] = p->column();
430 if (col < row_length)
434 if (exchange_data ==
false)
435 graph->Epetra_CrsGraph::InsertGlobalIndices(row,
443 graph->InsertGlobalIndices(1,
451 const auto &range_map =
452 static_cast<const Epetra_Map &
>(graph->RangeMap());
453 int ierr = graph->GlobalAssemble(*column_space_map, range_map,
true);
456 ierr = graph->OptimizeStorage();
469 parallel_partitioning.
size());
481 const std::vector<size_type> &n_entries_per_row)
484 parallel_partitioning.
size());
495 const IndexSet &col_parallel_partitioning,
500 col_parallel_partitioning.
size());
517 const IndexSet &col_parallel_partitioning,
519 const std::vector<size_type> &n_entries_per_row)
522 col_parallel_partitioning.
size());
539 const IndexSet &col_parallel_partitioning,
545 col_parallel_partitioning.
size());
557 IndexSet nonlocal_partitioner = writable_rows;
559 row_parallel_partitioning.
size());
562 IndexSet tmp = writable_rows & row_parallel_partitioning;
563 Assert(tmp == row_parallel_partitioning,
565 "The set of writable rows passed to this method does not "
566 "contain the locally owned rows, which is not allowed."));
569 nonlocal_partitioner.
subtract_set(row_parallel_partitioning);
572 Epetra_Map nonlocal_map =
575 std::make_unique<Epetra_CrsGraph>(Copy, nonlocal_map, 0);
583 template <
typename SparsityPatternType>
586 const IndexSet &row_parallel_partitioning,
587 const IndexSet &col_parallel_partitioning,
588 const SparsityPatternType &nontrilinos_sparsity_pattern,
590 const bool exchange_data)
593 col_parallel_partitioning.
size());
600 nontrilinos_sparsity_pattern,
609 template <
typename SparsityPatternType>
612 const IndexSet ¶llel_partitioning,
613 const SparsityPatternType &nontrilinos_sparsity_pattern,
615 const bool exchange_data)
618 parallel_partitioning.
size());
620 parallel_partitioning.
size());
622 parallel_partitioning.
size());
627 nontrilinos_sparsity_pattern,
650 graph = std::make_unique<Epetra_FECrsGraph>(*sp.
graph);
660 template <
typename SparsityPatternType>
689 graph = std::make_unique<Epetra_FECrsGraph>(View,
693 graph->FillComplete();
749 const auto &range_map =
750 static_cast<const Epetra_Map &
>(
graph->RangeMap());
757 ierr =
graph->OptimizeStorage();
759 catch (
const int error_code)
764 "The Epetra_CrsGraph::OptimizeStorage() function "
765 "has thrown an error with code " +
766 std::to_string(error_code) +
767 ". You will have to look up the exact meaning of this error "
768 "in the Trilinos source code, but oftentimes, this function "
769 "throwing an error indicates that you are trying to allocate "
770 "more than 2,147,483,647 nonzero entries in the sparsity "
771 "pattern on the local process; this will not work because "
772 "Epetra indexes entries with a simple 'signed int'."));
790 return graph->RowMap().LID(
815 if (
graph->Filled() ==
false)
817 int nnz_present =
graph->NumGlobalIndices(i);
827 int ierr =
graph->ExtractGlobalRowView(trilinos_i,
832 Assert(nnz_present == nnz_extracted,
836 const std::ptrdiff_t local_col_index =
837 std::find(col_indices, col_indices + nnz_present, trilinos_j) -
840 if (local_col_index == nnz_present)
847 int nnz_present =
graph->NumGlobalIndices(i);
855 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
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)
bool is_compressed() const
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
bool in_local_range(const size_type index) 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_NAMESPACE_CLOSE
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)
#define DEAL_II_NOT_IMPLEMENTED()
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)
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()
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)