Graybat  1.1
Graph Approach for Highly Generic Communication Schemes Based on Adaptive Topologies
Vertex.hpp
1 #pragma once
2 
3 #include <numeric> // std::accumulate
4 #include <iostream> // std::cout
5 
6 namespace graybat {
7 
8  template <class T_Cage>
10 
11  typedef unsigned VertexID;
12  typedef T_Cage Cage;
13  typedef typename Cage::GraphPolicy GraphPolicy;
14  typedef typename Cage::Edge Edge;
15  typedef typename Cage::Event Event;
16  typedef typename GraphPolicy::VertexProperty VertexProperty;
17 
18  VertexID id;
19  VertexProperty &vertexProperty;
20  Cage &cage;
21 
22  CommunicationVertex(const VertexID id, VertexProperty &vertexProperty, Cage &cage) :
23  id(id),
24  vertexProperty(vertexProperty),
25  cage(cage){
26 
27  }
28 
29  /***************************************************************************
30  * Graph Operations
31  ****************************************************************************/
32  VertexProperty& operator()(){
33  return vertexProperty;
34  }
35 
36  CommunicationVertex& operator=(const CommunicationVertex &other){
37  id = other.id;
38  vertexProperty = other.vertexProperty;
39 
40  return *this;
41  }
42 
43 
44  size_t nInEdges() const {
45  return cage.getInEdges(*this).size();
46  }
47 
48  size_t nOutEdges() const {
49  return cage.getOutEdges(*this).size();
50  }
51 
52  bool operator==(CommunicationVertex v){
53  return (id == v.id);
54  }
55 
56  bool operator!=(CommunicationVertex v){
57  return (id != v.id);
58  }
59 
60  /***************************************************************************
61  * Communication Operations
62  ****************************************************************************/
63 
64  template <class T_Data>
65  void spread(const T_Data& data, std::vector<Event> &events){
66  cage.spread(*this, data, events);
67  }
68 
69  template <class T_Data>
70  void spread(const T_Data& data){
71  cage.spread(*this, data);
72  }
73 
74 
75  template <class T_Data>
76  void collect(T_Data& data){
77  cage.collect(*this, data);
78 
79  }
80 
81  template <class T_Data, class T_Functor>
82  void forward(T_Data& data, T_Functor f){
83  cage.collect(*this, data);
84  f(data);
85  cage.spread(*this, data);
86 
87  }
88 
89  template <class T_Data>
90  void forward(T_Data& data){
91  assert(nInEdges() == nOutEdges());
92  cage.collect(*this, data);
93  cage.spread(*this, data);
94 
95  }
96 
109  template <typename T_Op>
110  typename T_Op::result_type accumulate(const T_Op op, const typename T_Op::result_type init){
111  std::vector<typename T_Op::result_type> data (nInEdges());
112  cage.collect(*this, data);
113  return std::accumulate(data.begin(), data.end(), init, op);
114 
115  }
116 
117  };
118 
119 } /* namespace graybat */
Definition: Vertex.hpp:9
Definition: Edge.hpp:8
T_Op::result_type accumulate(const T_Op op, const typename T_Op::result_type init)
Collects from each incoming edge one elements and reduces them by the binary operator op...
Definition: Vertex.hpp:110
Definition: BiStar.hpp:8