CXXGraph  0.2.0
CXXGraph is a header only, that manages the Graphs and it's algorithm in C++
Partitioner.hpp
1 /***********************************************************/
2 /*** ______ ____ ______ _ ***/
3 /*** / ___\ \/ /\ \/ / ___|_ __ __ _ _ __ | |__ ***/
4 /*** | | \ / \ / | _| '__/ _` | '_ \| '_ \ ***/
5 /*** | |___ / \ / \ |_| | | | (_| | |_) | | | | ***/
6 /*** \____/_/\_\/_/\_\____|_| \__,_| .__/|_| |_| ***/
7 /*** |_| ***/
8 /***********************************************************/
9 /*** Header-Only C++ Library for Graph ***/
10 /*** Representation and Algorithms ***/
11 /***********************************************************/
12 /*** Author: ZigRazor ***/
13 /*** E-Mail: zigrazor@gmail.com ***/
14 /***********************************************************/
15 /*** Collaboration: ----------- ***/
16 /***********************************************************/
17 /*** License: AGPL v3.0 ***/
18 /***********************************************************/
19 
20 #ifndef __CXXGRAPH_PARTITIONING_PARTITIONER_H__
21 #define __CXXGRAPH_PARTITIONING_PARTITIONER_H__
22 
23 #pragma once
24 #include <vector>
25 #include "PartitionStrategy.hpp"
26 #include "Partitioning/Utility/Globals.hpp"
27 #include "Edge/Edge.hpp"
28 #include "CoordinatedPartitionState.hpp"
29 #include "Utility/Runnable.hpp"
30 #include "PartitionerThread.hpp"
31 #include "PartitionAlgorithm.hpp"
32 #include "HDRF.hpp"
33 
34 namespace CXXGRAPH
35 {
36  namespace PARTITIONING
37  {
38  template <typename T>
40  {
41  private:
42  std::list<const Edge<T> *> dataset;
43  PartitionStrategy<T>* algorithm;
44  Globals GLOBALS;
45 
46  CoordinatedPartitionState<T> startCoordinated();
47 
48 
49  public:
50  Partitioner(const std::list<const Edge<T> *> &dataset, Globals &G);
51  ~Partitioner();
52 
53  CoordinatedPartitionState<T> performCoordinatedPartition();
54  };
55  template <typename T>
56  Partitioner<T>::Partitioner(const std::list<const Edge<T> *> &dataset, Globals &G) : GLOBALS(G)
57  {
58  //this->GLOBALS = G;
59  this->dataset = dataset;
60  if (GLOBALS.partitionStategy == PartitionAlgorithm::HDRF_ALG)
61  {
62  algorithm = new HDRF<T>(GLOBALS);
63  }
64  }
65  template <typename T>
66  CoordinatedPartitionState<T> Partitioner<T>::startCoordinated()
67  {
68  CoordinatedPartitionState<T> state(GLOBALS);
69  int processors = GLOBALS.threads;
70 
71  std::thread myThreads[processors];
72 
73  int n = dataset.size();
74  int subSize = n / processors + 1;
75  for (int t = 0; t < processors; t++)
76  {
77  int iStart = t * subSize;
78  int iEnd = std::min((t + 1) * subSize, n);
79  if (iEnd >= iStart)
80  {
81  std::vector<const Edge<T>*> list(std::next(dataset.begin(), iStart), std::next(dataset.begin(), iEnd));
82  Runnable *x = new PartitionerThread<T>(list, &state, algorithm, new std::list<int>());
83  myThreads[t] = std::thread(&Runnable::run, x);
84  }
85  }
86  for (int t = 0; t < processors; t++)
87  {
88  myThreads[t].join();
89  }
90  return state;
91  }
92  template <typename T>
93  Partitioner<T>::~Partitioner()
94  {
95  }
96  template <typename T>
97  CoordinatedPartitionState<T> Partitioner<T>::performCoordinatedPartition()
98  {
99  return startCoordinated();
100  }
101 
102  }
103 }
104 
105 #endif // __CXXGRAPH_PARTITIONING_PARTITIONER_H__
Definition: Edge.hpp:39
Definition: CoordinatedPartitionState.hpp:40
Definition: Globals.hpp:32
Definition: HDRF.hpp:35
Definition: PartitionStrategy.hpp:34
Definition: Partitioner.hpp:40