GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
distributed_constrained_oblivious_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_CONSTRAINED_OBLIVIOUS_INGRESS_HPP
24 #define GRAPHLAB_DISTRIBUTED_CONSTRAINED_OBLIVIOUS_INGRESS_HPP
25 
26 
27 #include <graphlab/graph/graph_basic_types.hpp>
28 #include <graphlab/graph/ingress/idistributed_ingress.hpp>
29 #include <graphlab/graph/ingress/distributed_ingress_base.hpp>
30 #include <graphlab/graph/ingress/ingress_edge_decision.hpp>
31 #include <graphlab/graph/distributed_graph.hpp>
32 #include <graphlab/rpc/buffered_exchange.hpp>
33 #include <graphlab/rpc/distributed_event_log.hpp>
34 #include <graphlab/util/dense_bitset.hpp>
35 #include <graphlab/util/cuckoo_map_pow2.hpp>
36 #include <graphlab/graph/ingress/sharding_constraint.hpp>
37 #include <graphlab/macros_def.hpp>
38 namespace graphlab {
39  template<typename VertexData, typename EdgeData>
40  class distributed_graph;
41 
42  /**
43  * \brief Ingress object assigning edges using randoming hash function.
44  */
45  template<typename VertexData, typename EdgeData>
47  public distributed_ingress_base<VertexData, EdgeData> {
48  public:
50  /// The type of the vertex data stored in the graph
51  typedef VertexData vertex_data_type;
52  /// The type of the edge data stored in the graph
53  typedef EdgeData edge_data_type;
54 
55  typedef typename graph_type::vertex_record vertex_record;
56  typedef typename graph_type::mirror_type mirror_type;
57 
58  typedef distributed_ingress_base<VertexData, EdgeData> base_type;
59  // typedef typename boost::unordered_map<vertex_id_type, std::vector<size_t> > degree_hash_table_type;
61 
62  /** Type of the degree hash table:
63  * a map from vertex id to a bitset of length num_procs. */
66 
67  /** Array of number of edges on each proc. */
68  std::vector<size_t> proc_num_edges;
69 
70  /** Ingress tratis. */
71  bool usehash;
72  bool userecent;
73 
74  sharding_constraint* constraint;
75  boost::hash<vertex_id_type> hashvid;
76 
77  public:
78  distributed_constrained_oblivious_ingress(distributed_control& dc, graph_type& graph, bool usehash = false, bool userecent = false) :
79  base_type(dc, graph),
80  dht(-1),proc_num_edges(dc.numprocs()), usehash(usehash), userecent(userecent) {
81  constraint = new sharding_constraint(dc.numprocs(), "grid");
82  }
83 
85  delete constraint;
86  }
87 
88  /** Add an edge to the ingress object using oblivious greedy assignment. */
89  void add_edge(vertex_id_type source, vertex_id_type target,
90  const EdgeData& edata) {
91  dht[source]; dht[target];
92  std::vector<procid_t> candidates;
93  constraint->get_joint_neighbors(get_master(source), get_master(target), candidates);
94  const procid_t owning_proc =
95  base_type::edge_decision.edge_to_proc_greedy(source, target, dht[source], dht[target], candidates, proc_num_edges, usehash, userecent);
97  edge_buffer_record record(source, target, edata);
98  base_type::edge_exchange.send(owning_proc, record);
99  } // end of add edge
100 
101  virtual void finalize() {
102  dht.clear();
104  }
105 
106  private:
107  procid_t get_master (vertex_id_type vid) {
108  return hashvid(vid) % base_type::rpc.numprocs();
109  }
110 
111 
112  }; // end of distributed_ob_ingress
113 
114 }; // end of namespace graphlab
115 #include <graphlab/macros_undef.hpp>
116 
117 
118 #endif