HavoqGT
havoqgt::mpi::termination_detection< SizeType > Class Template Reference

#include <termination_detection.hpp>

Collaboration diagram for havoqgt::mpi::termination_detection< SizeType >:

Public Types

typedef SizeType size_type
 
typedef std::pair< size_type, size_typestatus_response_type
 

Public Member Functions

 termination_detection (MPI_Comm in_mpi_comm, int in_num_tree_children=2, int in_query_status_tag=2, int in_query_response_tag=3, int in_terminate_tag=4)
 
void inc_queued (size_t _i=1)
 
void inc_completed (size_t _i=1)
 
bool test_for_termination ()
 

Private Types

enum  termination_detection_state_type { WAITING_INIT, WAITING_ISEND_CHILDREN, WAITING_RECV_CHILDREN, WAITING_ISEND_PARENT }
 

Private Member Functions

bool test_for_termination_internal (const size_type &in_queued, const size_type &in_completed)
 
bool handle_waiting_init (const size_type &in_queued, const size_type &in_completed)
 
bool handle_waiting_isend_children (const size_type &in_queued, const size_type &in_completed)
 
bool handle_waiting_recv_children (const size_type &in_queued, const size_type &in_completed)
 
bool handle_waiting_isend_parent (const size_type &in_queued, const size_type &in_completed)
 
void send_terminate_to_children ()
 
bool mpi_test (MPI_Request &in_req)
 
void isend_status_response_to_parent ()
 
bool mpi_iprobe (int in_source, int in_tag)
 
void send_query_status_to_children ()
 
int parent_rank ()
 
int begin_child_rank ()
 
bool is_leaf_rank ()
 
int num_children ()
 

Private Attributes

MPI_Comm m_mpi_comm
 Configuration parameters. More...
 
int m_num_tree_children
 
int m_query_status_tag
 
int m_query_response_tag
 
int m_terminate_tag
 
int m_mpi_size
 
int m_mpi_rank
 
termination_detection_state_type m_current_state
 
std::vector< MPI_Request > m_vec_req_isend_children
 
MPI_Request m_req_isend_parent
 
status_response_typem_ptr_buf_isend_parent
 
int m_num_waiting_recv_children
 
status_response_type m_subtree_status_response
 
status_response_type m_previous_subtree_status_response
 
size_type m_count_queued
 
size_type m_count_completed
 

Detailed Description

template<typename SizeType>
class havoqgt::mpi::termination_detection< SizeType >

Definition at line 97 of file termination_detection.hpp.

Member Typedef Documentation

template<typename SizeType>
typedef SizeType havoqgt::mpi::termination_detection< SizeType >::size_type

Definition at line 102 of file termination_detection.hpp.

template<typename SizeType>
typedef std::pair<size_type, size_type> havoqgt::mpi::termination_detection< SizeType >::status_response_type

Definition at line 103 of file termination_detection.hpp.

Member Enumeration Documentation

Constructor & Destructor Documentation

template<typename SizeType>
havoqgt::mpi::termination_detection< SizeType >::termination_detection ( MPI_Comm  in_mpi_comm,
int  in_num_tree_children = 2,
int  in_query_status_tag = 2,
int  in_query_response_tag = 3,
int  in_terminate_tag = 4 
)
inline

Definition at line 105 of file termination_detection.hpp.

109  {
110  m_mpi_comm = in_mpi_comm;
111  m_num_tree_children = in_num_tree_children;
112  m_query_status_tag = in_query_status_tag;
113  m_query_response_tag = in_query_response_tag;
114  m_terminate_tag = in_terminate_tag;
115  CHK_MPI( MPI_Comm_rank( m_mpi_comm, &m_mpi_rank) );
116  CHK_MPI( MPI_Comm_size( m_mpi_comm, &m_mpi_size) );
121  status_response_type(std::numeric_limits<size_type>::max(),
122  std::numeric_limits<size_type>::max());
123 
124  m_count_queued = 0;
125  m_count_completed = 0;
126  /*for(int i=0; i<m_mpi_size; ++i) {
127  if(m_mpi_rank == i) {
128  std::cout << m_mpi_rank << " parent_rank() = " << parent_rank() << std::endl;
129  std::cout << m_mpi_rank << " begin_child_rank() = " << begin_child_rank() << std::endl;
130  std::cout << m_mpi_rank << " is_leaf_rank() = " << is_leaf_rank() << std::endl;
131  std::cout << m_mpi_rank << " num_children() = " << num_children() << std::endl;
132  std::cout << std::endl;
133  }
134  MPI_Barrier(in_mpi_comm);
135 
136  }
137  exit(-1);*/
138  }
std::pair< size_type, size_type > status_response_type
status_response_type m_previous_subtree_status_response
MPI_Comm m_mpi_comm
Configuration parameters.
termination_detection_state_type m_current_state
#define CHK_MPI(a)
Definition: mpi.hpp:68

