15 template <
typename T,
typename =
void>
32 constexpr
explicit global_ptr(T* ptr) noexcept : raw_ptr_(ptr) {}
38 constexpr
this_t&
operator=(std::nullptr_t) noexcept { raw_ptr_ =
nullptr;
return *
this; }
42 constexpr
explicit operator bool() const noexcept {
return raw_ptr_ !=
nullptr; }
43 constexpr
bool operator!() const noexcept {
return raw_ptr_ ==
nullptr; }
68 return this_t(raw_ptr_ + diff);
72 return this_t(raw_ptr_ - diff);
85 T* raw_ptr_ =
nullptr;
88 static_assert(std::is_trivially_copyable_v<global_ptr<int>>);
90 template <
typename T1,
typename T2>
97 return p1.raw_ptr() == p2.raw_ptr();
100 template <
typename T>
105 template <
typename T>
110 template <
typename T>
112 return p1.raw_ptr() != p2.raw_ptr();
115 template <
typename T>
120 template <
typename T>
125 template <
typename T>
127 return p1.raw_ptr() < p2.raw_ptr();
130 template <
typename T>
132 return p1.raw_ptr() > p2.raw_ptr();
135 template <
typename T>
137 return p1.raw_ptr() <= p2.raw_ptr();
140 template <
typename T>
142 return p1.raw_ptr() >= p2.raw_ptr();
145 template <
typename T>
150 template <
typename T,
typename U>
155 template <
typename T,
typename U>
160 template <
typename T,
typename U>
165 template <
typename T,
typename U>
172 template <
typename T,
typename>
186 with_read_write([&](T& this_v) { this_v = v; });
191 with_read_write([&](T& this_v) { this_v =
std::move(v); });
196 with_read_write([&](T& this_v) {
197 r.with_read_write([&](T& v) {
205 with_read_write([&](T& this_v) {
206 r.with_read_write([&](T& v) {
213 with_read_write([&](T& this_v) { this_v += v; });
218 with_read_write([&](T& this_v) { this_v -= v; });
223 with_read_write([&](T& this_v) { ++this_v; });
228 with_read_write([&](T& this_v) { --this_v; });
234 with_read_write([&](T& this_v) { ret = this_v++; });
240 with_read_write([&](T& this_v) { ret = this_v--; });
246 with_read_write([&](T& this_v) {
247 r.with_read_write([&](T& v) {
255 template <
typename Fn>
256 void with_read_write(Fn&& f) {
260 std::forward<Fn>(f)(buf);
265 std::forward<Fn>(f)(*ptr_.raw_ptr());
272 template <
typename T>
273 class global_ref<T, std::enable_if_t<std::is_trivially_copyable_v<T>>> {
291 with_write_only([&](T& this_v) { this_v = v; });
296 with_write_only([&](T& this_v) { this_v =
std::move(v); });
301 return (*
this = r.get());
305 return (*
this = r.get());
309 with_read_write([&](T& this_v) { this_v += v; });
314 with_read_write([&](T& this_v) { this_v -= v; });
319 with_read_write([&](T& this_v) { ++this_v; });
324 with_read_write([&](T& this_v) { --this_v; });
330 with_read_write([&](T& this_v) { ret = this_v++; });
336 with_read_write([&](T& this_v) { ret = this_v--; });
342 with_read_write([&](T& this_v) {
343 r.with_read_write([&](T& v) {
351 std::remove_const_t<T> ret;
362 template <
typename Fn>
363 void with_read_write(Fn&& f) {
367 std::forward<Fn>(f)(buf);
372 std::forward<Fn>(f)(*ptr_.raw_ptr());
376 template <
typename Fn>
377 void with_write_only(Fn&& f) {
380 std::forward<Fn>(f)(buf);
385 std::forward<Fn>(f)(*ptr_.raw_ptr());
392 template <
typename T>
397 template <
typename T,
typename MemberT>
399 using member_t = std::remove_extent_t<MemberT>;
400 member_t* member_ptr =
reinterpret_cast<member_t*
>(std::addressof(ptr.
raw_ptr()->*mp));
407 template <
typename T>
410 template <
typename T>
416 static_assert(!is_global_ptr_v<int>);
418 ITYR_TEST_CASE(
"[ityr::ori::global_ptr] global pointer manipulation") {
419 int* a1 =
reinterpret_cast<int*
>(0x00100000);
420 int* a2 =
reinterpret_cast<int*
>(0x01000000);
421 int* a3 =
reinterpret_cast<int*
>(0x10000000);
483 global_ptr<void> nullp;
485 ITYR_CHECK(nullp == global_ptr<void>(
nullptr));
500 struct point1 {
int x;
int y;
int z; };
501 uintptr_t base_addr = 0x00300000;
502 global_ptr<point1> px1(
reinterpret_cast<point1*
>(base_addr));
503 ITYR_CHECK(&(px1->*(&point1::x)) == global_ptr<int>(
reinterpret_cast<int*
>(base_addr + offsetof(point1, x))));
504 ITYR_CHECK(&(px1->*(&point1::y)) == global_ptr<int>(
reinterpret_cast<int*
>(base_addr + offsetof(point1, y))));
505 ITYR_CHECK(&(px1->*(&point1::z)) == global_ptr<int>(
reinterpret_cast<int*
>(base_addr + offsetof(point1, z))));
506 struct point2 {
int v[3]; };
507 global_ptr<point2> px2(
reinterpret_cast<point2*
>(base_addr));
508 global_ptr<int> pv = &(px2->*(&point2::v));
509 ITYR_CHECK(pv == global_ptr<int>(
reinterpret_cast<int*
>(base_addr)));
510 ITYR_CHECK(&pv[0] == global_ptr<int>(
reinterpret_cast<int*
>(base_addr) + 0));
511 ITYR_CHECK(&pv[1] == global_ptr<int>(
reinterpret_cast<int*
>(base_addr) + 1));
512 ITYR_CHECK(&pv[2] == global_ptr<int>(
reinterpret_cast<int*
>(base_addr) + 2));
516 ITYR_CHECK(global_ptr<char>(
reinterpret_cast<char*
>(p1.raw_ptr())) == reinterpret_pointer_cast<char>(p1));
517 ITYR_CHECK(reinterpret_pointer_cast<char>(p1 + 4) == reinterpret_pointer_cast<char>(p1) + 4 *
sizeof(
int));
518 global_ptr<const int> p1_const(const_pointer_cast<const int>(p1));
519 ITYR_CHECK(reinterpret_pointer_cast<const int>(p1) == p1_const);
534 ITYR_TEST_CASE(
"[ityr::ori::global_ptr] global reference") {
535 common::runtime_options common_opts;
536 runtime_options opts;
537 common::singleton_initializer<common::topology::instance> topo_;
538 common::singleton_initializer<common::rma::instance> rma_;
541 common::singleton_initializer<core::instance> core_(n_cb * bs, bs / 4);
548 global_ptr<int> gp_local(
reinterpret_cast<int*
>(p_local));
556 for (
int i = 0; i <
n_ranks; i++) {
568 global_ptr<int> gp(
reinterpret_cast<int*
>(p));
576 *gp = (*gp * 2) / 2 - 1 + 2;
static auto & get()
Definition: util.hpp:180
Definition: global_ptr.hpp:19
std::ptrdiff_t difference_type
Definition: global_ptr.hpp:25
constexpr bool operator!() const noexcept
Definition: global_ptr.hpp:43
constexpr void swap(this_t &p) noexcept
Definition: global_ptr.hpp:75
constexpr this_t & operator++() noexcept
Definition: global_ptr.hpp:61
constexpr pointer raw_ptr() const noexcept
Definition: global_ptr.hpp:40
constexpr global_ptr(T *ptr) noexcept
Definition: global_ptr.hpp:32
constexpr reference operator[](difference_type diff) const
Definition: global_ptr.hpp:47
constexpr this_t operator--(int) noexcept
Definition: global_ptr.hpp:65
constexpr global_ptr() noexcept
Definition: global_ptr.hpp:30
constexpr reference operator*() const
Definition: global_ptr.hpp:45
T element_type
Definition: global_ptr.hpp:23
std::remove_cv_t< T > value_type
Definition: global_ptr.hpp:24
std::random_access_iterator_tag iterator_category
Definition: global_ptr.hpp:28
constexpr this_t operator-(difference_type diff) const noexcept
Definition: global_ptr.hpp:71
constexpr this_t & operator=(const this_t &) noexcept=default
constexpr this_t & operator=(std::nullptr_t) noexcept
Definition: global_ptr.hpp:38
constexpr global_ptr(std::nullptr_t) noexcept
Definition: global_ptr.hpp:37
T * pointer
Definition: global_ptr.hpp:26
constexpr this_t operator+(difference_type diff) const noexcept
Definition: global_ptr.hpp:67
global_ref< T > reference
Definition: global_ptr.hpp:27
constexpr this_t & operator+=(difference_type diff) noexcept
Definition: global_ptr.hpp:51
constexpr this_t & operator--() noexcept
Definition: global_ptr.hpp:62
constexpr this_t & operator-=(difference_type diff) noexcept
Definition: global_ptr.hpp:56
constexpr this_t operator++(int) noexcept
Definition: global_ptr.hpp:64
constexpr global_ptr(const this_t &) noexcept=default
this_t & operator++()
Definition: global_ptr.hpp:318
this_t & put(const T &v)
Definition: global_ptr.hpp:356
constexpr global_ref(const this_t &r) noexcept
Definition: global_ptr.hpp:281
T operator++(int)
Definition: global_ptr.hpp:328
void swap(this_t r)
Definition: global_ptr.hpp:340
std::remove_cv_t< T > value_type
Definition: global_ptr.hpp:277
T operator--(int)
Definition: global_ptr.hpp:334
this_t & operator-=(const T &v)
Definition: global_ptr.hpp:313
this_t & operator=(const T &v)
Definition: global_ptr.hpp:290
this_t & operator=(T &&v)
Definition: global_ptr.hpp:295
this_t & operator--()
Definition: global_ptr.hpp:323
this_t & operator=(const this_t &r)
Definition: global_ptr.hpp:300
T get() const
Definition: global_ptr.hpp:350
this_t & operator=(this_t &&r)
Definition: global_ptr.hpp:304
constexpr pointer operator&() const noexcept
Definition: global_ptr.hpp:283
this_t & operator+=(const T &v)
Definition: global_ptr.hpp:308
constexpr global_ref(const global_ptr< T > &p) noexcept
Definition: global_ptr.hpp:280
Definition: global_ptr.hpp:173
this_t & operator=(T &&v)
Definition: global_ptr.hpp:190
constexpr pointer operator&() const noexcept
Definition: global_ptr.hpp:183
this_t & operator+=(const T &v)
Definition: global_ptr.hpp:212
this_t & operator=(const T &v)
Definition: global_ptr.hpp:185
this_t & operator=(const this_t &r)
Definition: global_ptr.hpp:195
this_t & operator-=(const T &v)
Definition: global_ptr.hpp:217
T operator++(int)
Definition: global_ptr.hpp:232
constexpr global_ref(const this_t &r) noexcept
Definition: global_ptr.hpp:181
this_t & operator++()
Definition: global_ptr.hpp:222
void swap(this_t r)
Definition: global_ptr.hpp:244
T operator--(int)
Definition: global_ptr.hpp:238
this_t & operator=(this_t &&r)
Definition: global_ptr.hpp:204
this_t & operator--()
Definition: global_ptr.hpp:227
constexpr global_ref(const global_ptr< T > &p) noexcept
Definition: global_ptr.hpp:180
std::remove_cv_t< T > value_type
Definition: global_ptr.hpp:177
#define ITYR_SUBCASE(name)
Definition: util.hpp:41
#define ITYR_CHECK(cond)
Definition: util.hpp:48
rank_t n_ranks()
Definition: topology.hpp:208
MPI_Comm mpicomm()
Definition: topology.hpp:206
rank_t my_rank()
Definition: topology.hpp:207
void mpi_wait(MPI_Request &req)
Definition: mpi_util.hpp:250
MPI_Request mpi_isend(const T *buf, std::size_t count, int target_rank, int tag, MPI_Comm comm)
Definition: mpi_util.hpp:67
void mpi_barrier(MPI_Comm comm)
Definition: mpi_util.hpp:42
MPI_Request mpi_irecv(T *buf, std::size_t count, int target_rank, int tag, MPI_Comm comm)
Definition: mpi_util.hpp:107
constexpr read_write_t read_write
Definition: util.hpp:15
constexpr write_t write
Definition: util.hpp:13
Definition: block_region_set.hpp:9
constexpr bool operator>(const global_ptr< T > &p1, const global_ptr< T > &p2) noexcept
Definition: global_ptr.hpp:131
constexpr void swap(global_ptr< T > &p1, global_ptr< T > &p2) noexcept
Definition: global_ptr.hpp:146
constexpr bool operator<=(const global_ptr< T > &p1, const global_ptr< T > &p2) noexcept
Definition: global_ptr.hpp:136
void get(global_ptr< ConstT > from_ptr, T *to_ptr, std::size_t count)
Definition: ori.hpp:80
global_ptr< T > reinterpret_pointer_cast(const global_ptr< U > &p) noexcept
Definition: global_ptr.hpp:166
constexpr bool operator>=(const global_ptr< T > &p1, const global_ptr< T > &p2) noexcept
Definition: global_ptr.hpp:141
void swap(global_ref< T > r1, global_ref< T > r2)
Definition: global_ptr.hpp:393
auto operator-(const global_ptr< T1 > &p1, const global_ptr< T2 > &p2)
Definition: global_ptr.hpp:91
bool operator==(const region< T > &r1, const region< T > &r2) noexcept
Definition: block_region_set.hpp:30
global_ptr< T > const_pointer_cast(const global_ptr< U > &p) noexcept
Definition: global_ptr.hpp:161
bool operator!=(const region< T > &r1, const region< T > &r2) noexcept
Definition: block_region_set.hpp:35
constexpr bool operator<(const global_ptr< T > &p1, const global_ptr< T > &p2) noexcept
Definition: global_ptr.hpp:126
constexpr block_size_t block_size
Definition: ori.hpp:19
global_ptr< T > static_pointer_cast(const global_ptr< U > &p) noexcept
Definition: global_ptr.hpp:151
uint32_t block_size_t
Definition: util.hpp:30
constexpr bool is_global_ptr_v
Definition: global_ptr.hpp:411
auto operator->*(global_ptr< T > ptr, MemberT T::*mp)
Definition: global_ptr.hpp:398
global_ptr< T > dynamic_pointer_cast(const global_ptr< U > &p) noexcept
Definition: global_ptr.hpp:156
rank_t my_rank()
Return the rank of the process running the current thread.
Definition: ityr.hpp:99
rank_t n_ranks()
Return the total number of processes.
Definition: ityr.hpp:107
ForwardIteratorD move(const ExecutionPolicy &policy, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIteratorD first_d)
Move a range to another.
Definition: parallel_loop.hpp:934
#define ITYR_ORI_FORCE_GETPUT
Definition: global_ptr.hpp:405
Definition: global_ptr.hpp:414