Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MPI_EndPoint.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/wum2/MPI_EndPoint.hh
11 /// @brief Handles communication between different roles in mpi
12 // Every role in mpi needs one of these for each different role it communicates with
13 // for example, slave only communicates with master so slave needs one
14 // master communicates with slave and pool, so master needs two
15 
16 // role_available_mem is a functor to the role's available memory function
17 //
18 // this allows a role with multiple endpoints have its endpoints be aware of
19 // other endpoint memory usage and act accordingly
20 /// @author Ken Jung
21 
22 #ifndef INCLUDED_protocols_wum2_MPI_EndPoint_hh
23 #define INCLUDED_protocols_wum2_MPI_EndPoint_hh
24 
25 #ifdef USEBOOSTMPI
26 #include <boost/mpi.hpp>
27 #include <boost/function.hpp>
28 #include <boost/tuple/tuple.hpp>
29 
33 
34 #include <set>
35 
36 namespace protocols {
37 namespace wum2 {
38 
39 using namespace boost;
40 enum {
41  CLEARCOMMAND = 100,
42  STATUSREQUEST,
43  STATUSRESPONSE,
44  WORKUNITVEC,
45 };
46 
47 class MPI_EndPoint : public EndPoint {
48 
49 public:
50  MPI_EndPoint( mpi::communicator world, function< uint64_t () > role_available_mem );
51  ~MPI_EndPoint(){}
52 
53  int mpi_rank() { return world_.rank(); }
54 
55  // real memory usage
56  virtual uint64_t current_mem() {
57  return inq_.current_mem() +
58  inbuf_.current_mem() +
59  outq_.current_mem() +
60  outbuf_.current_mem();
61  }
62 
63  // checks and responds to a status request, then calls functor
64  // int refers to rank of node requesting the StatusResponse
65  virtual void check_and_act_status_request( function< void ( StatusResponse & , int ) > functor );
66 
67  // default functor for check_and_act_status_request
68  // opens irecv from asking node in anticipation of wu isend from asking node
69  // -> master sending new wu to slave
70  // opens isend to asking node in anticipation of wu irecv from asking node
71  // -> slave sending completed wu back to master
72  virtual void listen_wu_sendrecv( StatusResponse & r, int requesting_node );
73 
74  // isend to that node requesting a StatusResponse
75  // fills up inbound_statusresponse_, acts_on_status_response required to clear it
76  virtual void send_status_request( int rank );
77 
78  // for each inbound StatusResponse, calls functor on it and then deletes it if functor return true
79  virtual void act_on_status_response( function<bool ( StatusResponse & r )> functor );
80 
81  // default functor for acts_on_status_response
82  // opens irecv from asking node in anticipation of wu isend from asking node
83  // -> master sending new wu to slave
84  // opens isend to asking node in anticipation of wu irecv from asking node
85  // -> slave sending completed wu back to master
86  virtual bool initiate_wu_sendrecv( StatusResponse & r );
87 
88  // deletes reqs and corresponding buffers that have been completed succesfully
89  // also moves stuff from inbuf to inq
90  virtual void cleanup_reqs();
91 
92  // setup an irecv from rank with WUs from rank's outbound totaling up to mem_size
93  void receive_wus( int rank, uint64_t mem_size );
94 
95  // setup an isend to rank with WUs from outbound totaling up to mem_size
96  void send_wus( int rank, uint64_t mem_size );
97 
98  // checks and act to a clear queue command
99  virtual void check_and_act_clearcommand();
100 
101  virtual bool has_open_status( int rank ) {
102  return open_status_.count( rank );
103  }
104 
105 private:
106 
107  mpi::communicator world_;
108 
109  WUQueueBuffer inbuf_;
110  WUQueueBuffer outbuf_;
111 
112  // these hold the buffers for statusresponse sending and receiving
113  std::list< tuple< mpi::request, StatusResponse > > outbound_statusresponse_;
114  std::list< tuple< mpi::request, StatusResponse > > inbound_statusresponse_;
115 
116  // these hold the buffers for statusrequest sending and receiving
117  std::list< tuple< mpi::request, StatusRequest > > outbound_statusrequest_;
118 
119  std::set<int> open_status_; // holds ranks of nodes who have not responded to a statusrequest
120 
121  // keep a irecv open for status response and clearcommand always
122  tuple< mpi::request, int > clearcommand_channel_;
123  tuple< mpi::request, StatusRequest > statusrequest_channel_;
124 
125 };
126 
127 
128 } // wum2
129 } // protocols
130 
131 #endif
132 #endif