Member Function Documentation

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::begin_child_rank ( )
inlineprivate

Definition at line 303 of file termination_detection.hpp.

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::handle_waiting_init ( const size_type in_queued,
const size_type in_completed 
)
inlineprivate

Definition at line 163 of file termination_detection.hpp.

164  {
165  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
166  m_subtree_status_response.first = 0;
167  m_subtree_status_response.second = 0;
168  if(m_mpi_rank == 0) {
171  } else {
173  CHK_MPI( MPI_Recv(NULL, 0, MPI_BYTE, parent_rank(), m_terminate_tag, m_mpi_comm, MPI_STATUS_IGNORE) );
176  return true;
177  }
178  else if(mpi_iprobe(/*parent_rank()*/MPI_ANY_SOURCE, m_query_status_tag)) {
179  //std::cout << m_mpi_rank << "ReceivedInit" << std::endl;
180  CHK_MPI( MPI_Recv(NULL, 0, MPI_BYTE, parent_rank(), m_query_status_tag,
181  m_mpi_comm, MPI_STATUS_IGNORE) );
184  }
185  }
186  return false;
187  }
MPI_Comm m_mpi_comm
Configuration parameters.
termination_detection_state_type m_current_state
bool mpi_iprobe(int in_source, int in_tag)
#define CHK_MPI(a)
Definition: mpi.hpp:68

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::handle_waiting_isend_children ( const size_type in_queued,
const size_type in_completed 
)
inlineprivate

Definition at line 189 of file termination_detection.hpp.

190  {
191  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
192  while(!m_vec_req_isend_children.empty()) {
194  m_vec_req_isend_children.pop_back();
195  else
196  break;
197  }
198  if(m_vec_req_isend_children.empty())
200  return false;
201  }
std::vector< MPI_Request > m_vec_req_isend_children
termination_detection_state_type m_current_state

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::handle_waiting_isend_parent ( const size_type in_queued,
const size_type in_completed 
)
inlineprivate

Definition at line 250 of file termination_detection.hpp.

251  {
252  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
255  }
256  return false;
257  }
termination_detection_state_type m_current_state

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::handle_waiting_recv_children ( const size_type in_queued,
const size_type in_completed 
)
inlineprivate

Definition at line 203 of file termination_detection.hpp.

204  {
205  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
206  if(is_leaf_rank()) {
207  m_subtree_status_response.first += in_queued;
208  m_subtree_status_response.second += in_completed;
211  } else {
212  status_response_type recv_buf;
213  while(mpi_iprobe(MPI_ANY_SOURCE, m_query_response_tag)) {
215  CHK_MPI( MPI_Recv( (void*) &recv_buf, sizeof(status_response_type),
216  MPI_BYTE, MPI_ANY_SOURCE, m_query_response_tag,
217  m_mpi_comm, MPI_STATUS_IGNORE) );
218  m_subtree_status_response.first += recv_buf.first;
219  m_subtree_status_response.second += recv_buf.second;
220  }
221  if(m_num_waiting_recv_children == 0) {
223  m_subtree_status_response.first += in_queued;
224  m_subtree_status_response.second += in_completed;
225  if(m_mpi_rank == 0) {
230  return true;
231  } else {
233  }
234  } else {
235  // This is a place we can debug termination detection
236  //std::cout << "m_subtree_status_response = " << m_subtree_status_response.first
237  // << ", " << m_subtree_status_response.second << std::endl;
238  }
240  return false;
241  } else {
244  }
245  }
246  }
247  return false;
248  }
std::pair< size_type, size_type > status_response_type
status_response_type m_previous_subtree_status_response
MPI_Comm m_mpi_comm
Configuration parameters.
termination_detection_state_type m_current_state
bool mpi_iprobe(int in_source, int in_tag)
#define CHK_MPI(a)
Definition: mpi.hpp:68

