Skip to content

Commit 64f031b

Browse files
committed
demo: Populate cluster neighbors before filling adjacency
Instead of gathering adjacency info from the map, we can scatter it into per-cluster neighbor list, which avoids expensive map iteration for every cluster. This could be optimized further to avoid vectors-of-vectors, but that can be left to the actual meshopt cluster partitioner; this change just improves METIS baseline from performance perspective to make comparisons more relevant.
1 parent a23ea0f commit 64f031b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

demo/nanite.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,24 +419,26 @@ static std::vector<std::vector<int> > partitionMetis(const std::vector<Cluster>&
419419
adjacency[std::make_pair(std::min(list[i], list[j]), std::max(list[i], list[j]))]++;
420420
}
421421

422+
std::vector<std::vector<std::pair<int, int> > > neighbors(pending.size());
423+
424+
for (std::map<std::pair<int, int>, int>::iterator it = adjacency.begin(); it != adjacency.end(); ++it)
425+
{
426+
neighbors[it->first.first].push_back(std::make_pair(it->first.second, it->second));
427+
neighbors[it->first.second].push_back(std::make_pair(it->first.first, it->second));
428+
}
429+
422430
std::vector<int> xadj(pending.size() + 1);
423431
std::vector<int> adjncy;
424432
std::vector<int> adjwgt;
425433
std::vector<int> part(pending.size());
426434

427435
for (size_t i = 0; i < pending.size(); ++i)
428436
{
429-
for (std::map<std::pair<int, int>, int>::iterator it = adjacency.begin(); it != adjacency.end(); ++it)
430-
if (it->first.first == int(i))
431-
{
432-
adjncy.push_back(it->first.second);
433-
adjwgt.push_back(it->second);
434-
}
435-
else if (it->first.second == int(i))
436-
{
437-
adjncy.push_back(it->first.first);
438-
adjwgt.push_back(it->second);
439-
}
437+
for (size_t j = 0; j < neighbors[i].size(); ++j)
438+
{
439+
adjncy.push_back(neighbors[i][j].first);
440+
adjwgt.push_back(neighbors[i][j].second);
441+
}
440442

441443
xadj[i + 1] = int(adjncy.size());
442444
}

0 commit comments

Comments
 (0)