GlobalCompletionEvent (GCE): Synchronization construct for determining when a global phase of asynchronous tasks have all completed. More...
#include <GlobalCompletionEvent.hpp>
Public Member Functions | |
int64_t | incomplete () const |
void | send_completion (Core owner, int64_t dec=1) |
Send a completion message to the originating core. More... | |
GlobalCompletionEvent (bool user_track=false) | |
~GlobalCompletionEvent () | |
void | set_shared_ptr (const void *p) |
template<typename T > | |
const T * | get_shared_ptr () |
void | reset () |
This is the state the GCE's on each core should be in at the beginning, and the state they should end up in after a Completion phase. More... | |
CompletionTarget | enroll (int64_t inc=1) |
Enroll more things that need to be completed before the global completion is, well, complete. More... | |
CompletionTarget | enroll_recurring (int64_t inc=1) |
Enqueue tasks to GCE which will be automatically re-enrolled when the current phase completes. More... | |
void | complete (int64_t dec=1) |
Mark a certain number of things completed. More... | |
void | complete (CompletionTarget ct, int64_t decr=1) |
Wrapper to call combining completion instead of local completion when given a CompletionTarget. More... | |
void | complete (GlobalAddress< GlobalCompletionEvent > ce, int64_t decr=1) |
Wrapper to call combining completion instead of local completion when given a GCE global address. More... | |
void | wait () |
Suspend calling task until all tasks completed (including additional tasks enrolled before count goes to 0). More... | |
Public Member Functions inherited from Grappa::CompletionEvent | |
CompletionEvent (int64_t count=0) | |
int64_t | get_count () const |
void | enroll (int64_t inc=1) |
void | complete (int64_t decr=1) |
Decrement count once, if count == 0, wake all waiters. More... | |
void | wait () |
void | wait (SuspendedDelegate *c) |
void | reset () |
void | send_completion (Core origin, int64_t decr=1) |
Static Public Member Functions | |
static std::vector< GlobalCompletionEvent * > | get_user_tracked () |
Static Public Attributes | |
static const Core | master_core = 0 |
The GlobalCompletionEvents master core is defined to be core 0. More... | |
Additional Inherited Members | |
Protected Attributes inherited from Grappa::CompletionEvent | |
ConditionVariable | cv |
int64_t | count |
GlobalCompletionEvent (GCE): Synchronization construct for determining when a global phase of asynchronous tasks have all completed.
For example, can be used to ensure that all tasks of a parallel loop have completed, including tasks or asynchronous delegates spawned during execution of the parallel loop.
A GlobalCompletionEvent must be replicated at the same address on all cores (the easiest way is to declare it as file-global or static storage). TODO: allow dynamic allocation in Grappa linear address space.
Anyone calling "wait" after at least some work has been "enrolled" globally will block. When all work has been completed on all cores, all tasks waiting on the GCE will be woken.
To ensure consistent behavior and guarantee deadlock freedom, every "enroll" must be causally followed by "complete", so either must be completed from the same task that called "enroll" or from a task spawned (transitively) from the enrolling task.
This is meant to be a reusable barrier; GCE's should begin in a state where a call to wait
will fall through, and end up, after all tasks are completed, back in the same state. Note: reset
no longer needs to be called between phases. Instead, it just must be guaranteed that at least one task has been enrolled before anyone tries to call wait
otherwise they may fall through before the enrollment has completed.
Definition at line 90 of file GlobalCompletionEvent.hpp.
|
inline |
Definition at line 203 of file GlobalCompletionEvent.hpp.
|
inline |
Definition at line 211 of file GlobalCompletionEvent.hpp.
|
inline |
Mark a certain number of things completed.
When the global count on all cores goes to 0, all tasks waiting on the GCE will be woken.
Note: this can be called in a message handler (e.g. remote completes from stolen tasks).
Definition at line 277 of file GlobalCompletionEvent.hpp.
|
inline |
Wrapper to call combining completion instead of local completion when given a CompletionTarget.
Definition at line 340 of file GlobalCompletionEvent.hpp.
|
inline |
Wrapper to call combining completion instead of local completion when given a GCE global address.
Definition at line 364 of file GlobalCompletionEvent.hpp.
|
inline |
Enroll more things that need to be completed before the global completion is, well, complete.
This will send a cancel to the master if this core previously entered the cancellable barrier.
Blocks until cancel completes (if it must cancel) to ensure correct ordering, therefore cannot be called from message handler.
Definition at line 234 of file GlobalCompletionEvent.hpp.
|
inline |
Enqueue tasks to GCE which will be automatically re-enrolled when the current phase completes.
This must be called on the master core.
Definition at line 267 of file GlobalCompletionEvent.hpp.
|
inline |
Definition at line 216 of file GlobalCompletionEvent.hpp.
|
static |
Definition at line 56 of file GlobalCompletionEvent.cpp.
|
inline |
Definition at line 179 of file GlobalCompletionEvent.hpp.
|
inline |
This is the state the GCE's on each core should be in at the beginning, and the state they should end up in after a Completion phase.
It should no longer be necessary to call reset
between calls to wait
as long as nothing fishy is going on.
Definition at line 221 of file GlobalCompletionEvent.hpp.
|
inline |
Send a completion message to the originating core.
Uses the local instance of the gce to keep track of information in order to flatten completions automatically.
Definition at line 183 of file GlobalCompletionEvent.hpp.
|
inline |
Definition at line 215 of file GlobalCompletionEvent.hpp.
|
inline |
Suspend calling task until all tasks completed (including additional tasks enrolled before count goes to 0).
This can be called from as many tasks as desired on different cores, as long as it is ensured that a task in the desired phase has been enrolled before wait is called.
If no tasks have been enrolled, or all have been completed by the time wait
is called, this will fall through and not suspend the calling task.
Definition at line 375 of file GlobalCompletionEvent.hpp.
|
static |
The GlobalCompletionEvents master core is defined to be core 0.
Definition at line 175 of file GlobalCompletionEvent.hpp.