finish_counter.hpp
1 
5 #pragma once
6 
7 #include <mutex>
8 #include <vector>
9 
10 #include <rapidsmpf/communicator/communicator.hpp>
11 #include <rapidsmpf/shuffler/chunk.hpp>
12 
19 namespace rapidsmpf::shuffler {
20 
28 namespace detail {
29 
39  public:
46  FinishCounter(Rank nranks, PartID n_local_partitions);
47 
48  ~FinishCounter() = default;
49 
62  void move_goalpost(Rank src_rank, ChunkID nchunks);
63 
74 
80  [[nodiscard]] bool all_finished() const;
81 
86  [[nodiscard]] std::string str() const;
87 
88  private:
91  Rank const nranks_;
92 
93  Rank n_ranks_with_goalpost_{0};
94  ChunkID total_chunk_goal_{0};
95  ChunkID total_finished_chunks_{0};
96  std::vector<bool> rank_reported_;
97 
98  mutable std::mutex mutex_;
99 };
100 
101 } // namespace detail
102 
113 inline std::ostream& operator<<(std::ostream& os, detail::FinishCounter const& obj) {
114  os << obj.str();
115  return os;
116 }
117 
118 } // namespace rapidsmpf::shuffler
Helper to tally the finish status of a shuffle.
void move_goalpost(Rank src_rank, ChunkID nchunks)
Move the goalpost for a specific source rank.
std::string str() const
Returns a description of this instance.
void add_finished_chunk()
Add a finished chunk to the global counter.
bool all_finished() const
Returns whether all partitions are finished (non-blocking).
FinishCounter(Rank nranks, PartID n_local_partitions)
Construct a finish counter.
std::uint64_t ChunkID
The globally unique ID of a chunk.
Definition: chunk.hpp:29
Shuffler interfaces.
Definition: chunk.hpp:15
std::uint32_t PartID
Partition ID, which goes from 0 to the total number of partitions.
Definition: chunk.hpp:22
std::ostream & operator<<(std::ostream &os, detail::FinishCounter const &obj)
Overloads the stream insertion operator for the FinishCounter class.
std::int32_t Rank
The rank of a node (e.g. the rank of a MPI process), or world size (total number of ranks).