GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
distributed_random_ingress.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 #ifndef GRAPHLAB_DISTRIBUTED_RANDOM_INGRESS_HPP
24 #define GRAPHLAB_DISTRIBUTED_RANDOM_INGRESS_HPP
25 
26 #include <boost/functional/hash.hpp>
27 
28 #include <graphlab/rpc/buffered_exchange.hpp>
29 #include <graphlab/graph/graph_basic_types.hpp>
30 #include <graphlab/graph/ingress/idistributed_ingress.hpp>
31 #include <graphlab/graph/ingress/distributed_ingress_base.hpp>
32 #include <graphlab/graph/distributed_graph.hpp>
33 
34 
35 #include <graphlab/macros_def.hpp>
36 namespace graphlab {
37  template<typename VertexData, typename EdgeData>
38  class distributed_graph;
39 
40  /**
41  * \brief Ingress object assigning edges using randoming hash function.
42  */
43  template<typename VertexData, typename EdgeData>
45  public distributed_ingress_base<VertexData, EdgeData> {
46  public:
48  /// The type of the vertex data stored in the graph
49  typedef VertexData vertex_data_type;
50  /// The type of the edge data stored in the graph
51  typedef EdgeData edge_data_type;
52 
53 
54  typedef distributed_ingress_base<VertexData, EdgeData> base_type;
55 
56  public:
58  base_type(dc, graph) {
59  } // end of constructor
60 
62 
63  /** Add an edge to the ingress object using random assignment. */
64  void add_edge(vertex_id_type source, vertex_id_type target,
65  const EdgeData& edata) {
67  const procid_t owning_proc = base_type::edge_decision.edge_to_proc_random(source, target, base_type::rpc.numprocs());
68  const edge_buffer_record record(source, target, edata);
69  base_type::edge_exchange.send(owning_proc, record);
70  } // end of add edge
71  }; // end of distributed_random_ingress
72 }; // end of namespace graphlab
73 #include <graphlab/macros_undef.hpp>
74 
75 
76 #endif