24#ifdef DEAL_II_WITH_TRILINOS
25# ifdef DEAL_II_WITH_MPI
26# include <Epetra_MpiComm.h>
28# include <Epetra_Map.h>
29# include <Epetra_SerialComm.h>
36#ifdef DEAL_II_WITH_TRILINOS
41# ifdef DEAL_II_WITH_64BIT_INDICES
45 , index_space_size(1 + map.MaxAllGID64())
46 , largest_range(
numbers::invalid_unsigned_int)
48 Assert(map.MinAllGID64() == 0,
50 "The Epetra_BlockMap does not contain the global index 0, "
51 "which means some entries are not present on any processor."));
58 const size_type n_indices = map.NumMyElements();
60 reinterpret_cast<size_type *
>(map.MyGlobalElements64());
61 add_indices(indices, indices + n_indices);
72 , index_space_size(1 + map.MaxAllGID())
73 , largest_range(
numbers::invalid_unsigned_int)
75 Assert(map.MinAllGID() == 0,
77 "The Epetra_BlockMap does not contain the global index 0, "
78 "which means some entries are not present on any processor."));
85 const size_type n_indices = map.NumMyElements();
86 unsigned int * indices =
87 reinterpret_cast<unsigned int *
>(map.MyGlobalElements());
113 std::vector<Range>::iterator store =
ranges.begin();
114 for (std::vector<Range>::iterator i =
ranges.begin(); i !=
ranges.end();)
116 std::vector<Range>::iterator next = i;
123 while (next !=
ranges.end() && (next->begin <= last_index))
125 last_index =
std::max(last_index, next->end);
131 *store =
Range(first_index, last_index);
135 if (store !=
ranges.end())
137 std::vector<Range> new_ranges(
ranges.begin(), store);
142 size_type next_index = 0, largest_range_size = 0;
143 for (std::vector<Range>::iterator i =
ranges.begin(); i !=
ranges.end(); ++i)
147 i->nth_index_in_set = next_index;
148 next_index += (i->end - i->begin);
149 if (i->end - i->begin > largest_range_size)
151 largest_range_size = i->end - i->begin;
173 std::vector<Range>::const_iterator r1 =
ranges.begin(),
181 if (r1->end <= r2->begin)
183 else if (r2->end <= r1->begin)
188 Assert(((r1->begin <= r2->begin) && (r1->end > r2->begin)) ||
189 ((r2->begin <= r1->begin) && (r2->end > r1->begin)),
193 result.add_range(
std::max(r1->begin, r2->begin),
199 if (r1->end <= r2->end)
217 ExcMessage(
"End index needs to be larger or equal to begin index!"));
221 std::vector<Range>::const_iterator r1 =
ranges.begin();
223 while (r1 !=
ranges.end())
225 if ((r1->end >
begin) && (r1->begin <
end))
230 else if (r1->begin >=
end)
242 const std::vector<types::global_dof_index> &n_indices_per_block)
const
244 std::vector<IndexSet> partitioned;
245 const unsigned int n_blocks = n_indices_per_block.size();
247 partitioned.reserve(n_blocks);
249 for (
const auto n_block_indices : n_indices_per_block)
251 partitioned.push_back(this->
get_view(start, start + n_block_indices));
252 start += n_block_indices;
257 for (
const auto &partition : partitioned)
259 sum += partition.size();
277 std::vector<Range> new_ranges;
279 std::vector<Range>::iterator own_it =
ranges.begin();
280 std::vector<Range>::iterator other_it = other.
ranges.begin();
282 while (own_it !=
ranges.end() && other_it != other.
ranges.end())
285 if (own_it->end <= other_it->begin)
287 new_ranges.push_back(*own_it);
292 if (own_it->begin >= other_it->end)
300 if (own_it->begin < other_it->begin)
302 Range r(own_it->begin, other_it->begin);
304 new_ranges.push_back(r);
309 own_it->begin = other_it->end;
310 if (own_it->begin > own_it->end)
312 own_it->begin = own_it->end;
321 for (; own_it !=
ranges.end(); ++own_it)
322 new_ranges.push_back(*own_it);
327 const std::vector<Range>::iterator
end = new_ranges.end();
328 for (std::vector<Range>::iterator it = new_ranges.begin(); it !=
end; ++it)
340 for (
const auto el : *
this)
341 set.add_indices(other, el * other.
size());
353 "pop_back() failed, because this IndexSet contains no entries."));
371 "pop_front() failed, because this IndexSet contains no entries."));
399 boost::container::small_vector<std::pair<size_type, size_type>, 200>
401 const bool ranges_are_sorted)
403 if (!ranges_are_sorted)
404 std::sort(tmp_ranges.begin(), tmp_ranges.end());
414 if (tmp_ranges.size() > 9)
417 tmp_set.
ranges.reserve(tmp_ranges.size());
418 for (
const auto &i : tmp_ranges)
423 if (this->
ranges.size() <= 1)
425 if (this->
ranges.size() == 1)
427 std::swap(*
this, tmp_set);
433 for (
const auto &i : tmp_ranges)
442 if ((
this == &other) && (offset == 0))
445 if (other.
ranges.size() != 0)
453 std::vector<Range>::const_iterator r1 =
ranges.begin(),
454 r2 = other.
ranges.begin();
456 std::vector<Range> new_ranges;
463 if (r2 == other.
ranges.end() ||
464 (r1 !=
ranges.end() && r1->end < (r2->begin + offset)))
466 new_ranges.push_back(*r1);
469 else if (r1 ==
ranges.end() || (r2->end + offset) < r1->begin)
471 new_ranges.emplace_back(r2->begin + offset, r2->end + offset);
479 std::max(r1->end, r2->end + offset));
480 new_ranges.push_back(next);
497 out <<
size() <<
" ";
498 out <<
ranges.size() << std::endl;
499 std::vector<Range>::const_iterator r =
ranges.begin();
500 for (; r !=
ranges.end(); ++r)
502 out << r->begin <<
" " << r->end << std::endl;
514 unsigned int n_ranges;
519 for (
unsigned int i = 0; i < n_ranges; ++i)
536 std::size_t n_ranges =
ranges.size();
537 out.write(
reinterpret_cast<const char *
>(&n_ranges),
sizeof(n_ranges));
538 if (
ranges.empty() ==
false)
539 out.write(
reinterpret_cast<const char *
>(&*
ranges.begin()),
548 std::size_t n_ranges;
549 in.read(
reinterpret_cast<char *
>(&
size),
sizeof(
size));
550 in.read(
reinterpret_cast<char *
>(&n_ranges),
sizeof(n_ranges));
556 in.read(
reinterpret_cast<char *
>(&*
ranges.begin()),
579 std::vector<Range>::const_iterator p = std::upper_bound(
587 return ((index >= p->begin) && (index < p->end));
595 return (p->end > index);
612 return p->begin + (n - p->nth_index_in_set);
624 std::vector<Range>::const_iterator p =
628 if (p ==
ranges.end() || p->end == n || p->begin > n)
634 return (n - p->begin) + p->nth_index_in_set;
648 std::vector<Range>::const_iterator main_range =
651 Range r(global_index, global_index + 1);
654 std::vector<Range>::const_iterator range_begin, range_end;
655 if (global_index < main_range->
begin)
657 range_begin =
ranges.begin();
658 range_end = main_range;
662 range_begin = main_range;
668 const std::vector<Range>::const_iterator p =
681 if (global_index < p->
begin)
684 return {
this,
static_cast<size_type>(p -
ranges.begin()), global_index};
689std::vector<IndexSet::size_type>
694 std::vector<size_type> indices;
697 for (
const auto &range :
ranges)
698 for (
size_type entry = range.begin; entry < range.end; ++entry)
699 indices.push_back(entry);
716#ifdef DEAL_II_WITH_TRILINOS
717# ifdef DEAL_II_TRILINOS_WITH_TPETRA
719Tpetra::Map<int, types::signed_global_dof_index>
721 const bool overlapping)
const
732 ExcMessage(
"You are trying to create an Tpetra::Map object "
733 "that partitions elements of an index set "
734 "between processors. However, the union of the "
735 "index sets on different processors does not "
736 "contain all indices exactly once: the sum of "
737 "the number of entries the various processors "
738 "want to store locally is " +
739 std::to_string(n_global_elements) +
740 " whereas the total size of the object to be "
742 std::to_string(
size()) +
743 ". In other words, there are "
744 "either indices that are not spoken for "
745 "by any processor, or there are indices that are "
746 "claimed by multiple processors."));
755 return Tpetra::Map<int, types::signed_global_dof_index>(
759# ifdef DEAL_II_WITH_MPI
760 Teuchos::rcp(
new Teuchos::MpiComm<int>(communicator))
762 Teuchos::rcp(
new Teuchos::Comm<int>())
768 std::vector<types::signed_global_dof_index> int_indices(indices.size());
769 std::copy(indices.begin(), indices.end(), int_indices.begin());
770 const Teuchos::ArrayView<types::signed_global_dof_index> arr_view(
772 return Tpetra::Map<int, types::signed_global_dof_index>(
776# ifdef DEAL_II_WITH_MPI
777 Teuchos::rcp(
new Teuchos::MpiComm<int>(communicator))
779 Teuchos::rcp(
new Teuchos::Comm<int>())
790 const bool overlapping)
const
801 ExcMessage(
"You are trying to create an Epetra_Map object "
802 "that partitions elements of an index set "
803 "between processors. However, the union of the "
804 "index sets on different processors does not "
805 "contain all indices exactly once: the sum of "
806 "the number of entries the various processors "
807 "want to store locally is " +
808 std::to_string(n_global_elements) +
809 " whereas the total size of the object to be "
811 std::to_string(
size()) +
812 ". In other words, there are "
813 "either indices that are not spoken for "
814 "by any processor, or there are indices that are "
815 "claimed by multiple processors."));
828# ifdef DEAL_II_WITH_MPI
829 Epetra_MpiComm(communicator)
845# ifdef DEAL_II_WITH_MPI
846 Epetra_MpiComm(communicator)
856#ifdef DEAL_II_WITH_PETSC
860 std::vector<size_type> indices;
863 PetscInt n = indices.size();
864 std::vector<PetscInt> pindices(indices.begin(), indices.end());
867 PetscErrorCode ierr =
868 ISCreateGeneral(communicator, n, pindices.data(), PETSC_COPY_VALUES, &is);
884 if (n_global_elements !=
size())
887 if (n_global_elements == 0)
890#ifdef DEAL_II_WITH_MPI
892 const bool all_contiguous =
897 bool is_globally_ascending =
true;
904 const std::vector<types::global_dof_index> global_dofs =
914 for (; index < global_dofs.size(); ++index)
919 if (new_dof <= old_dof)
921 is_globally_ascending =
false;
931 int is_ascending = is_globally_ascending ? 1 : 0;
932 int ierr = MPI_Bcast(&is_ascending, 1, MPI_INT, 0, communicator);
935 return (is_ascending == 1);
ElementIterator begin() const
bool is_element_binary_search(const size_type local_index) const
size_type index_within_set_binary_search(const size_type global_index) const
IS make_petsc_is(const MPI_Comm communicator=MPI_COMM_WORLD) const
bool is_ascending_and_one_to_one(const MPI_Comm communicator) const
bool is_contiguous() const
ElementIterator at(const size_type global_index) const
void fill_index_vector(std::vector< size_type > &indices) const
std::vector< IndexSet > split_by_block(const std::vector< types::global_dof_index > &n_indices_per_block) const
size_type n_elements() const
void add_range_lower_bound(const Range &range)
ElementIterator begin() const
void set_size(const size_type size)
void read(std::istream &in)
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
IndexSet tensor_product(const IndexSet &other) const
void write(std::ostream &out) const
void block_read(std::istream &in)
void add_ranges_internal(boost::container::small_vector< std::pair< size_type, size_type >, 200 > &tmp_ranges, const bool ranges_are_sorted)
IntervalIterator begin_intervals() const
Tpetra::Map< int, types::signed_global_dof_index > make_tpetra_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
std::vector< Range > ranges
void subtract_set(const IndexSet &other)
ElementIterator end() const
Threads::Mutex compress_mutex
size_type index_space_size
void block_write(std::ostream &out) const
IndexSet get_view(const size_type begin, const size_type end) const
void add_range(const size_type begin, const size_type end)
std::size_t memory_consumption() const
size_type nth_index_in_set_binary_search(const size_type local_index) const
std::vector< size_type > get_index_vector() const
types::global_dof_index size_type
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
IndexSet operator&(const IndexSet &is) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
types::global_dof_index size_type
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > memory_consumption(const T &t)
T sum(const T &t, const MPI_Comm mpi_communicator)
T min(const T &t, const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
std::vector< T > gather(const MPI_Comm comm, const T &object_to_send, const unsigned int root_process=0)
std::string compress(const std::string &input)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
const types::global_dof_index invalid_dof_index
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
static bool end_compare(const IndexSet::Range &x, const IndexSet::Range &y)
static bool nth_index_compare(const IndexSet::Range &x, const IndexSet::Range &y)
size_type nth_index_in_set