Skip to content

Commit e3beb48

Browse files
committed
mpi global cfl
1 parent 2468017 commit e3beb48

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,8 @@ class CSolver {
14791479

14801480
void PerformCFLReductions(CGeometry *geometry, CConfig *config, unsigned short iMesh);
14811481

1482+
void SynchronizeCFLFlags(bool &reduceCFL, bool &resetCFL, bool &canIncrease);
1483+
14821484
void ApplyCFLToCoarseGrid(CGeometry *geometry, CSolver **solver_container,
14831485
CConfig *config, unsigned short iMesh,
14841486
bool reduceCFL, bool resetCFL, bool canIncrease,

SU2_CFD/src/solvers/CSolver.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,34 @@ void CSolver::PerformCFLReductions(CGeometry *geometry, CConfig *config, unsigne
18501850
config->SetCFL(iMesh, Avg_CFL_Local);
18511851
}
18521852

1853+
void CSolver::SynchronizeCFLFlags(bool &reduceCFL, bool &resetCFL, bool &canIncrease) {
1854+
#ifdef HAVE_MPI
1855+
/* Synchronize CFL decision flags across all MPI ranks to ensure consistent global strategy.
1856+
This prevents different ranks from making conflicting CFL decisions which would cause:
1857+
- Inconsistent CFL values for corresponding points across domain decomposition
1858+
- Potential divergence when some ranks reduce CFL while others increase
1859+
- Multigrid issues when coarse levels don't respond to fine grid instabilities
1860+
1861+
Logic:
1862+
- reduceCFL: Use logical OR - if ANY rank needs to reduce, ALL should reduce (safety)
1863+
- resetCFL: Use logical OR - if ANY rank detects catastrophic divergence, ALL should reset
1864+
- canIncrease: Use logical AND - only increase if ALL ranks are stable (conservative) */
1865+
1866+
int reduceCFL_int = reduceCFL ? 1 : 0;
1867+
int resetCFL_int = resetCFL ? 1 : 0;
1868+
int canIncrease_int = canIncrease ? 1 : 0;
1869+
1870+
SU2_MPI::Allreduce(MPI_IN_PLACE, &reduceCFL_int, 1, MPI_INT, MPI_LOR, SU2_MPI::GetComm());
1871+
SU2_MPI::Allreduce(MPI_IN_PLACE, &resetCFL_int, 1, MPI_INT, MPI_LOR, SU2_MPI::GetComm());
1872+
SU2_MPI::Allreduce(MPI_IN_PLACE, &canIncrease_int, 1, MPI_INT, MPI_LAND, SU2_MPI::GetComm());
1873+
1874+
reduceCFL = (reduceCFL_int != 0);
1875+
resetCFL = (resetCFL_int != 0);
1876+
canIncrease = (canIncrease_int != 0);
1877+
#endif
1878+
/* No synchronization needed for serial builds - flags remain as computed locally */
1879+
}
1880+
18531881
void CSolver::ApplyCFLToCoarseGrid(CGeometry *geometry, CSolver **solver_container,
18541882
CConfig *config, unsigned short iMesh,
18551883
bool reduceCFL, bool resetCFL, bool canIncrease,
@@ -2487,28 +2515,8 @@ void CSolver::AdaptCFLNumber(CGeometry **geometry,
24872515
}
24882516
}
24892517

2490-
/* Synchronize CFL decision flags across all MPI ranks to ensure consistent global strategy.
2491-
This prevents different ranks from making conflicting CFL decisions which would cause:
2492-
- Inconsistent CFL values for corresponding points across domain decomposition
2493-
- Potential divergence when some ranks reduce CFL while others increase
2494-
- Multigrid issues when coarse levels don't respond to fine grid instabilities
2495-
2496-
Logic:
2497-
- reduceCFL: Use logical OR - if ANY rank needs to reduce, ALL should reduce (safety)
2498-
- resetCFL: Use logical OR - if ANY rank detects catastrophic divergence, ALL should reset
2499-
- canIncrease: Use logical AND - only increase if ALL ranks are stable (conservative) */
2500-
2501-
int reduceCFL_int = reduceCFL ? 1 : 0;
2502-
int resetCFL_int = resetCFL ? 1 : 0;
2503-
int canIncrease_int = canIncrease ? 1 : 0;
2504-
2505-
SU2_MPI::Allreduce(MPI_IN_PLACE, &reduceCFL_int, 1, MPI_INT, MPI_LOR, SU2_MPI::GetComm());
2506-
SU2_MPI::Allreduce(MPI_IN_PLACE, &resetCFL_int, 1, MPI_INT, MPI_LOR, SU2_MPI::GetComm());
2507-
SU2_MPI::Allreduce(MPI_IN_PLACE, &canIncrease_int, 1, MPI_INT, MPI_LAND, SU2_MPI::GetComm());
2508-
2509-
reduceCFL = (reduceCFL_int != 0);
2510-
resetCFL = (resetCFL_int != 0);
2511-
canIncrease = (canIncrease_int != 0);
2518+
/* Synchronize CFL decision flags across all MPI ranks */
2519+
SynchronizeCFLFlags(reduceCFL, resetCFL, canIncrease);
25122520

25132521
if (rank == MASTER_NODE && iter % 50 == 0) {
25142522
cout << "MPI-Synchronized CFL Flags - Iter " << iter

0 commit comments

Comments
 (0)