MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PostMaster.h
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2013 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
65 #ifndef _POST_MASTER_H
66 #define _POST_MASTER_H
67 
68 #ifdef USE_MPI
69 #include <mpi.h>
70 #endif
71 
72 class TgtInfo {
73  public:
75  : id_(),
76  bindIndex_( 0 ), dataSize_( 0 )
77  {;}
78 
79  Eref eref() const {
80  return Eref( id_.eref() );
81  }
82 
83  void set( ObjId id, unsigned int bindIndex, unsigned int size ) {
84  id_ = id;
86  dataSize_ = size;
87  }
88 
89  unsigned int dataSize() const {
90  return dataSize_;
91  }
92 
93  unsigned int bindIndex() const {
94  return bindIndex_;
95  }
96 
97  static const unsigned int headerSize;
98  private:
100  unsigned int bindIndex_;
101  unsigned int dataSize_; // Does double duty for SetGet operations as a flag to indicate type of operation.
102 };
103 
104 class PostMaster {
105  public:
106  PostMaster();
107  unsigned int getNumNodes() const;
108  unsigned int getMyNode() const;
109  unsigned int getBufferSize() const;
110  void setBufferSize( unsigned int size );
111  void reinit( const Eref& e, ProcPtr p );
112  void process( const Eref& e, ProcPtr p );
113 
115  void clearPending();
117  void clearPendingSetGet();
119  void clearPendingRecv();
121  void finalizeSends();
122 
124  void handleRemoteGet( const Eref& e,
125  const OpFunc* op, int requestingNode );
126 
127  void handleRemoteGetVec( const Eref& e,
128  const OpFunc* op, int requestingNode );
129 
131  double* addToSendBuf( const Eref& e,
132  unsigned int bindIndex, unsigned int size );
134  double* addToSetBuf( const Eref& e,
135  unsigned int opIndex, unsigned int size, unsigned int hopType );
137  void dispatchSetBuf( const Eref& e );
138 
140  double* remoteGet( const Eref& e, unsigned int bindIndex );
141  void remoteGetVec( const Eref& e, unsigned int bindIndex,
142  vector< vector< double > >& getRecvBuf,
143  vector< unsigned int >& size );
144  void remoteFieldGetVec( const Eref& e, unsigned int bindIndex,
145  vector< double >& getRecvBuf );
146 
147  static const unsigned int reserveBufSize;
148  static const unsigned int setRecvBufSize;
149  static const int MSGTAG;
150  static const int SETTAG;
151  static const int GETTAG;
152  static const int RETURNTAG;
153  static const int CONTROLTAG;
154  static const int DIETAG;
155  static const Cinfo* initCinfo();
156  private:
157  unsigned int recvBufSize_;
158  // Used on master for sending, on others for receiving.
159  vector< double > setSendBuf_;
160  vector< double > setRecvBuf_;
161  vector< vector< double > > sendBuf_;
162  vector< vector< double > > recvBuf_;
163  vector< unsigned int > sendSize_;
164  vector< double > getHandlerBuf_; // Just enough for one TgtInfo.
165 #ifdef USE_MPI
166  MPI_Request setSendReq_;
167  MPI_Request setRecvReq_;
168  MPI_Request getHandlerReq_;
169  MPI_Status setSendStatus_;
170  MPI_Status setRecvStatus_;
171  vector< MPI_Request > recvReq_;
172  vector< MPI_Request > sendReq_;
173  vector< MPI_Status > doneStatus_;
174 #endif // USE_MPI
175  vector< int > doneIndices_;
179  unsigned int numRecvDone_;
180 };
181 
182 #endif // _POST_MASTER_H
static const int DIETAG
Definition: PostMaster.h:154
unsigned int dataSize_
Definition: PostMaster.h:101
vector< double > setRecvBuf_
Definition: PostMaster.h:160
static const int SETTAG
Definition: PostMaster.h:150
ObjId id_
Definition: PostMaster.h:99
void handleRemoteGet(const Eref &e, const OpFunc *op, int requestingNode)
Handles 'get' calls from another node, to an object on mynode.
Definition: PostMaster.cpp:223
Eref eref() const
Definition: PostMaster.h:79
void dispatchSetBuf(const Eref &e)
Sends off contets of Set buffer.
Definition: PostMaster.cpp:487
static double op(double x)
unsigned int getNumNodes() const
Definition: PostMaster.cpp:704
unsigned int bindIndex() const
Definition: PostMaster.h:93
double * addToSendBuf(const Eref &e, unsigned int bindIndex, unsigned int size)
Returns pointer to Send buffer for filling in arguments.
Definition: PostMaster.cpp:442
unsigned int dataSize() const
Definition: PostMaster.h:89
void remoteGetVec(const Eref &e, unsigned int bindIndex, vector< vector< double > > &getRecvBuf, vector< unsigned int > &size)
This is a blocking call. However, it must still handle other.
Definition: PostMaster.cpp:623
vector< vector< double > > recvBuf_
Definition: PostMaster.h:162
static const unsigned int headerSize
Definition: PostMaster.h:97
Definition: ObjId.h:20
static const int GETTAG
Definition: PostMaster.h:151
static const int CONTROLTAG
Definition: PostMaster.h:153
unsigned int getBufferSize() const
Definition: PostMaster.cpp:714
int isSetSent_
Definition: PostMaster.h:176
int setSendSize_
Definition: PostMaster.h:178
vector< unsigned int > sendSize_
Definition: PostMaster.h:163
void reinit(const Eref &e, ProcPtr p)
Definition: PostMaster.cpp:164
void process(const Eref &e, ProcPtr p)
Definition: PostMaster.cpp:190
vector< double > setSendBuf_
Definition: PostMaster.h:159
unsigned int recvBufSize_
Definition: PostMaster.h:157
double * remoteGet(const Eref &e, unsigned int bindIndex)
Blocking call to get a value from a remote node.
Definition: PostMaster.cpp:520
static const int MSGTAG
Definition: PostMaster.h:149
vector< int > doneIndices_
Definition: PostMaster.h:175
void clearPendingSetGet()
Clears arrived set and get calls.
Definition: PostMaster.cpp:299
unsigned int bindIndex_
Definition: PostMaster.h:100
void setBufferSize(unsigned int size)
Definition: PostMaster.cpp:722
Definition: Eref.h:26
unsigned int getMyNode() const
Definition: PostMaster.cpp:709
vector< vector< double > > sendBuf_
Definition: PostMaster.h:161
void clearPendingRecv()
Clears arrived messages.
Definition: PostMaster.cpp:383
unsigned int numRecvDone_
Definition: PostMaster.h:179
void clearPending()
All arrived messages and set calls are handled and cleared.
Definition: PostMaster.cpp:215
Eref eref() const
Definition: ObjId.cpp:66
void set(ObjId id, unsigned int bindIndex, unsigned int size)
Definition: PostMaster.h:83
void remoteFieldGetVec(const Eref &e, unsigned int bindIndex, vector< double > &getRecvBuf)
This is a blocking call. However, it must still handle other.
Definition: PostMaster.cpp:568
void handleRemoteGetVec(const Eref &e, const OpFunc *op, int requestingNode)
Definition: PostMaster.cpp:284
void finalizeSends()
Checks that all sends have gone out.
Definition: PostMaster.cpp:147
double * addToSetBuf(const Eref &e, unsigned int opIndex, unsigned int size, unsigned int hopType)
Returns pointer to Set buffer for filling in arguments.
Definition: PostMaster.cpp:463
static const Cinfo * initCinfo()
Definition: PostMaster.cpp:82
static char id[]
Definition: mfield.cpp:404
vector< double > getHandlerBuf_
Definition: PostMaster.h:164
int isSetRecv_
Definition: PostMaster.h:177
static const unsigned int reserveBufSize
Definition: PostMaster.h:147
Definition: Cinfo.h:18
TgtInfo()
Definition: PostMaster.h:74
static const int RETURNTAG
Definition: PostMaster.h:152
static const unsigned int setRecvBufSize
Definition: PostMaster.h:148