diff --git a/libs/core/openshmem_base/include/hpx/openshmem_base/openshmem_environment.hpp b/libs/core/openshmem_base/include/hpx/openshmem_base/openshmem_environment.hpp index 6d95f3039f36..fa85e892909a 100644 --- a/libs/core/openshmem_base/include/hpx/openshmem_base/openshmem_environment.hpp +++ b/libs/core/openshmem_base/include/hpx/openshmem_base/openshmem_environment.hpp @@ -31,6 +31,7 @@ namespace hpx { namespace util { std::uint8_t* end_addr; unsigned int * rcv; unsigned int * xmt; + hpx::mutex * mut; }; struct HPX_CORE_EXPORT openshmem_environment diff --git a/libs/core/openshmem_base/src/openshmem_environment.cpp b/libs/core/openshmem_base/src/openshmem_environment.cpp index 6f52df7d29e5..504676ef770f 100644 --- a/libs/core/openshmem_base/src/openshmem_environment.cpp +++ b/libs/core/openshmem_base/src/openshmem_environment.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -204,6 +203,8 @@ namespace hpx::util { // segments[i].xmt = reinterpret_cast(hpx::util::openshmem_environment::shmem_buffer + beg_signal + page_count + i); + + segments[i].mut = &(openshmem_environment::segment_mutex[i]); } shmem_barrier_all(); diff --git a/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/receiver_connection.hpp b/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/receiver_connection.hpp index de659401ee33..bdb87d49cc76 100644 --- a/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/receiver_connection.hpp +++ b/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/receiver_connection.hpp @@ -130,7 +130,7 @@ namespace hpx::parcelset::policies::openshmem { { buffer_.chunks_.resize(num_zero_copy_chunks); { - hpx::util::openshmem_environment::scoped_lock l; + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); hpx::util::openshmem_environment::wait_until( 1, hpx::util::openshmem_environment::segments[idx].rcv); @@ -172,8 +172,9 @@ namespace hpx::parcelset::policies::openshmem { const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; const auto idx = (self_*nthreads_)+sending_thd_id_; - hpx::util::openshmem_environment::scoped_lock l; - hpx::util::openshmem_environment::wait_until( + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); + + hpx::util::openshmem_environment::wait_until( 1, hpx::util::openshmem_environment::segments[idx].rcv); (*(hpx::util::openshmem_environment::segments[idx].rcv)) = 0; @@ -211,7 +212,7 @@ namespace hpx::parcelset::policies::openshmem { const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; const auto idx = (self_*nthreads_)+sending_thd_id_; - hpx::util::openshmem_environment::scoped_lock l; + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); hpx::util::openshmem_environment::wait_until( 1, hpx::util::openshmem_environment::segments[idx].rcv); @@ -249,7 +250,7 @@ namespace hpx::parcelset::policies::openshmem { const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; const auto idx = (self_*nthreads_)+sending_thd_id_; - hpx::util::openshmem_environment::scoped_lock l; + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); hpx::util::openshmem_environment::wait_until( 1, hpx::util::openshmem_environment::segments[idx].rcv); @@ -277,13 +278,12 @@ namespace hpx::parcelset::policies::openshmem { bool request_done() noexcept { - hpx::util::openshmem_environment::scoped_try_lock l; - if (!l.locked) - { - return false; - } + const auto self_ = hpx::util::openshmem_environment::rank(); + const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; + const auto idx = (self_*nthreads_)+sending_thd_id_; - return request_ptr_; + const bool l = hpx::util::openshmem_environment::segments[idx].mut->try_lock(); + return l; } #if defined(HPX_HAVE_PARCELPORT_COUNTERS) diff --git a/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/sender_connection.hpp b/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/sender_connection.hpp index 2cac1f04ba9b..b72145466555 100644 --- a/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/sender_connection.hpp +++ b/libs/full/parcelport_openshmem/include/hpx/parcelport_openshmem/sender_connection.hpp @@ -157,7 +157,7 @@ namespace hpx::parcelset::policies::openshmem { const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; const auto idx = (dst_*nthreads_)+thd_id_; - hpx::util::openshmem_environment::scoped_lock l; + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); // put from this localities openshmem shared memory segment // into the remote locality (dst_)'s shared memory segment @@ -195,7 +195,7 @@ namespace hpx::parcelset::policies::openshmem { const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; const auto idx = (dst_*nthreads_)+thd_id_; - hpx::util::openshmem_environment::scoped_lock l; + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); hpx::util::openshmem_environment::put_signal( reinterpret_cast(chunks.data()), dst_, @@ -225,7 +225,8 @@ namespace hpx::parcelset::policies::openshmem { const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; const auto idx = (dst_*nthreads_)+thd_id_; - hpx::util::openshmem_environment::scoped_lock l; + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); + hpx::util::openshmem_environment::put_signal( reinterpret_cast(buffer_.data_.data()), dst_, static_cast(hpx::util::openshmem_environment::segments[idx].beg_addr), @@ -256,7 +257,7 @@ namespace hpx::parcelset::policies::openshmem { return false; } - hpx::util::openshmem_environment::scoped_lock l; + std::lock_guard l(*(hpx::util::openshmem_environment::segments[idx].mut)); hpx::util::openshmem_environment::put_signal( reinterpret_cast(c.data_.cpos_), @@ -304,11 +305,11 @@ namespace hpx::parcelset::policies::openshmem { bool request_done() { - hpx::util::openshmem_environment::scoped_try_lock l; - if (!l.locked) - { - return false; - } + const auto nthreads_ = hpx::util::openshmem_environment::nthreads_; + const auto idx = (dst_*nthreads_)+thd_id_; + + const bool l = hpx::util::openshmem_environment::segments[idx].mut->try_lock(); + return l; return true; }