OpenAtom  Version1.5a
InputDataHandler.h
1 #include "debug_flags.h"
2 #include "inputDataHandler.decl.h"
3 #include "RDMAMessages.h"
4 #include "ckPairCalculator.h"
5 
6 
7 #ifndef INPUT_DATA_HANDLER_H
8 #define INPUT_DATA_HANDLER_H
9 
10 ///namespace cp {
11 ///namespace paircalc {
12 
13 /// Forward declaration of the message types
14 class paircalcInputMsg;
15 
16 /** A very thin wrapper class. Instantiated as a chare array that provides GSpace chares with an API to send the input data in.
17  * The intent is to permit a somewhat generic message handling behavior that doesnt require GSpace to jump through hoops.
18  *
19  * Currently it is desired to collate messages and compute on them later. Requirements might change later to require streamed
20  * computing etc which can be met by configuring this class with different message handlers.
21  *
22  * This is a template class only so that it does not have to pay the penalties associated with using base class pointers.
23  * The left and right message handlers could simply have been pointers to a base class MessageHandler. However,
24  * this would involve virtual function call overhead and would almost certainly prevent inlining of the handlers' operator().
25  * To avoid this and *yet* retain the ability to support new behavior at a later date, this has been made a template class.
26  * This should provide a relatively stable API for the GSpace chares to use, and all this template muck is only compile
27  * time overhead anyway.
28  *
29  * @note: Behavior expected of handlerType classes:
30  * - void handlerType::operator() (paircalcInputMsg *msg) : Used to pass in the messages for processing
31  * - void handlerType::setupRDMA(RDMASetupRequestMsg<RDMApair_GSP_PC> *msg,RDMApair_GSP_PC *tkn) : Used to pass on a RDMA setup request from a sender
32  */
33 template <class leftHandlerType, class rightHandlerType>
34 class InputDataHandler: public ArrayElement4D // CBaseT< ArrayElementT<CkIndex4D>,CProxy_InputDataHandler<leftHandlerType,rightHandlerType> >
35 {
36  public:
37  // ----------------------------------------- Cons/Des-truction -----------------------------------------
38  /// @entry An instance needs to be configured with the actual message handlers.
39  InputDataHandler(CProxy_PairCalculator pcProxy)
40  {
41  #ifdef DEBUG_CP_PAIRCALC_INPUTDATAHANDLER
42  CkPrintf("InputHandler[%d,%d,%d,%d] I was just born. Now I am going to try and get a direct handle to my parent PC\n",thisIndex.w,thisIndex.x,thisIndex.y,thisIndex.z);
43  #endif
44  /// Get a handle on your customer PairCalc chare array element
45  PairCalculator *myCustomerPC = pcProxy(thisIndex.w,thisIndex.x,thisIndex.y,thisIndex.z).ckLocal();
46  /// If your customer is on this same processor (which it MUST be) Ask it for pointers to the message handlers
47  if (myCustomerPC)
48  {
49  leftHandler = myCustomerPC->leftHandler();
50  rightHandler = myCustomerPC->rightHandler();
51  #ifdef DEBUG_CP_PAIRCALC_INPUTDATAHANDLER
52  CkPrintf("InputHandler[%d,%d,%d,%d] My left and right handlers: %p %p \n",thisIndex.w,thisIndex.x,thisIndex.y,thisIndex.z,leftHandler,rightHandler);
53  #endif
54 
55  }
56  else
57  CkAbort("InputHandler: My customer PairCalc object is not (yet?) on this processor. What am I doing here? I am aborting... \n");
58  //CkAbort("\nInputHandler[%d,%d,%d,%d] My customer PairCalc object is not (yet?) on this processor. What am I doing here? I am aborting...",thisIndex.w,thisIndex.x,thisIndex.y,thisIndex.z);
59  }
60  /// @entry migration constructor
61  InputDataHandler(CkMigrateMessage *msg) {}
62 
63  // ----------------------------------------- Entry Methods -----------------------------------------
64  /// @entry Deposit some data belonging to the left matrix block
65  inline void acceptLeftData(paircalcInputMsg *msg) { (*leftHandler)(msg); }
66  /// @entry Deposit some data belonging to the right matrix block
67  inline void acceptRightData(paircalcInputMsg *msg) { (*rightHandler)(msg); }
68 
69  // ----------------------------------------- RDMA Support -----------------------------------------
70  /// @entry Senders call this to setup an RDMA link to send the left matrix block
72  {
73  #ifndef PC_USE_RDMA
74  CkPrintf("InputDataHandler[%d %d %d %d]. Someone called an RDMA method on me when RDMA has not been enabled.\n",
75  thisIndex.w, thisIndex.x, thisIndex.y, thisIndex.z);
76  CkAbort("InputDataHandler aborting because someone called an RDMA method when it has been turned off for me...\n");
77  #endif
78  #ifdef DEBUG_CP_PAIRCALC_INPUTDATAHANDLER
79  CkPrintf("InputHandler[%d,%d,%d,%d] Received an RDMA channel setup request for left data from %d. \n",thisIndex.w,thisIndex.x,thisIndex.y,thisIndex.z,msg->sender());
80  #endif
81  /// Get a copy of the transaction token sent in the message
82  RDMApair_GSP_PC replyToken = msg->token();
83  /// Verify that the setup request has come to the correct place
84  CkAssert(replyToken.shouldSendLeft);
85  /// Insert receiver identification into the handshake token
86  replyToken.pcIndex = thisIndex;
87  /// Delegate the actual RDMA setup work to the message handler
88  leftHandler->setupRDMA(msg,&replyToken);
89  }
90 
91 
92  /// @entry Senders call this to setup an RDMA link to send the right matrix block
94  {
95  #ifndef PC_USE_RDMA
96  CkPrintf("InputDataHandler[%d %d %d %d]. Someone called an RDMA method on me when RDMA has not been enabled.\n",
97  thisIndex.w, thisIndex.x, thisIndex.y, thisIndex.z);
98  CkAbort("InputDataHandler aborting because someone called an RDMA method when it has been turned off for me...\n");
99  #endif
100  #ifdef DEBUG_CP_PAIRCALC_INPUTDATAHANDLER
101  CkPrintf("InputHandler[%d,%d,%d,%d] Received an RDMA channel setup request for right data from %d. \n",thisIndex.w,thisIndex.x,thisIndex.y,thisIndex.z,msg->sender());
102  #endif
103  /// Get a copy of the transaction token sent in the message
104  RDMApair_GSP_PC replyToken = msg->token();
105  /// Verify that the setup request has come to the correct place
106  CkAssert(!replyToken.shouldSendLeft);
107  /// Insert receiver identification into the handshake token
108  replyToken.pcIndex = thisIndex;
109  /// Delegate the actual RDMA setup work to the message handler
110  rightHandler->setupRDMA(msg,&replyToken);
111  }
112 
113  private:
114  /// A message handler object that actually handles incoming msgs carrying left matrix data
115  leftHandlerType *leftHandler;
116  /// A message handler object that actually handles incoming msgs carrying right matrix data
117  rightHandlerType *rightHandler;
118 };
119 
120 //} // end namespace paircalc
121 //} // end namespace cp
122 
123 /** This include is inside the #define block to avoid redefinition.
124  * def.h files dont have include guards and can cause problems for modules with template chares/messages.
125  */
126 #define CK_TEMPLATES_ONLY
127  #include "inputDataHandler.def.h"
128 #undef CK_TEMPLATES_ONLY
129 #endif // INPUT_DATA_HANDLER_H
130 
void setupRDMALeft(RDMASetupRequestMsg< RDMApair_GSP_PC > *msg)
Entry Method. Senders call this to setup an RDMA link to send the left matrix block.
CollatorType * leftHandler() const
Returns a pointer to the collator that will buffer the left matrix data (only for use by the correspo...
InputDataHandler(CkMigrateMessage *msg)
Entry Method. migration constructor.
InputDataHandler(CProxy_PairCalculator pcProxy)
Entry Method. An instance needs to be configured with the actual message handlers.
rightHandlerType * rightHandler
A message handler object that actually handles incoming msgs carrying right matrix data...
CollatorType * rightHandler() const
Returns a pointer to the collator that will buffer the right matrix data (only for use by the corresp...
The new message for sending input data to the PairCalculator.
Definition: pcMessages.h:117
A request from a data sender to setup an RDMA link. Initiates the sender-receiver handshake required ...
Definition: RDMAMessages.h:22
void acceptLeftData(paircalcInputMsg *msg)
Entry Method. Deposit some data belonging to the left matrix block.
void setupRDMARight(RDMASetupRequestMsg< RDMApair_GSP_PC > *msg)
Entry Method. Senders call this to setup an RDMA link to send the right matrix block.
tokenType token() const
Get a copy of the handshake token the sender created.
Definition: RDMAMessages.h:26
void acceptRightData(paircalcInputMsg *msg)
Entry Method. Deposit some data belonging to the right matrix block.
int sender() const
Get an integer representation of the sender's ID.
Definition: RDMAMessages.h:28
A (hopefully) tiny token that is unique to every data sender-receiver pair, and is shared by them dur...
Definition: RDMAMessages.h:94
A very thin wrapper class.
Useful debugging flags.
leftHandlerType * leftHandler
A message handler object that actually handles incoming msgs carrying left matrix data...