GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dc_internal_types.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_INTERNAL_TYPES_HPP
25 #define DC_INTERNAL_TYPES_HPP
26 #include <boost/function.hpp>
27 #include <boost/unordered_map.hpp>
28 #include <graphlab/rpc/dc_types.hpp>
29 #include <graphlab/util/resizing_array_sink.hpp>
30 #include <graphlab/parallel/pthread_tools.hpp>
31 #include <graphlab/serialization/serialization_includes.hpp>
32 namespace graphlab {
33 class distributed_control;
34 
35 namespace dc_impl {
36 
37 /**
38  * \internal
39  * \ingroup rpc
40  * The type of the callback function used by the communications
41 classes when data is received*/
42 typedef void (*comm_recv_callback_type)(void* tag, procid_t src,
43  const char* buf, size_t len);
44 
45 /**
46  * \internal
47  * \ingroup rpc
48  * The type of the local function call dispatcher.
49  * \see dispatch_type2
50  */
51 typedef void (*dispatch_type)(distributed_control& dc, procid_t, unsigned char, const char* data, size_t len);
52 
53 /**
54  *\internal
55  * \ingroup rpc
56  * A second type of the local function call dispatcher.
57  * Currently only used by POD calls. TODO: to move all other call
58  * systems to use dispatch2.
59  * \see dispatch_type
60  */
61 typedef void (*dispatch_type2)(distributed_control& dc, procid_t, unsigned char, const char* data, size_t len);
62 
63 
64 typedef boost::unordered_map<std::string, dispatch_type> dispatch_map_type;
65 
66 // commm capabilities
67 const size_t COMM_STREAM = 1;
68 const size_t COMM_DATAGRAM = 0;
69 
70 /**
71  * \internal
72  * \ingroup rpc
73  * The header form of each packet */
74 struct packet_hdr {
75  uint32_t len; /// length of the packet
76  procid_t src; /// source machine
77  unsigned char packet_type_mask; /// the types are in dc_packet_mask.hpp
78  unsigned char sequentialization_key;
79 };
80 
81 typedef uint32_t block_header_type;
82 
83 /**
84  * \internal
85  * \ingroup rpc
86  * special handling for the only pointer datatype
87 we natively support serialization for. Basically,
88 we must delete it. if charstring_free is called on a
89 char*, it will be deleted. Otherwise it will not do anything*/
90 template <typename T>
91 inline void charstring_free(T& t) { }
92 
93 /**
94  * \internal
95  * \ingroup rpc
96  */
97 template <>
98 inline void charstring_free<char*>(char* &c){
99  delete [] c;
100 };
101 
102 // if 1, uses semaphore
103 // if 0 uses spin wait
104 #define REQUEST_WAIT_METHOD 1
105 
106 
107 /**
108  * \internal
109  * \ingroup rpc
110  *
111  * The data needed to receive the matched send / recvs */
112 struct recv_from_struct {
113  inline recv_from_struct():tag(0), hasdata(false) { }
114 
115  std::string data;
116  size_t tag;
117  mutex lock;
118  conditional cond;
119  bool hasdata;
120 
121 };
122 
123 /**
124  * \internal
125  * \ingroup rpc
126  * Used for termination detection
127  */
128 struct terminator_token {
129  terminator_token():calls_sent(0),calls_recv(0),terminate(false) { }
130  terminator_token(size_t sent, size_t recv):calls_sent(sent),
131  calls_recv(recv),terminate(false) { }
132  size_t calls_sent;
133  size_t calls_recv;
134  bool terminate;
135 };
136 
137 
138 }
139 }
140 
141 SERIALIZABLE_POD(graphlab::dc_impl::terminator_token);
142 #endif
143