Skip to content

Commit

Permalink
Performance issues and removed one useless parameter (nThread, inheri…
Browse files Browse the repository at this point in the history
…ted by the object).
  • Loading branch information
atalon-lip6 committed Nov 28, 2023
1 parent 1d6d2cc commit 521f38c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
26 changes: 26 additions & 0 deletions core/base/geometry/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,32 @@ namespace ttk {
template <typename T>
T distance(const std::vector<T> &p0, const std::vector<T> &p1);

template <typename T>
inline T distance2D(const T *p0, const T *p1, const int &dimension = 3)
{
T distance = 0;
T di0 = (p0[0]-p1[0]);
T di1 = (p0[1]-p1[1]);
if constexpr(std::is_same<T, float>::value) {

Check failure on line 204 in core/base/geometry/Geometry.h

View workflow job for this annotation

GitHub Actions / test-build-ubuntu (ubuntu-22.04)

‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Werror]

Check failure on line 204 in core/base/geometry/Geometry.h

View workflow job for this annotation

GitHub Actions / test-build-ubuntu (ubuntu-22.04)

‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Werror]

Check failure on line 204 in core/base/geometry/Geometry.h

View workflow job for this annotation

GitHub Actions / test-build-ubuntu (ubuntu-22.04)

‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Werror]

Check failure on line 204 in core/base/geometry/Geometry.h

View workflow job for this annotation

GitHub Actions / test-build-ubuntu (ubuntu-22.04)

‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Werror]

Check failure on line 204 in core/base/geometry/Geometry.h

View workflow job for this annotation

GitHub Actions / test-build-ubuntu (ubuntu-22.04)

‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Werror]

Check failure on line 204 in core/base/geometry/Geometry.h

View workflow job for this annotation

GitHub Actions / test-build-ubuntu (ubuntu-22.04)

‘if constexpr’ only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Werror]
distance = fmaf(di0, di0, distance);
distance = fmaf(di1, di1, distance);
}
else {
distance = fma(di0, di0, distance);
distance = fma(di1, di1, distance);
}

return sqrt(distance);
}

/// Compute the Euclidean distance between two vectors by first flattening
/// them
/// \param p0 xyz coordinates of the first input point.
/// \param p1 xyz coordinates of the second input point.
template <typename T>
T distanceFlatten(const std::vector<std::vector<T>> &p0,
const std::vector<std::vector<T>> &p1);

/// Compute the Euclidean distance between two vectors by first flattening
/// them
/// \param p0 xyz coordinates of the first input point.
Expand Down
28 changes: 12 additions & 16 deletions core/base/topoMap/TopoMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ namespace ttk {
const std::vector<T> &distMatrix,
T *allCoords,
size_t n,
size_t angularSampleNb,
size_t nThread);
size_t angularSampleNb);

