-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPartitionParhip.h
98 lines (81 loc) · 2.87 KB
/
PartitionParhip.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// SPDX-FileCopyrightText: 2019-2023 Technical University of Munich
//
// SPDX-License-Identifier: BSD-3-Clause
/**
* @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
*
* @author David Schneller <david.schneller@tum.de>
*/
#ifndef PUML_PARTITIONPARHIP_H
#define PUML_PARTITIONPARHIP_H
#include "PartitionTarget.h"
#ifdef USE_MPI
#include <mpi.h>
#endif // USE_MPI
#ifndef USE_PARHIP
#warning ParHIP is not enabled.
#endif
#include "utils/logger.h"
#include "PartitionBase.h"
#include "PartitionGraph.h"
#include <parhip_interface.h>
#include "Topology.h"
namespace PUML {
template <TopoType Topo>
class PartitionParhip : public PartitionBase<Topo> {
public:
PartitionParhip(int mode) : mode(mode) {}
#ifdef USE_MPI
virtual auto partition(int* partition,
const PartitionGraph<Topo>& graph,
const PartitionTarget& target,
int seed = 1) -> PartitioningResult {
int rank = 0;
MPI_Comm_rank(graph.comm(), &rank);
std::vector<idxtype> vtxdist(graph.vertexDistribution().begin(),
graph.vertexDistribution().end());
std::vector<idxtype> xadj(graph.adjDisp().begin(), graph.adjDisp().end());
std::vector<idxtype> adjncy(graph.adj().begin(), graph.adj().end());
std::vector<idxtype> vwgt(graph.vertexWeights().begin(), graph.vertexWeights().end());
std::vector<idxtype> adjwgt(graph.edgeWeights().begin(), graph.edgeWeights().end());
auto cellCount = graph.localVertexCount();
if (!target.vertexWeightsUniform()) {
logWarning(rank) << "Node weights (target vertex weights) are currently ignored by ParHIP.";
}
if (graph.vertexWeights().size() > graph.localVertexCount()) {
logWarning(rank) << "Multiple vertex weights are currently ignored by ParHIP.";
}
int edgecut = 0;
int nparts = target.vertexCount();
std::vector<idxtype> part(cellCount);
double imbalance = target.imbalance();
MPI_Comm comm = graph.comm();
ParHIPPartitionKWay(vtxdist.data(),
xadj.data(),
adjncy.data(),
vwgt.empty() ? nullptr : vwgt.data(),
adjwgt.empty() ? nullptr : adjwgt.data(),
&nparts,
&imbalance,
true,
seed,
mode,
&edgecut,
part.data(),
&comm);
for (int i = 0; i < cellCount; i++) {
partition[i] = part[i];
}
return PartitioningResult::SUCCESS;
}
#endif // USE_MPI
private:
int mode;
};
} // namespace PUML
#endif // PUML_PARTITIONPARHIP_H