Graybat  1.1
Graph Approach for Highly Generic Communication Schemes Based on Adaptive Topologies
Filter.hpp
1 #pragma once
2 
3 #include <algorithm> /* std::sort*/
4 #include <vector> /* std::vector */
5 
6 namespace graybat {
7 
8  namespace mapping {
9 
10  struct Filter {
11 
12  const size_t vertexTag;
13 
14  Filter(size_t vertexTag):
15  vertexTag(vertexTag){
16 
17  }
18 
19  template<typename T_Cage>
20  std::vector<typename T_Cage::Vertex> operator()(const unsigned processID, const unsigned processCount, T_Cage &cage){
21 
22  using CommunicationPolicy = typename T_Cage::CommunicationPolicy;
23  using Vertex = typename T_Cage::Vertex;
24  using Context = typename CommunicationPolicy::Context;
25  using VAddr = typename CommunicationPolicy::VAddr;
26 
27  std::vector<VAddr> peersWithSameTag;
28 
29  CommunicationPolicy& comm = cage.comm;
30  Context context = comm.getGlobalContext();
31 
32 
33  // Get the information about who wants to
34  // host vertices with the same tag
35  std::array<size_t, 1> sendData{vertexTag};
36  for(VAddr vAddr = 0; vAddr < context.size(); vAddr++){
37  comm.asyncSend(vAddr, 0, context, sendData);
38  }
39 
40  for(VAddr vAddr = 0; vAddr < context.size(); vAddr++){
41  std::array<size_t, 1> recvData{0};
42  comm.recv(vAddr, 0, context, recvData);
43  if(recvData[0] == vertexTag){
44  peersWithSameTag.push_back(vAddr);
45  }
46  }
47 
48  // Distribute vertices to peers with same tag
49  std::sort(peersWithSameTag.begin(), peersWithSameTag.end());
50 
51  const size_t nPeers = peersWithSameTag.size();
52  size_t peer_i = 0;
53 
54  std::vector<Vertex> vertices = cage.getVertices();
55  std::vector<Vertex> myVertices;
56 
57  for(size_t i = 0; i < vertices.size(); ++i){
58  if(vertices[i]().tag == vertexTag){
59  if(peersWithSameTag.at(peer_i) == context.getVAddr()){
60  myVertices.push_back(vertices[i]);
61 
62  }
63  peer_i = (peer_i + 1 % nPeers);
64 
65  }
66 
67  }
68 
69  return myVertices;
70 
71  }
72 
73  };
74 
75  } /* mapping */
76 
77 } /* graybat */
Definition: Filter.hpp:10
Definition: BiStar.hpp:8