Skip to content

Commit

Permalink
review updates:
Browse files Browse the repository at this point in the history
- documentation
- make partition checks const
- test fixes

Co-authored-by: Gregor Olenik <[email protected]>
  • Loading branch information
MarcelKoch and greole committed Jan 12, 2023
1 parent 6d68a70 commit cbb11c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions core/distributed/partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ void Partition<LocalIndexType, GlobalIndexType>::finalize_construction()


template <typename LocalIndexType, typename GlobalIndexType>
bool Partition<LocalIndexType, GlobalIndexType>::has_connected_parts()
bool Partition<LocalIndexType, GlobalIndexType>::has_connected_parts() const
{
return this->get_num_parts() - this->get_num_empty_parts() ==
this->get_num_ranges();
}


template <typename LocalIndexType, typename GlobalIndexType>
bool Partition<LocalIndexType, GlobalIndexType>::has_ordered_parts()
bool Partition<LocalIndexType, GlobalIndexType>::has_ordered_parts() const
{
if (this->has_connected_parts()) {
auto exec = this->get_executor();
Expand Down
4 changes: 2 additions & 2 deletions include/ginkgo/core/distributed/partition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class Partition
*
* @return true if each part has no more than one contiguous range.
*/
bool has_connected_parts();
bool has_connected_parts() const;

/**
* Checks if the ranges are ordered by their part index.
Expand All @@ -240,7 +240,7 @@ class Partition
*
* @return true if the ranges are ordered by their part index.
*/
bool has_ordered_parts();
bool has_ordered_parts() const;

/**
* Builds a partition from a given mapping global_index -> part_id.
Expand Down
12 changes: 7 additions & 5 deletions include/ginkgo/core/distributed/partition_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ class Partition;
* Builds a partition from a local range.
*
* @param exec the Executor on which the partition should be built.
* @param local_range the start and end indices of the local range.
* @param comm the communicator used to determine the global partition.
* @param local_range the start and end indices of the local range.
*
* @warning The local ranges have to be continuous and ascending. This means
* that for a process `i` with `range[i] = [s_i, e_i)` then for process
* `j = i+1` `range[j] = [s_j = e_i, e_j)`.
* @warning This throws, if the resulting partition would contain gaps.
* That means that for a partition of size `n` every local range `r_i
* = [s_i, e_i)` either `s_i != 0` and another local range `r_j =
* [s_j, e_j = s_i)` exists, or `e_i != n` and another local range
* `r_j = [s_j = e_i, e_j)` exists.
*
* @return a Partition where each range has the individual local_start
* and local_ends.
Expand All @@ -76,8 +78,8 @@ build_partition_from_local_range(std::shared_ptr<const Executor> exec,
* Builds a partition from a local size.
*
* @param exec the Executor on which the partition should be built.
* @param local_range the number of the locally owned indices
* @param comm the communicator used to determine the global partition.
* @param local_range the number of the locally owned indices
*
* @return a Partition where each range has the specified local size. More
* specifically, if this is called on process i with local_size `s_i`,
Expand Down
4 changes: 2 additions & 2 deletions test/distributed/partition_helper_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ template <typename IndexType>
std::vector<IndexType> create_iota(IndexType min, IndexType max)
{
std::vector<IndexType> iota(
clamp(max - min, static_cast<IndexType>(0), max));
clamp(max - min, IndexType(0), max));
std::iota(iota.begin(), iota.end(), min);
return iota;
}
Expand Down Expand Up @@ -98,7 +98,7 @@ std::vector<std::size_t> sample_unique(std::size_t min, std::size_t max,
std::default_random_engine engine;
auto values = create_iota(min, max);
std::shuffle(values.begin(), values.end(), engine);
values.erase(values.begin() + clamp(n, 0ul, values.size()), values.end());
values.erase(values.begin() + clamp(n, gko::size_type(0), values.size()), values.end());
return values;
}

Expand Down

0 comments on commit cbb11c8

Please sign in to comment.