Here is the caller graph for this function:

template<typename SizeType>
void havoqgt::mpi::termination_detection< SizeType >::inc_completed ( size_t  _i = 1)
inline

Definition at line 141 of file termination_detection.hpp.

Here is the caller graph for this function:

template<typename SizeType>
void havoqgt::mpi::termination_detection< SizeType >::inc_queued ( size_t  _i = 1)
inline

Definition at line 140 of file termination_detection.hpp.

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::is_leaf_rank ( )
inlineprivate

Definition at line 304 of file termination_detection.hpp.

Here is the caller graph for this function:

template<typename SizeType>
void havoqgt::mpi::termination_detection< SizeType >::isend_status_response_to_parent ( )
inlineprivate

Definition at line 275 of file termination_detection.hpp.

275  {
276  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
277  CHK_MPI( MPI_Isend( (void*) &m_subtree_status_response, sizeof(status_response_type),
278  MPI_BYTE, parent_rank(), m_query_response_tag,
280  }
std::pair< size_type, size_type > status_response_type
MPI_Comm m_mpi_comm
Configuration parameters.
#define CHK_MPI(a)
Definition: mpi.hpp:68

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::mpi_iprobe ( int  in_source,
int  in_tag 
)
inlineprivate

Definition at line 282 of file termination_detection.hpp.

282  {
283  //std::cout << m_mpi_rank << " " << __FUNCTION__ << " source = " << in_source << " tag = " << in_tag << std::endl;
284  MPI_Status status;
285  int flag(0);
286  CHK_MPI( MPI_Iprobe(in_source, in_tag, m_mpi_comm, &flag, &status) );
287  return flag == 1;
288  }
MPI_Comm m_mpi_comm
Configuration parameters.
#define CHK_MPI(a)
Definition: mpi.hpp:68

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::mpi_test ( MPI_Request &  in_req)
inlineprivate

Definition at line 268 of file termination_detection.hpp.

268  {
269  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
270  int flag(0);
271  CHK_MPI( MPI_Test( &(in_req), &flag, MPI_STATUS_IGNORE) );
272  return flag == 1;
273  }
#define CHK_MPI(a)
Definition: mpi.hpp:68

Here is the caller graph for this function:

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::num_children ( )
inlineprivate

Definition at line 305 of file termination_detection.hpp.

305  {
306  int to_return = std::min(m_num_tree_children, m_mpi_size - begin_child_rank());
307  if (to_return < 0) to_return = 0;
308  return to_return;
309  }

Here is the caller graph for this function:

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::parent_rank ( )
inlineprivate

Definition at line 302 of file termination_detection.hpp.

Here is the caller graph for this function:

template<typename SizeType>
void havoqgt::mpi::termination_detection< SizeType >::send_query_status_to_children ( )
inlineprivate

Definition at line 290 of file termination_detection.hpp.

290  {
291  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
292  for(int i=0; i<num_children(); ++i) {
293  int child_rank = i + begin_child_rank();
294  MPI_Request isend_request;
295  //std::cout << m_mpi_rank << "MPI_Isend -- " << child_rank << " " << m_query_status_tag << std::endl;
296  CHK_MPI( MPI_Isend(NULL, 0, MPI_BYTE, child_rank, m_query_status_tag,
297  m_mpi_comm, &isend_request) );
298  m_vec_req_isend_children.push_back(isend_request);
299  }
300  }
std::vector< MPI_Request > m_vec_req_isend_children
MPI_Comm m_mpi_comm
Configuration parameters.
#define CHK_MPI(a)
Definition: mpi.hpp:68

Here is the caller graph for this function:

template<typename SizeType>
void havoqgt::mpi::termination_detection< SizeType >::send_terminate_to_children ( )
inlineprivate

Definition at line 259 of file termination_detection.hpp.

259  {
260  //std::cout << m_mpi_rank << " " << __FUNCTION__ << std::endl;
261  for(int i=0; i<num_children(); ++i) {
262  int child_rank = i + begin_child_rank();
263  CHK_MPI( MPI_Send(NULL, 0, MPI_BYTE, child_rank, m_terminate_tag,
264  m_mpi_comm) );
265  }
266  }
MPI_Comm m_mpi_comm
Configuration parameters.
#define CHK_MPI(a)
Definition: mpi.hpp:68

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::test_for_termination ( )
inline

Definition at line 143 of file termination_detection.hpp.

143  {
145  }
bool test_for_termination_internal(const size_type &in_queued, const size_type &in_completed)

Here is the caller graph for this function:

template<typename SizeType>
bool havoqgt::mpi::termination_detection< SizeType >::test_for_termination_internal ( const size_type in_queued,
const size_type in_completed 
)
inlineprivate

Definition at line 148 of file termination_detection.hpp.

149  {
150  switch(m_current_state) {
151  case WAITING_INIT:
152  return handle_waiting_init(in_queued, in_completed);
154  return handle_waiting_isend_children(in_queued, in_completed);
156  return handle_waiting_recv_children(in_queued, in_completed);
158  return handle_waiting_isend_parent(in_queued, in_completed);
159  };
160  return false;
161  }
bool handle_waiting_recv_children(const size_type &in_queued, const size_type &in_completed)
bool handle_waiting_isend_children(const size_type &in_queued, const size_type &in_completed)
termination_detection_state_type m_current_state
bool handle_waiting_init(const size_type &in_queued, const size_type &in_completed)
bool handle_waiting_isend_parent(const size_type &in_queued, const size_type &in_completed)

Here is the caller graph for this function:

Member Data Documentation

template<typename SizeType>
size_type havoqgt::mpi::termination_detection< SizeType >::m_count_completed
private

Definition at line 333 of file termination_detection.hpp.

template<typename SizeType>
size_type havoqgt::mpi::termination_detection< SizeType >::m_count_queued
private

Definition at line 332 of file termination_detection.hpp.

template<typename SizeType>
termination_detection_state_type havoqgt::mpi::termination_detection< SizeType >::m_current_state
private

Definition at line 322 of file termination_detection.hpp.

template<typename SizeType>
MPI_Comm havoqgt::mpi::termination_detection< SizeType >::m_mpi_comm
private

Configuration parameters.

Definition at line 313 of file termination_detection.hpp.

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::m_mpi_rank
private

Definition at line 320 of file termination_detection.hpp.

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::m_mpi_size
private

Definition at line 319 of file termination_detection.hpp.

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::m_num_tree_children
private

Definition at line 314 of file termination_detection.hpp.

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::m_num_waiting_recv_children
private

Definition at line 328 of file termination_detection.hpp.

template<typename SizeType>
status_response_type havoqgt::mpi::termination_detection< SizeType >::m_previous_subtree_status_response
private

Definition at line 330 of file termination_detection.hpp.

template<typename SizeType>
status_response_type* havoqgt::mpi::termination_detection< SizeType >::m_ptr_buf_isend_parent
private

Definition at line 327 of file termination_detection.hpp.

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::m_query_response_tag
private

Definition at line 316 of file termination_detection.hpp.

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::m_query_status_tag
private

Definition at line 315 of file termination_detection.hpp.

template<typename SizeType>
MPI_Request havoqgt::mpi::termination_detection< SizeType >::m_req_isend_parent
private

Definition at line 326 of file termination_detection.hpp.

template<typename SizeType>
status_response_type havoqgt::mpi::termination_detection< SizeType >::m_subtree_status_response
private

Definition at line 329 of file termination_detection.hpp.

template<typename SizeType>
int havoqgt::mpi::termination_detection< SizeType >::m_terminate_tag
private

Definition at line 317 of file termination_detection.hpp.

template<typename SizeType>
std::vector<MPI_Request> havoqgt::mpi::termination_detection< SizeType >::m_vec_req_isend_children
private

Definition at line 324 of file termination_detection.hpp.


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