template <typename T>
bool computeConvexHull(T *allCoords,
Expand Down Expand Up @@ -439,7 +438,7 @@ namespace ttk {
= {goalCoordChosenSmall[0] - outputCoords[idChosenSmall * 2],
goalCoordChosenSmall[1] - outputCoords[idChosenSmall * 2 + 1]};

T distBaryPointSmall = ttk::Geometry::distance(
T distBaryPointSmall = ttk::Geometry::distance2D(
&outputCoords[idChosenSmall * 2], coordscenterSmall, 2);
T preFinalPosBarySmall[2] = {coordscenterSmall[0] + smallCompMoveVect[0],
coordscenterSmall[1] + smallCompMoveVect[1]};
Expand Down Expand Up @@ -469,14 +468,13 @@ namespace ttk {
if(nBig > 1) {
finalDistortion = rotateMergingCompsBest(
idsInHullSmall, idsInHullBig, compSmall, compBig, idChosenSmall,
idChosenBig, distMatrix, outputCoords, n, this->AngularSampleNb,
this->threadNumber_);
idChosenBig, distMatrix, outputCoords, n, this->AngularSampleNb);
if(finalDistortion < -1) {
return 1;
}
}

T finalDist = ttk::Geometry::distance(
T finalDist = ttk::Geometry::distance2D(
&outputCoords[2 * idChosenSmall], &outputCoords[2 * idChosenBig], 2);
if(fabs(finalDist - edgeCost) > Epsilon) {
this->printErr(
Expand Down Expand Up @@ -533,15 +531,15 @@ namespace ttk {
for(size_t u1 = 0; u1 < n; u1++) {
for(size_t u2 = u1 + 1; u2 < n; u2++) {
edgeHeapAfter.push(
std::make_pair(ttk::Geometry::distance(
std::make_pair(ttk::Geometry::distance2D(
&outputCoords[2 * u1], &outputCoords[2 * u2], 2),
std::make_pair(u1, u2)));
}
}
} else if(this->Strategy == STRATEGY::PRIM) {
for(size_t u1 = 0; u1 < n; u1++) {
edgeHeapAfter.push(std::make_pair(
ttk::Geometry::distance(&outputCoords[0], &outputCoords[2 * u1], 2),
ttk::Geometry::distance2D(&outputCoords[0], &outputCoords[2 * u1], 2),
std::make_pair(0, u1)));
}
}
Expand Down Expand Up @@ -594,7 +592,7 @@ namespace ttk {
stillToDo.erase(v);
for(size_t uToDo : stillToDo) {
edgeHeapAfter.push(std::make_pair(
ttk::Geometry::distance(
ttk::Geometry::distance2D(
&outputCoords[2 * v], &outputCoords[2 * uToDo], 2),
std::make_pair(v, uToDo)));
}
Expand Down Expand Up @@ -680,12 +678,10 @@ namespace ttk {
const std::vector<T> &distMatrix,
T *allCoords,
size_t n,
size_t angularSampleNb,
size_t nThread) { // TODO remove nThread
TTK_FORCE_USE(nThread);
size_t angularSampleNb) {
// The distance between the two components.
T shortestDistPossible
= ttk::Geometry::distance(&allCoords[2 * iPt1], &allCoords[2 * iPt2], 2);
= ttk::Geometry::distance2D(&allCoords[2 * iPt1], &allCoords[2 * iPt2], 2);
T coordPt1[2] = {allCoords[2 * iPt1], allCoords[2 * iPt1 + 1]};
T coordPt2[2] = {allCoords[2 * iPt2], allCoords[2 * iPt2 + 1]};
size_t comp1Size = comp1.size(), comp2Size = comp2.size();
Expand Down Expand Up @@ -750,7 +746,7 @@ namespace ttk {
bool errorDuringLoop = false;
bool foundValidAngle = false;
#ifdef TTK_ENABLE_OPENMP
#pragma omp parallel for num_threads(nThread) shared(allCoords)
#pragma omp parallel for num_threads(this->threadNumber_) shared(allCoords)
#endif
// We enumerate the rotation angles for the first component.
for(size_t i1 = 0; i1 < nbIter1; i1++) {
Expand All @@ -774,7 +770,7 @@ namespace ttk {
T coordARotate[2] = {coords1Test[2 * i], coords1Test[2 * i + 1]};
for(size_t j = 0; j < comp2Size; j++) {
T coordBRotate[2] = {coords2Test[2 * j], coords2Test[2 * j + 1]};
T newDist = ttk::Geometry::distance(coordARotate, coordBRotate, 2);
T newDist = ttk::Geometry::distance2D(coordARotate, coordBRotate, 2);
curScore += (newDist - origDistMatrix[i][j])
* (newDist - origDistMatrix[i][j]);
if(newDist + Epsilon < shortestDistPossible) {
Expand Down Expand Up @@ -852,7 +848,7 @@ namespace ttk {
idsInHull.push_back(compPtsIds[0]);
if(nbPoint == 2) {
double dist
= ttk::Geometry::distance(&compCoords[0], &compCoords[2], 2);
= ttk::Geometry::distance2D(&compCoords[0], &compCoords[2], 2);

if(dist > Epsilon) {
idsInHull.push_back(compPtsIds[1]);
Expand Down

0 comments on commit 521f38c

Please sign in to comment.