GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dc_comm_base.hpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #ifndef DC_COMM_BASE_HPP
25 #define DC_COMM_BASE_HPP
26 #include <sys/socket.h>
27 #include <vector>
28 #include <string>
29 #include <map>
30 #include <graphlab/rpc/dc_types.hpp>
31 #include <graphlab/rpc/dc_internal_types.hpp>
32 #include <graphlab/rpc/dc_receive.hpp>
33 #include <graphlab/rpc/dc_send.hpp>
34 namespace graphlab {
35 namespace dc_impl {
36 
37 
38 /**
39  * \ingroup rpc
40  * \internal
41 The base class of all comms implementations
42 */
43 class dc_comm_base {
44  public:
45 
46  inline dc_comm_base() { };
47 
48  virtual size_t capabilities() const = 0;
49  /**
50  Parses initialization parameters. Most of these parameters are
51  user provided, or provided on a higher level initialization system.
52  It is entirely up to the comm implementation how these parameters to be treated.
53  The descriptions here are largely prescriptive.
54  All machines are called with the same initialization parameters (of course with the
55  exception of curmachineid)
56 
57  The expected behavior is that
58  this fuction should pause until all communication has been set up
59  and returns the number of systems in the network.
60  After which, all other remaining public functions (numprocs(), send(), etc)
61  should operate normally. Every received message should immediate trigger the
62  attached receiver
63 
64  machines: a vector of string over machine IDs. This is typically provided by the user
65  or through some other initialization mechanism
66  initstring: Additional parameters passed by the user
67  curmachineid: The ID of the current machine. Will be size_t(-1) if this is not available.
68  (Some comm protocols will negotiate this itself.)
69 
70  receiver: the receiving object
71  */
72  virtual void init(const std::vector<std::string> &machines,
73  const std::map<std::string,std::string> &initopts,
74  procid_t curmachineid,
75  std::vector<dc_receive*> receiver,
76  std::vector<dc_send*> sender) = 0;
77 
78  /// Must close all connections when this function is called
79  virtual void close() = 0;
80 
81  virtual void trigger_send_timeout(procid_t target, bool urgent) = 0;
82 
83  virtual ~dc_comm_base() {}
84  virtual procid_t numprocs() const = 0;
85 
86  virtual procid_t procid() const = 0;
87 
88  virtual size_t network_bytes_sent() const = 0;
89  virtual size_t network_bytes_received() const = 0;
90  virtual size_t send_queue_length() const = 0;
91 
92 };
93 
94 } // namespace dc_impl
95 } // namespace graphlab
96 #endif
97