19 const std::vector<std::vector<size_t>> &nodeNeighs,
20 std::vector<size_t> &nodePartition,
23 auto t1 = steady_clock::now();
24 idx_t nvtxs = nodeNeighs.size();
29 std::vector<idx_t> part(nvtxs, 0);
30 std::vector<idx_t> vwgt(nvtxs * nWeights, 0);
31 auto nParts = idx_t(nPartitions);
34 std::vector<idx_t> xadj(nvtxs, 0);
35 std::vector<idx_t> adjncy;
36 for (
size_t i=0; i<nvtxs; i++) {
37 adjncy.insert(adjncy.end(), nodeNeighs[i].begin(), nodeNeighs[i].end());
38 xadj[i+1] = xadj[i] + idx_t(nodeNeighs[i].size());
40 std::cout << fmt::format(
"adjcny size = {}, xadj[end] = {}\n",
41 adjncy.size(), xadj[nvtxs]);
43 std::cout <<
"\nmetisGraphPartition():\n";
44 if (partitionMethod ==
"metis_recursive") {
45 std::cout <<
" METIS_PartGraphRecursive partitions a graph into K parts\n";
46 std::cout <<
" using multilevel recursive bisection.\n";
48 metis_return = METIS_PartGraphRecursive(&nvtxs, &ncon, xadj.data(),
49 adjncy.data(), NULL, NULL,
50 NULL, &nParts, NULL, NULL, NULL, &objval,
52 }
else if (partitionMethod ==
"metis_kway") {
53 std::cout <<
" METIS_PartGraphKway partitions a graph into K parts\n";
54 std::cout <<
" using multilevel K-way partition.\n";
56 metis_return = METIS_PartGraphKway(&nvtxs, &ncon, xadj.data(),
57 adjncy.data(), NULL, NULL,
58 NULL, &nParts, NULL, NULL, NULL, &objval,
61 std::cerr <<
"Argument partitionMethod = "
62 << partitionMethod <<
" is invalid.\n"
63 <<
"Valid values are {'metis_recursive', 'metis_kway'}.\n";
68 auto t2 = steady_clock::now();
70 std::cout << fmt::format(
"\n Return code = {}\n"
71 " Edge cuts for partition = {}\n"
72 " Partition calculation time (ms) = {}\n",
73 metis_return, (
int) objval,
77 nodePartition.resize(0);
78 nodePartition.insert(nodePartition.end(), part.begin(), part.end());
void metisGraphPartition(std::string partitionMethod, const std::vector< std::vector< size_t > > &nodeNeighs, std::vector< size_t > &nodePartition, size_t nPartitions)
Partitions the nodes based on node neighborlist supplied. Function first creates a graph with nodes a...
float timeDiff(std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, std::string unit="microseconds")
Returns difference between two times.