GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
distributed_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_OBLIVIOUS_INGRESS_HPP
24 #define GRAPHLAB_DISTRIBUTED_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/macros_def.hpp>
37 namespace graphlab {
38  template<typename VertexData, typename EdgeData>
39  class distributed_graph;
40 
41  /**
42  * \brief Ingress object assigning edges using randoming hash function.
43  */
44  template<typename VertexData, typename EdgeData>
46  public distributed_ingress_base<VertexData, EdgeData> {
47  public:
49  /// The type of the vertex data stored in the graph
50  typedef VertexData vertex_data_type;
51  /// The type of the edge data stored in the graph
52  typedef EdgeData edge_data_type;
53 
54  typedef typename graph_type::vertex_record vertex_record;
55  typedef typename graph_type::mirror_type mirror_type;
56 
57  typedef distributed_ingress_base<VertexData, EdgeData> base_type;
58  // typedef typename boost::unordered_map<vertex_id_type, std::vector<size_t> > degree_hash_table_type;
60 
61  /** Type of the degree hash table:
62  * a map from vertex id to a bitset of length num_procs. */
65 
66  /** Array of number of edges on each proc. */
67  std::vector<size_t> proc_num_edges;
68 
69  /** Ingress tratis. */
70  bool usehash;
71  bool userecent;
72 
73  public:
74  distributed_oblivious_ingress(distributed_control& dc, graph_type& graph, bool usehash = false, bool userecent = false) :
75  base_type(dc, graph),
76  dht(-1),proc_num_edges(dc.numprocs()), usehash(usehash), userecent(userecent) {
77 
78  INITIALIZE_TRACER(ob_ingress_compute_assignments, "Time spent in compute assignment");
79  }
80 
82 
83  /** Add an edge to the ingress object using oblivious greedy assignment. */
84  void add_edge(vertex_id_type source, vertex_id_type target,
85  const EdgeData& edata) {
86  dht[source]; dht[target];
87  const procid_t owning_proc =
88  base_type::edge_decision.edge_to_proc_greedy(source, target, dht[source], dht[target], proc_num_edges, usehash, userecent);
90  edge_buffer_record record(source, target, edata);
91  base_type::edge_exchange.send(owning_proc, record);
92  } // end of add edge
93 
94  virtual void finalize() {
95  dht.clear();
97 
98  }
99 
100  }; // end of distributed_ob_ingress
101 
102 }; // end of namespace graphlab
103 #include <graphlab/macros_undef.hpp>
104 
105 
106 #endif