bootstrap.hpp
1 
6 #pragma once
7 
8 #include <chrono>
9 #include <cstdint>
10 #include <memory>
11 #include <optional>
12 #include <string>
13 
14 #include <rapidsmpf/config.hpp>
15 #include <rapidsmpf/utils.hpp>
16 
18 
20 using Rank = std::int32_t;
21 
23 using rapidsmpf::Duration;
24 
28 enum class Backend {
35  AUTO,
36 
44  FILE,
45 };
46 
53 struct Context {
56 
59 
62 
64  std::optional<std::string> coord_dir;
65 };
66 
88 
100 void broadcast(Context const& ctx, void* data, std::size_t size, Rank root = 0);
101 
109 void barrier(Context const& ctx);
110 
120 void put(Context const& ctx, std::string const& key, std::string const& value);
121 
133 std::string get(
134  Context const& ctx,
135  std::string const& key,
136  Duration timeout = std::chrono::seconds{30}
137 );
138 
139 } // namespace rapidsmpf::bootstrap
void broadcast(Context const &ctx, void *data, std::size_t size, Rank root=0)
Broadcast data from root rank to all other ranks.
void put(Context const &ctx, std::string const &key, std::string const &value)
Store a key-value pair in the coordination backend.
std::string get(Context const &ctx, std::string const &key, Duration timeout=std::chrono::seconds{30})
Retrieve a value from the coordination backend.
std::int32_t Rank
Type alias for communicator::Rank.
Definition: bootstrap.hpp:20
void barrier(Context const &ctx)
Perform a barrier synchronization across all ranks.
Context init(Backend backend=Backend::AUTO)
Initialize the bootstrap context from environment variables.
Backend
Backend types for process coordination and bootstrapping.
Definition: bootstrap.hpp:28
@ FILE
File-based coordination using a shared directory.
@ AUTO
Automatically detect the best backend based on environment.
Context information for the current process/rank.
Definition: bootstrap.hpp:53
std::optional< std::string > coord_dir
Coordination directory (for FILE backend).
Definition: bootstrap.hpp:64
Rank nranks
Total number of ranks in the job.
Definition: bootstrap.hpp:58
Backend backend
Backend used for coordination.
Definition: bootstrap.hpp:61
Rank rank
This process's rank (0-indexed).
Definition: bootstrap.hpp:55