Skip to content

Commit 5a1c6b2

Browse files
committed
include outer index
1 parent ab62777 commit 5a1c6b2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Common/include/toolboxes/graph_toolbox.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,16 @@ T createNaturalColoring(Index_t numInnerIndexes) {
479479
* pattern is returned.
480480
* \param[in] pattern - Sparse pattern to be colored.
481481
* \param[in] groupSize - Size of the outer index groups, default 1.
482+
* \param[in] includeOuterIdx - If the outer indices are the same type of entity as
483+
* the inner indices this must be true. For example, when both are point
484+
* indices, i.e. the pattern is the adjacency matrix.
482485
* \param[in] balanceColors - Try to balance number of indexes per color,
483486
* tends to result in worse locality (thus false by default).
484487
* \param[out] indexColor - Optional, vector with colors given to the outer indices.
485488
* \return Coloring in the same type of the input pattern.
486489
*/
487490
template <typename Color_t = unsigned char, size_t MaxColors = 255, size_t MaxMB = 128, class T>
488-
T colorSparsePattern(const T& pattern, size_t groupSize = 1, bool balanceColors = false,
491+
T colorSparsePattern(const T& pattern, size_t groupSize = 1, bool includeOuterIdx = false, bool balanceColors = false,
489492
std::vector<Color_t>* indexColor = nullptr) {
490493
static_assert(std::is_integral<Color_t>::value, "");
491494
static_assert(std::numeric_limits<Color_t>::max() >= MaxColors, "");
@@ -538,6 +541,11 @@ T colorSparsePattern(const T& pattern, size_t groupSize = 1, bool balanceColors
538541

539542
for (; it != searchOrder.end(); ++it) {
540543
bool free = true;
544+
if (includeOuterIdx) {
545+
for (Index_t k = iOuter; k < grpEnd && free; ++k) {
546+
free = !innerInColor[*it][k];
547+
}
548+
}
541549
/*--- Traverse entire group as a large outer index. ---*/
542550
for (Index_t k = outerPtr[iOuter]; k < outerPtr[grpEnd] && free; ++k) {
543551
free = !innerInColor[*it][innerIdx[k] - minIdx];

Common/src/geometry/CGeometry.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring(su2double* efficien
37723772
bool admissibleColoring = false; /* keep track wether the last tested coloring is admissible */
37733773

37743774
while (true) {
3775-
edgeColoring = colorSparsePattern(pattern, nextEdgeColorGroupSize, balanceColors);
3775+
edgeColoring = colorSparsePattern(pattern, nextEdgeColorGroupSize, false, balanceColors);
37763776

37773777
/*--- If the coloring fails, reduce the color group size. ---*/
37783778
if (edgeColoring.empty()) {
@@ -3809,12 +3809,12 @@ const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring(su2double* efficien
38093809

38103810
/*--- If the last tested coloring was not admissible, recompute the final coloring. ---*/
38113811
if (!admissibleColoring) {
3812-
edgeColoring = colorSparsePattern(pattern, edgeColorGroupSize, balanceColors);
3812+
edgeColoring = colorSparsePattern(pattern, edgeColorGroupSize, false, balanceColors);
38133813
}
38143814
}
38153815
/*--- No adaptivity. ---*/
38163816
else {
3817-
edgeColoring = colorSparsePattern(pattern, edgeColorGroupSize, balanceColors);
3817+
edgeColoring = colorSparsePattern(pattern, edgeColorGroupSize, false, balanceColors);
38183818
}
38193819

38203820
/*--- If the coloring fails use the natural coloring. This is a
@@ -3867,7 +3867,7 @@ const CCompressedSparsePatternUL& CGeometry::GetElementColoring(su2double* effic
38673867

38683868
/*--- Color the elements. ---*/
38693869
constexpr bool balanceColors = true;
3870-
elemColoring = colorSparsePattern(pattern, elemColorGroupSize, balanceColors);
3870+
elemColoring = colorSparsePattern(pattern, elemColorGroupSize, false, balanceColors);
38713871

38723872
/*--- Same as for the edge coloring. ---*/
38733873
if (elemColoring.empty()) SetNaturalElementColoring();
@@ -3896,7 +3896,7 @@ void CGeometry::ColorMGLevels(unsigned short nMGLevels, const CGeometry* const*
38963896
/*--- Color the coarse points. ---*/
38973897
vector<tColor> color;
38983898
const auto& adjacency = geometry[iMesh]->nodes->GetPoints();
3899-
if (colorSparsePattern<tColor, nColor>(adjacency, 1, false, &color).empty()) continue;
3899+
if (colorSparsePattern<tColor, nColor>(adjacency, 1, true, false, &color).empty()) continue;
39003900

39013901
/*--- Propagate colors to fine mesh. ---*/
39023902
for (auto step = 0u; step < iMesh; ++step) {
@@ -4042,8 +4042,8 @@ const CGeometry::CLineletInfo& CGeometry::GetLineletInfo(const CConfig* config)
40424042
}
40434043
}
40444044

4045-
const auto coloring =
4046-
colorSparsePattern<uint8_t, std::numeric_limits<uint8_t>::max()>(CCompressedSparsePatternUL(adjacency), 1, true);
4045+
const auto coloring = colorSparsePattern<uint8_t, std::numeric_limits<uint8_t>::max()>(
4046+
CCompressedSparsePatternUL(adjacency), 1, false, true);
40474047
const auto nColors = coloring.getOuterSize();
40484048

40494049
/*--- Sort linelets by color. ---*/

0 commit comments

Comments
 (0)