|
IBAMR
IBAMR version 0.19.
|
Stage multiple asynchronous group communications so that the collective can advance asynchronously (as individual underlying MPI requests are completed). More...
#include <tbox/AsyncCommStage.h>
Classes | |
| struct | StagedGroup |
| Augmented AsyncCommGroup, to operate on a stage. More... | |
Public Member Functions | |
| AsyncCommStage () | |
| Construct a stage that may begin allocating and managing groups. More... | |
| virtual | ~AsyncCommStage (void) |
| Deallocate groups remaining in the stage and all internal data used to manage groups. More... | |
| AsyncCommGroup * | allocateCommGroup (int nchild, RelaunchableJob *handle=NULL) |
| Allocate a group in this stage. More... | |
| RelaunchableJob * | advanceAny () |
| Advance to completion one group (any group) that is currently waiting for communication to complete. More... | |
| int | advanceSome (Array< RelaunchableJob * > &completed) |
| Advance to completion one or more groups (any groups) that are currently waiting for communication to complete. More... | |
| bool | isDone () const |
| Return whether the stage is done with all requested communications. More... | |
| bool | numberOfOutstandingGroups () const |
| Return the number of allocated groups that have pending communication. More... | |
| bool | numberOfOutstandingRequests () const |
| Return the number of pending SAMRAI_MPI::request objects. More... | |
Private Types | |
| typedef StagedGroup * | StagedGroupPtr |
| Trivial typedef used by SAMRAI template scripts to generate code to instantiate Array<StagedGroup*> (not used anywhere else). More... | |
Private Member Functions | |
| void | destageGroup (StagedGroup *group) |
| Clear references to a group allocated on this stage. More... | |
| SAMRAI_MPI::request * | lookupRequestPointer (const int igroup) const |
| Lookup and return the request pointer from the stage for the given group. More... | |
Static Private Member Functions | |
| static void | freeTimers () |
Private Attributes | |
| int | d_n_group |
| Number of groups (including deallocated groups) that are still occupying space in the stage. More... | |
| int | d_n_req |
| Number of request slots, including unused ones that belonged to deallocated groups. More... | |
| Array< StagedGroup * > | d_group |
| Groups managed in this stage. More... | |
| Array< SAMRAI_MPI::request > | d_req |
| SAMRAI_MPI::request objects used by the groups. More... | |
| Array< int > | d_req_to_group |
| Map from request index to group index. More... | |
| Array< int > | d_group_to_req |
| Map from group index to (the group's first) request index. More... | |
Static Private Attributes | |
| static Pointer< Timer > | t_wait_any |
| static Pointer< Timer > | t_wait_some |
Friends | |
| struct | StagedGroup |
Use this class when you
This class allocates a set of AsyncCommGroup objects and manages the space for their SAMRAI_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.
|
private |
| SAMRAI::tbox::AsyncCommStage::AsyncCommStage | ( | ) |
|
virtual |
| AsyncCommGroup* SAMRAI::tbox::AsyncCommStage::allocateCommGroup | ( | int | nchild, |
| RelaunchableJob * | handle = NULL |
||
| ) |
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.
| nchild | Number of child branches per tree node (see AsyncCommGroup). |
| handle | Optional pointer back to a user object associated with the group. See class documentation. |
| RelaunchableJob* SAMRAI::tbox::AsyncCommStage::advanceAny | ( | ) |
This method uses MPI_Waitany, which may be prone to starvation. It is better to use advanceSome(), which uses MPI_Waitsome, which avoids starvation.
| int SAMRAI::tbox::AsyncCommStage::advanceSome | ( | Array< RelaunchableJob * > & | completed | ) |
| completed | Array space to put handleegies associated with the completed communications. |
completed array. | bool SAMRAI::tbox::AsyncCommStage::isDone | ( | ) | const |
| bool SAMRAI::tbox::AsyncCommStage::numberOfOutstandingGroups | ( | ) | const |
| bool SAMRAI::tbox::AsyncCommStage::numberOfOutstandingRequests | ( | ) | const |
|
private |
To ONLY be be used just before freeing an allocated group. This clears the references so that the group can be deallocated without leaving behind broken references.
|
private |
The given group MUST have been allocated by the stage. The number of requests that the group may use is the same as the number of children the group has on each branch.
The pointer is NOT guaranteed to be the same for the life of the group, as a stage may rearange the array of SAMRAI_MPI::request objects. However, the pointer is valid until the next call to allocateCommGroup().
This is private because only friend class StagedGroup should use it.
|
staticprivate |
Free static timers.
To be called by shutdown registry to make sure memory for timers does not leak.
|
friend |
|
private |
|
private |
|
private |
|
mutableprivate |
This is mutable because the const method getRequestPointer() needs to return a non-const SAMRAI_MPI::request pointer. The pointer must be non-const for use in MPI calls. getRequestPointer() should be const because no group should require a non-const stage just to get the request allocated for it.
1.8.17