@@ -3609,7 +3609,7 @@ const su2vector<unsigned long>& CGeometry::GetTransposeSparsePatternMap(Connecti
36093609 return pattern.transposePtr ();
36103610}
36113611
3612- const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring (su2double* efficiency) {
3612+ const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring (su2double* efficiency, bool maximizeEdgeColorGroupSize ) {
36133613 /* --- Check for dry run mode with dummy geometry. ---*/
36143614 if (nEdge == 0 ) return edgeColoring;
36153615
@@ -3637,7 +3637,60 @@ const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring(su2double* efficien
36373637
36383638 /* --- Color the edges. ---*/
36393639 constexpr bool balanceColors = true ;
3640- edgeColoring = colorSparsePattern (pattern, edgeColorGroupSize, balanceColors);
3640+
3641+ /* --- If requested, find an efficient coloring with maximum color group size (up to edgeColorGroupSize). ---*/
3642+ if (maximizeEdgeColorGroupSize) {
3643+ auto upperEdgeColorGroupSize = edgeColorGroupSize + 1 ; /* upper bound that is deemed too large */
3644+ auto nextEdgeColorGroupSize = edgeColorGroupSize; /* next value that we are going to try */
3645+ auto lowerEdgeColorGroupSize = 1ul ; /* lower bound that is known to work */
3646+
3647+ bool admissibleColoring = false ; /* keep track wether the last tested coloring is admissible */
3648+
3649+ while (true ) {
3650+ edgeColoring = colorSparsePattern (pattern, nextEdgeColorGroupSize, balanceColors);
3651+
3652+ /* --- If the coloring fails, reduce the color group size. ---*/
3653+ if (edgeColoring.empty ()) {
3654+ upperEdgeColorGroupSize = nextEdgeColorGroupSize;
3655+ admissibleColoring = false ;
3656+ }
3657+ /* --- If the coloring succeeds, check the efficiency. ---*/
3658+ else {
3659+ const su2double currentEfficiency =
3660+ coloringEfficiency (edgeColoring, omp_get_max_threads (), nextEdgeColorGroupSize);
3661+
3662+ /* --- If the coloring is not efficient, reduce the color group size. ---*/
3663+ if (currentEfficiency < COLORING_EFF_THRESH) {
3664+ upperEdgeColorGroupSize = nextEdgeColorGroupSize;
3665+ admissibleColoring = false ;
3666+ }
3667+ /* --- Otherwise, enlarge the color group size. ---*/
3668+ else {
3669+ lowerEdgeColorGroupSize = nextEdgeColorGroupSize;
3670+ admissibleColoring = true ;
3671+ }
3672+ }
3673+
3674+ const auto increment = (upperEdgeColorGroupSize - lowerEdgeColorGroupSize) / 2 ;
3675+ nextEdgeColorGroupSize = lowerEdgeColorGroupSize + increment;
3676+
3677+ /* --- Terminating condition. ---*/
3678+ if (increment == 0 ) {
3679+ break ;
3680+ }
3681+ }
3682+
3683+ edgeColorGroupSize = nextEdgeColorGroupSize;
3684+
3685+ /* --- If the last tested coloring was not admissible, recompute the final coloring. ---*/
3686+ if (!admissibleColoring) {
3687+ edgeColoring = colorSparsePattern (pattern, edgeColorGroupSize, balanceColors);
3688+ }
3689+ }
3690+ /* --- No adaptivity. ---*/
3691+ else {
3692+ edgeColoring = colorSparsePattern (pattern, edgeColorGroupSize, balanceColors);
3693+ }
36413694
36423695 /* --- If the coloring fails use the natural coloring. This is a
36433696 * "soft" failure as this "bad" coloring should be detected
0 commit comments