Charades
Public Member Functions | Public Attributes | Private Attributes | List of all members
LPChare Class Reference

A chare that encapsulates a set of LPStructs and their events. More...

#include <lp.h>

Inheritance diagram for LPChare:

Public Member Functions

 LPChare ()
 Default constructor. More...
 
 LPChare (CkMigrateMessage *m)
 Migration constructor.
 
uint64_t get_next_event_id ()
 
Eventget_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.

Todo:
Some changes to events should be made to simplify/unify pupping
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.
 
Eventcurrent_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...
 
Schedulerscheduler
 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.

Eventcancel_q
 Queue of events this LP needs to cancel.
 
Time min_cancel_q
 Minimum time in this LPs cancel queue.
 

Detailed Description

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.

Todo:
See if moving the AVL tree from the scheduler to here would be feasible and not mess up performance.
Todo:
Converting AVL tree to an STL type or an array based structure would make migration way simpler.

Constructor & Destructor Documentation

◆ LPChare()

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.

Todo:
Remove this if we no longer need a global lp proxy

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.

Member Function Documentation

◆ add_to_cancel_q()

void LPChare::add_to_cancel_q ( Event e)

Add an event to the queue of events to be cancelled later.

Parameters
ethe 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

◆ cancel_event()

void LPChare::cancel_event ( Event event)

Cancel an event that should have never been received.

Parameters
ethe event to be cancelled
Precondition
the event e exists in either the pending heap or processed queue



Call a different method based on where e currently exists


If the event hasn't been executed yet, just delete from pending heap

If the event was alredy executed, add it to the cancel queue
If the event exists somewhere else, this is an error

◆ delete_pending()

void LPChare::delete_pending ( Event event)

Cancel an event from the pending queue by simply removing it.

Parameters
ethe event to delete from the pending queue

Must also update the min time of this LP chare in the scheduler

◆ execute_me()

int LPChare::execute_me ( )

Called during execution to execute the next event owned by this LP.

Returns
false if no events are able to be executed

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

◆ fossil_me()

void LPChare::fossil_me ( Time  gvt)

Called after GVT computation to commit old events.

Parameters
gvtthe 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.

◆ init()

void LPChare::init ( )

Called at the start of a simulation to run LP init handlers.

Call the init handler on every LP struct owned by this chare, then do a reduction to stop the charm scheduler.

◆ load_balance()

void LPChare::load_balance ( )

Tell this chare that we are going to do load balancing.

Just call AtSync to trigger automatic load balancing

◆ process_cancel_q()

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.

Note
Cancelling an event in the queue can cause a new even to be added to the queue which is why a double loop is required.
Even though only events in the processed queue are placed in the cancel queue, they may be rolled back via other means and therefore end up in the pending heap for this step.

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

◆ recv_anti_event()

void LPChare::recv_anti_event ( RemoteEvent event)

Entry method for receiving and processing an anti event.

Parameters
eventan anti event sent from another chare

Inform the scheduler that the anti event was received (which may affect the GVT computation)

Todo:
This might not be needed once CD is no longer used for GVT

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

◆ recv_local_event()

void LPChare::recv_local_event ( Event e)

Regular method for common processing on locally allocated events.

Parameters
ea 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

Todo:
Locally sent events can't cause violations so this should be moved to the remote handler.

Push the event onto our heap of pending events

◆ recv_remote_event()

void LPChare::recv_remote_event ( RemoteEvent event)

Entry method for receiving a remote event from another chare.

Parameters
eventan 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.

◆ ResumeFromSync()

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

◆ rollback_me() [1/2]

void LPChare::rollback_me ( Time  ts)

Do a primary rollback to a given virtual timestamp.

Parameters
tsthe 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.

◆ rollback_me() [2/2]

void LPChare::rollback_me ( Event event)

Do a secondary rollback to a particular event.

Parameters
eventthe 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.

◆ stop_scheduler()

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.

Note
CkCallbacks cannot currently just directly call CkExit because it will exit the whole program instead of just the scheduler.
Todo:
This should be moved to a standalone function at least and maybe even stored in a global CkCallback variable.

◆ UserSetLBLoad()

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.

See also
g_tw_ldb_metric
g_tw_metric_ts_abs
g_tw_metric_invert

Member Data Documentation

◆ all_events

AvlTree LPChare::all_events

A pointer to the PE level AVL tree for hashing remote events.

Todo:
should this be move to the LP level?

◆ events

PendingHeap LPChare::events
private

All future events received for any of our LPs.

The next_token LPToken gets its timestamp from the top of this heap.

◆ isOptimistic

bool LPChare::isOptimistic
private

Set to true if this LP is an optimistic LP.

Todo:
Should the LP class be specialised based on sync protocol as well?

◆ lp_structs

vector<LPBase*> LPChare::lp_structs
private

A list of all LPs owned by this chare.

Initialized in the constructor based on maps set by the model.

◆ next_token

LPToken LPChare::next_token
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

◆ processed_events

ProcessedQueue LPChare::processed_events
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.

◆ scheduler

Scheduler* LPChare::scheduler
private

A direct pointer to the scheduler managing this LP chare.

The scheduler map be sequential, optimistic, or conservative.

Todo:
Should the LP class be specialized based on sync protocol as well?

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