Charades
|
A chare that encapsulates a set of LPStructs and their events. More...
#include <lp.h>
Public Member Functions | |
LPChare () | |
Default constructor. More... | |
LPChare (CkMigrateMessage *m) | |
Migration constructor. | |
uint64_t | get_next_event_id () |
Event * | get_current_event () const |
Time | get_current_time () const |
void | set_current_event (Event *e) |
void | stop_scheduler () |
Stops the Charm++ scheduler and returns control to main. More... | |
Scheduler Calls | |
These are regular methods called by the scheduler at various points throughout simulation execution. | |
void | init () |
Called at the start of a simulation to run LP init handlers. More... | |
void | finalize () |
int | execute_me () |
Called during execution to execute the next event owned by this LP. More... | |
void | fossil_me (Time gvt) |
Called after GVT computation to commit old events. More... | |
Migration methods | |
These methods are used to enable migration for things like LB and potentially checkpoint/restart.
| |
void | reconstruct_causality (Event *, Event **, Event **) |
Correctly rebuild causality chains when unpacking. | |
void | reconstruct_pending_event (Event *) |
Correclty rebuild pending events when unpacking. | |
void | reconstruct_processed_event (Event *, Event **, Event **) |
Correctly rebuild processed events when unpacking. | |
virtual void | pup (PUP::er &p) |
Pack/unpack this LP chare. | |
void | load_balance () |
Tell this chare that we are going to do load balancing. More... | |
void | ResumeFromSync () |
Called by the runtime system to tell this chare we can resume. More... | |
void | UserSetLBLoad () |
Called by the runtime system to get the load of this chare. More... | |
Event Receive Methods | |
Methods for receiving different types of events. Remote and Anti events come from other chares so they require entry methods. | |
void | recv_remote_event (RemoteEvent *event) |
Entry method for receiving a remote event from another chare. More... | |
void | recv_anti_event (RemoteEvent *event) |
Entry method for receiving and processing an anti event. More... | |
void | recv_local_event (Event *e) |
Regular method for common processing on locally allocated events. More... | |
Rollback/Cancellation Methods | |
The purpose of these methods is recovery from causality violations so therefore they are only used in optimistic mode. | |
void | rollback_me (Time ts) |
Do a primary rollback to a given virtual timestamp. More... | |
void | rollback_me (Event *event) |
Do a secondary rollback to a particular event. More... | |
void | cancel_event (Event *event) |
Cancel an event that should have never been received. More... | |
void | delete_pending (Event *event) |
Cancel an event from the pending queue by simply removing it. More... | |
void | add_to_cancel_q (Event *e) |
Add an event to the queue of events to be cancelled later. More... | |
void | process_cancel_q () |
Process and cancel each event in the cancel queue. More... | |
Public Attributes | |
AvlTree | all_events |
A pointer to the PE level AVL tree for hashing remote events. More... | |
Private Attributes | |
LPToken | next_token |
LPToken whose key is the timestamp of the next event this chare will execute. More... | |
Time | current_time |
Time of most recently executed event. | |
Event * | current_event |
Most recently executed event. | |
uint64_t | next_event_id |
The next available ID for uniquely identifying events from this LP. | |
PendingHeap | events |
All future events received for any of our LPs. More... | |
ProcessedQueue | processed_events |
A flat queue of all events previously processed by our LPs that haven't yet been committed or rolled back. More... | |
vector< LPBase * > | lp_structs |
A list of all LPs owned by this chare. More... | |
Scheduler * | scheduler |
A direct pointer to the scheduler managing this LP chare. More... | |
bool | isOptimistic |
Set to true if this LP is an optimistic LP. More... | |
LB metrics | |
Variables used to define load for custom load balancing metrics | |
int | committed_events |
Number of events committed since last LB. | |
int | rolled_back_events |
Number of events rolled back since last LB. | |
int | committed_time |
Timestamp of most recent committed event. | |
Cancellation Queue Variables | |
These variables manage the events that need to be cancelled in this LP. Cancellation management has been simplified since the scheduler now calls cancellation methods on all of its LPs. | |
Event * | cancel_q |
Queue of events this LP needs to cancel. | |
Time | min_cancel_q |
Minimum time in this LPs cancel queue. | |
A chare that encapsulates a set of LPStructs and their events.
Everything the contained LPs need for execution should be contained in here to make migration work correctly. At the moment, this is true except for the PE level AVL tree.
LPChare::LPChare | ( | ) |
Default constructor.
Initializes all member variables for this LP chare.
Since the lps proxy is not set during main, we have to make sure it is correctly set on every PE during the construction of the array.
Get the pointer to the local branch of the scheduler and register our token with it so event execution, fossil collection, and event cancellation can be scheduled for this LP chare.
Create the correct number of LPStructs based on the model specified mappings, initialize their RNG streams, but wait to call init handlers.
void LPChare::add_to_cancel_q | ( | Event * | e | ) |
Add an event to the queue of events to be cancelled later.
e | the event to add to the cancel queue |
Put the event at the head of the cancel queue
Update the min cancel time locally and in the scheduler if necessary
void LPChare::cancel_event | ( | Event * | event | ) |
Cancel an event that should have never been received.
e | the event to be cancelled |
void LPChare::delete_pending | ( | Event * | event | ) |
Cancel an event from the pending queue by simply removing it.
e | the event to delete from the pending queue |
Must also update the min time of this LP chare in the scheduler
int LPChare::execute_me | ( | ) |
Called during execution to execute the next event owned by this LP.
Pull off the top event for execution and set the current event and ts
Execute the event on the target LPStruct
Move the event to the processed queue if we are optimistic, otherwise free and commit the event immediately.
Update the scheduler with our new minimum timestamp
void LPChare::fossil_me | ( | Time | gvt | ) |
Called after GVT computation to commit old events.
gvt | the current Global Virtual Time |
Pop off events from the BACK of the processed queue and commit/free them until the oldest timestamp in the processed queue is greater than or equal to the passed in GVT.
void LPChare::init | ( | ) |
void LPChare::load_balance | ( | ) |
Tell this chare that we are going to do load balancing.
Just call AtSync to trigger automatic load balancing
void LPChare::process_cancel_q | ( | ) |
Process and cancel each event in the cancel queue.
Iterate through cancel queue and cancel every event based on where it currently exists.
For each event in the queue, cancel it based on it's current location.
If the event hasn't been executed yet, just delete from pending
If the event was alredy executed, roll back to it and free it
If the event exists somewhere else, this is an error
void LPChare::recv_anti_event | ( | RemoteEvent * | event | ) |
Entry method for receiving and processing an anti event.
event | an anti event sent from another chare |
Inform the scheduler that the anti event was received (which may affect the GVT computation)
Allocate a local event as a key into the hash and fill it
Attempt to insert the key into the AVL hash, which returns an actual event if there was already one that matched the key in the tree.
If there was already a real event, then cancel that event
void LPChare::recv_local_event | ( | Event * | e | ) |
Regular method for common processing on locally allocated events.
e | a locally allocated Event sent by an LP on our chare or created and filled in recv_remote_event |
Use g_local_map to look up the specific LPStruct pointer for this event
If this event is now the earliest event we know about, update the scheduler with our new minumum time.
Check if this event incurs a causality violation
Push the event onto our heap of pending events
void LPChare::recv_remote_event | ( | RemoteEvent * | event | ) |
Entry method for receiving a remote event from another chare.
event | an event sent from a different chare to an LP on this chare |
Inform the scheduler that the remote event was received (which may affect the GVT computation)
Allocate local space for the event and copy over the relevant fields
In optimistic execution the event needs to be hashed so that it can be found if it needs to be cancelled. Additionally, this checks to see if an anti-event for this event has already arrived in which case the event is immediately freed and ignored.
After pre-processing, the locally allocated event is passed to recv_local_event for the remainder of the work.
void LPChare::ResumeFromSync | ( | ) |
Called by the runtime system to tell this chare we can resume.
Do a reduction to inform the scheduler that balancing is complete
void LPChare::rollback_me | ( | Time | ts | ) |
Do a primary rollback to a given virtual timestamp.
ts | the virtual timestamp to rollback to |
Pop events from our processed queue and roll them back until the most recently processed event has a timestamp less than or equal to ts. Each rolled back event is pushed back onto the pending heap.
Update our min time in the scheduler, and current event and time to point to our new most recently processed event, or NULL if there are no longer any processed events.
void LPChare::rollback_me | ( | Event * | event | ) |
Do a secondary rollback to a particular event.
event | the event to rollback to |
Pop events from our processed queue until we pop an event matching the event passed in. For all events that don't match, we roll them back and push them back onto the pending heap.
Once we have found the event that was passed in, we roll it back as normal but then return control to the calling context, which will decide how to proceed.
Update our min time in the scheduler, and current event and time to point to our new most recently processed event, or NULL if there are no longer any processed events.
void LPChare::stop_scheduler | ( | ) |
Stops the Charm++ scheduler and returns control to main.
Just call CkExit(), which stops the Charm++ scheduler and returns control to the user defined main function.
void LPChare::UserSetLBLoad | ( | ) |
Called by the runtime system to get the load of this chare.
Sets the weight of this LP chare based on an application specific metric.
The metric used and how it is used is configured at runtime.
AvlTree LPChare::all_events |
|
private |
All future events received for any of our LPs.
The next_token LPToken gets its timestamp from the top of this heap.
|
private |
|
private |
A list of all LPs owned by this chare.
Initialized in the constructor based on maps set by the model.
|
private |
LPToken whose key is the timestamp of the next event this chare will execute.
It is updated when events are received, executed, or rolled back
|
private |
A flat queue of all events previously processed by our LPs that haven't yet been committed or rolled back.
The oldest_token LPToken gets its timestamp from the back of this queue.
|
private |