Grappa  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Grappa::GlobalCompletionEvent Class Reference

GlobalCompletionEvent (GCE): Synchronization construct for determining when a global phase of asynchronous tasks have all completed. More...

#include <GlobalCompletionEvent.hpp>

Inheritance diagram for Grappa::GlobalCompletionEvent:
Grappa::CompletionEvent

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...
 
void enroll (int64_t inc=1)
 Enroll more things that need to be completed before the global completion is, well, complete. More...
 
void complete (int64_t dec=1)
 Mark a certain number of things completed. 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 ()
 

Additional Inherited Members

- Protected Attributes inherited from Grappa::CompletionEvent
ConditionVariable cv
 
int64_t count
 

Detailed Description

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 74 of file GlobalCompletionEvent.hpp.

Constructor & Destructor Documentation

Grappa::GlobalCompletionEvent::GlobalCompletionEvent ( bool  user_track = false)
inline

Definition at line 178 of file GlobalCompletionEvent.hpp.

Grappa::GlobalCompletionEvent::~GlobalCompletionEvent ( )
inline

Definition at line 186 of file GlobalCompletionEvent.hpp.

Member Function Documentation

void Grappa::GlobalCompletionEvent::complete ( int64_t  dec = 1)
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 241 of file GlobalCompletionEvent.hpp.

void Grappa::GlobalCompletionEvent::enroll ( int64_t  inc = 1)
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 208 of file GlobalCompletionEvent.hpp.

template<typename T >
const T* Grappa::GlobalCompletionEvent::get_shared_ptr ( )
inline

Definition at line 191 of file GlobalCompletionEvent.hpp.

std::vector< GlobalCompletionEvent * > GlobalCompletionEvent::get_user_tracked ( )
static

Definition at line 42 of file GlobalCompletionEvent.cpp.

int64_t Grappa::GlobalCompletionEvent::incomplete ( ) const
inline

Definition at line 154 of file GlobalCompletionEvent.hpp.

void Grappa::GlobalCompletionEvent::reset ( )
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 196 of file GlobalCompletionEvent.hpp.

void Grappa::GlobalCompletionEvent::send_completion ( Core  owner,
int64_t  dec = 1 
)
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 158 of file GlobalCompletionEvent.hpp.

void Grappa::GlobalCompletionEvent::set_shared_ptr ( const void *  p)
inline

Definition at line 190 of file GlobalCompletionEvent.hpp.

void Grappa::GlobalCompletionEvent::wait ( )
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 276 of file GlobalCompletionEvent.hpp.


The documentation for this class was generated from the following files: