#include <source/toolbox/parallel/AsyncCommStage.h>
Public Member Functions | |
AsyncCommStage () | |
Construct a stage that may begin allocating and managing groups. | |
virtual | ~AsyncCommStage (void) |
Deallocate groups remaining in the stage and all internal data used to manage groups. | |
AsyncCommGroup * | allocateCommGroup (int nchild, RelaunchableJob *handle=NULL) |
Allocate a group in this stage. | |
RelaunchableJob * | advanceAny () |
Advance to completion one group (any group) that is currently waiting for communication to complete. | |
int | advanceSome (Array< RelaunchableJob * > &completed) |
Advance to completion one or more groups (any groups) that are currently waiting for communication to complete. | |
bool | isDone () const |
Return whether the stage is done with all requested communications. | |
bool | numberOfOutstandingGroups () const |
Return the number of allocated groups that have pending communication. | |
bool | numberOfOutstandingRequests () const |
Return the number of pending MPI::request objects. | |
Friends | |
class | StagedGroup |
Use this class when you
This class allocates a set of AsyncCommGroup objects and manages the space for their MPI::request's. The requests are staged such that a single MPI_Waitany or MPI_Waitsome call applies to all communication groups allocated by the stage. Thus the communications performed by the AsyncCommGroup objects can complete in the order allowed by the MPI messages. The exact order is NOT deterministic!
To advance the communication operation of any of the allocated AsyncCommGroup objects, use advanceAny() or advanceSome(). In general, advanceSome() has better performance than advanceAny() because it gets around the "starvation" problem. See the MPI documentation for a discussion of starvation.
This class supports communication and uses MPI for message passing. If MPI is disabled, the job of this class disappears and the class is effectively empty, except for allocating and deallocating AsyncCommGroup objects. The public interfaces still remain so the class can compile, but the implementations are trivial.
|
Construct a stage that may begin allocating and managing groups.
|
|
Deallocate groups remaining in the stage and all internal data used to manage groups.
|
|
Allocate a group in this stage. You may specify a handle associated with the allocated group and pointing back to an object. These pointers are returned when their group communications are completed by the stage methods advanceAny() or advanceSome(). They help identify the user object waiting for the communication to complete. To use the handle, create a user class inheritting from RelaunchableJob so that any handle can be dynamically casted back to the user class. Usage outline:
Usage example: * class UserClass : RelaunchableJob { ... }; * UserClass user_object[10]; * AsyncCommStage stage; * for ( i=0; i<10; ++i ) { * AsyncCommGroup *group = * stage.allocateCommGroup( 2, &user_object[i] ); * useGroupToInitiateCommunication(group); * } * RelaunchableJob *handle = stage.advanceAny(); * UserClass *completed_user_object = dynamic_cast<UserClass*>(handle); * Allocating a group with a NULL handle works, but you lose the ability to map a specific communication back to a user object. See advanceAny() and advanceSome(). An allocated group should be deallocated using the delete operator when no longer needed. All allocated groups will be deleted when the stage goes out of scope. Since it is an error to delete a group that has pending message requests, it is also an error to delete a stage that has groups with pending message requests.
|
|
Advance to completion one group (any group) that is currently waiting for communication to complete. This method uses MPI_Waitany, which may be prone to starvation. It is better to use advanceSome(), which uses MPI_Waitsome, which avoids starvation.
|
|
Advance to completion one or more groups (any groups) that are currently waiting for communication to complete.
|
|
Return whether the stage is done with all requested communications.
|
|
Return the number of allocated groups that have pending communication.
|
|
Return the number of pending MPI::request objects.
|
|
|