/
PartitionBase.h
67 lines (56 loc) · 1.65 KB
/
PartitionBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @file
* This file is part of PUML
*
* For conditions of distribution and use, please see the copyright
* notice in the file 'COPYING' at the root directory of this package
* and the copyright notice at https://github.com/TUM-I5/PUMGen
*
* @copyright 2019-2023 Technische Universitaet Muenchen
* @author Sebastian Rettenberger <sebastian.rettenberger@tum.de>
* @author David Schneller <david.schneller@tum.de>
*/
#ifndef PUML_PARTITION_BASE_H
#define PUML_PARTITION_BASE_H
#ifdef USE_MPI
#include <mpi.h>
#endif // USE_MPI
#include "utils/logger.h"
#include "Topology.h"
#include "PUML.h"
#include "PartitionGraph.h"
#include "PartitionTarget.h"
#include <vector>
#include <stdexcept>
namespace PUML
{
enum class PartitioningResult {
SUCCESS = 0,
ERROR
};
template<TopoType Topo>
class PartitionBase
{
public:
PartitionBase() { }
virtual ~PartitionBase() = default;
#ifdef USE_MPI
std::vector<int> partition(const PartitionGraph<Topo>& graph, const PartitionTarget& target, int seed = 1)
{
std::vector<int> part(graph.localVertexCount());
auto result = partition(part, graph, target, seed);
if (result != PartitioningResult::SUCCESS) {
logError() << "Partitioning failed.";
}
return part;
}
PartitioningResult partition(std::vector<int>& part, const PartitionGraph<Topo>& graph, const PartitionTarget& target, int seed = 1)
{
return partition(part.data(), graph, target, seed);
}
virtual PartitioningResult partition(int* part, const PartitionGraph<Topo>& graph, const PartitionTarget& target, int seed = 1) = 0;
#endif // USE_MPI
};
using TETPartitionBase = PartitionBase<TETRAHEDRON>;
}
#endif // PUML_PARTITION_BASE_H