1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_H
53 std::shared_ptr<Proxy>
scope();
63 decltype(std::declval<LockMPI3>().scope())
l;
66template <
typename Result =
void>
69 Task(std::future<Result> &&task) :
m_task{std::move(task)} {};
72 template <
class Func,
typename... Args>
74 return {std::async(std::launch::async, std::forward<Func>(f), std::forward<Args>(args)...)};
80 bool test() {
return m_task.wait_for(std::chrono::microseconds{1}) == std::future_status::ready; }
84 throw std::future_error(std::future_errc::no_state);
Atomic lock allowing only one process to acquire it. Implemented using MPI3 RMA.
Definition: util.h:14
void unlock()
Release the lock.
Definition: util.cpp:24
MPI_Comm m_comm
MPI communicator.
Definition: util.h:16
~LockMPI3()
Release the lock and destroy it. This is collective and must be called by all processes in the commun...
Definition: util.cpp:10
void lock()
Acquire exclusive lock.
Definition: util.cpp:17
std::shared_ptr< Proxy > scope()
Definition: util.cpp:31
bool m_locked
whether lock is active
Definition: util.h:18
std::weak_ptr< Proxy > m_proxy
Keep track of proxy object so that if lock is deleted, the proxy does not try to unlock.
Definition: util.h:48
LockMPI3(const LockMPI3 &)=delete
LockMPI3 & operator=(const LockMPI3 &)=delete
MPI_Win m_win
empty window handle
Definition: util.h:17
Utility object that locks on creation and unlocks on destruction.
Definition: util.h:57
LockMPI3 lock
Definition: util.h:62
ScopeLock(MPI_Comm comm)
Definition: util.h:59
decltype(std::declval< LockMPI3 >().scope()) l
Definition: util.h:63
Task(Task &&other)=default
static Task create(Func &&f, Args &&...args)
Definition: util.h:73
Task(std::future< Result > &&task)
Definition: util.h:69
Result wait()
wait for the task to complete and return its result
Definition: util.h:82
std::future< Result > m_task
Definition: util.h:89
~Task()
Definition: util.h:77
bool test()
Returns true if the task has completed.
Definition: util.h:80
Definition: ArrayHandler.h:23
Proxy that locks on creation and unlocks on destruction. Useful for locking a scope.
Definition: util.h:38
LockMPI3 & m_lock
Definition: util.h:39
bool m_deleted
whether the lock was already deleted
Definition: util.h:44
~Proxy()
Definition: util.cpp:42