19 lock_win_(topology::
mpicomm(), n_locks_, 0) {}
26 lock_t result = mpi_atomic_cas_value<lock_t>(1, 0, target_rank, get_disp(idx), lock_win_.
win());
35 while (!
trylock(target_rank, idx));
44 lock_t result = mpi_atomic_faa_value<lock_t>(1, target_rank, get_disp(idx), lock_win_.
win());
50 while (mpi_atomic_get_value<lock_t>(target_rank, get_disp(idx), lock_win_.
win()) != 1);
58 mpi_atomic_faa_value<lock_t>(-1, target_rank, get_disp(idx), lock_win_.
win());
64 lock_t result = mpi_atomic_get_value<lock_t>(target_rank, get_disp(idx), lock_win_.
win());
71 struct alignas(common::hardware_destructive_interference_size) lock_wrapper {
72 template <
typename... Args>
73 lock_wrapper(Args&&...
args) : value(std::forward<Args>(
args)...) {}
74 std::atomic<lock_t> value;
77 std::size_t get_disp(
int idx)
const {
78 return idx *
sizeof(lock_wrapper) + offsetof(lock_wrapper, value);
82 mpi_win_manager<lock_wrapper> lock_win_;
85 ITYR_TEST_CASE(
"[ityr::common::global_lock] lock and unlock") {
87 singleton_initializer<topology::instance> topo;
92 using value_t = std::size_t;
101 std::size_t n_updates = 100;
104 for (std::size_t i = 0; i < n_updates; i++) {
105 lock.lock(target_rank);
107 auto v = common::mpi_get_value<value_t>(target_rank, 0, value_win.win());
108 common::mpi_put_value<value_t>(v + 1, target_rank, 0, value_win.win());
110 lock.unlock(target_rank);
121 global_lock lock(n_elems);
123 using value_t = std::size_t;
126 for (
int i = 0; i < n_elems; i++) {
132 std::size_t n_updates = 1000;
135 for (std::size_t i = 0; i < n_updates; i++) {
136 int idx = i % n_elems;
137 lock.lock(target_rank, idx);
139 auto v = common::mpi_get_value<value_t>(target_rank, idx *
sizeof(value_t), value_win.win());
140 common::mpi_put_value<value_t>(v + 1, target_rank, idx *
sizeof(value_t), value_win.win());
142 lock.unlock(target_rank, idx);
149 for (
int i = 0; i < n_elems; i++) {
150 sum += value_win.local_buf()[i];
Definition: global_lock.hpp:15
void priolock(topology::rank_t target_rank, int idx=0) const
Definition: global_lock.hpp:38
void lock(topology::rank_t target_rank, int idx=0) const
Definition: global_lock.hpp:33
void unlock(topology::rank_t target_rank, int idx=0) const
Definition: global_lock.hpp:53
bool trylock(topology::rank_t target_rank, int idx=0) const
Definition: global_lock.hpp:21
bool is_locked(topology::rank_t target_rank, int idx=0) const
Definition: global_lock.hpp:61
global_lock(int n_locks=1)
Definition: global_lock.hpp:17
MPI_Win win() const
Definition: mpi_rma.hpp:409
#define ITYR_SUBCASE(name)
Definition: util.hpp:41
#define ITYR_CHECK(cond)
Definition: util.hpp:48
rank_t n_ranks()
Definition: topology.hpp:208
int rank_t
Definition: topology.hpp:12
MPI_Comm mpicomm()
Definition: topology.hpp:206
Definition: allocator.hpp:16
va_list args
Definition: util.hpp:76
void mpi_barrier(MPI_Comm comm)
Definition: mpi_util.hpp:42
rank_t n_ranks()
Return the total number of processes.
Definition: ityr.hpp:107
#define ITYR_PROFILER_RECORD(event,...)
Definition: profiler.hpp:319
Definition: prof_events.hpp:94
Definition: prof_events.hpp:89
Definition: prof_events.hpp:99