Skip to content

Commit ae3a481

Browse files
authored
Option to use level scheduling for OMP parallelization of ILU (#2793)
* use levels for FE connectivity * config option and template etc. * fix * try to fix ARM 64 warning * Apply suggestion from @pcarruscag * regressions
1 parent f3d5be3 commit ae3a481

8 files changed

Lines changed: 223 additions & 127 deletions

File tree

Common/include/CConfig.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ class CConfig {
645645
unsigned long Linear_Solver_Restart_Deflation; /*!< \brief Number of vectors used for deflated restarts. */
646646
unsigned long Linear_Solver_Prec_Threads; /*!< \brief Number of threads per rank for ILU and LU_SGS preconditioners. */
647647
unsigned short Linear_Solver_ILU_n; /*!< \brief ILU fill=in level. */
648+
bool Linear_Solver_ILU_levels; /*!< \brief Use level scheduling for OMP parallelization of ILU. */
648649
su2double SemiSpan; /*!< \brief Wing Semi span. */
649650
su2double MSW_Alpha; /*!< \brief Coefficient for blending states in the MSW scheme. */
650651
su2double Roe_Kappa; /*!< \brief Relaxation of the Roe scheme. */
@@ -4377,6 +4378,11 @@ class CConfig {
43774378
*/
43784379
unsigned short GetLinear_Solver_ILU_n(void) const { return Linear_Solver_ILU_n; }
43794380

4381+
/*!
4382+
* \brief Get whether to use level scheduling for OMP parallelization of ILU.
4383+
*/
4384+
bool GetLinear_Solver_ILU_levels(void) const { return Linear_Solver_ILU_levels; }
4385+
43804386
/*!
43814387
* \brief Get restart frequency of the linear solver for the implicit formulation.
43824388
* \return Restart frequency of the linear solver for the implicit formulation.

Common/include/linear_algebra/CSysMatrix.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828

2929
#pragma once
3030

31-
#include "../../include/CConfig.hpp"
31+
#include "../CConfig.hpp"
3232
#include "CSysVector.hpp"
3333
#include "CPastixWrapper.hpp"
34+
#include "../toolboxes/graph_toolbox.hpp"
3435

3536
#include <cstdlib>
3637
#include <vector>
@@ -120,10 +121,9 @@ class CSysMatrix {
120121
const int rank; /*!< \brief MPI Rank. */
121122
const int size; /*!< \brief MPI Size. */
122123

123-
enum : size_t {
124-
MAXNVAR = 20
125-
}; /*!< \brief Maximum number of variables the matrix can handle. The static
126-
size is needed for fast, per-thread, static memory allocation. */
124+
/*!< \brief Maximum number of variables the matrix can handle. The static
125+
* size is needed for fast, per-thread, static memory allocation. */
126+
enum : size_t { MAXNVAR = 20 };
127127

128128
enum { OMP_MAX_SIZE_L = 8192 }; /*!< \brief Max. chunk size used in light parallel for loops. */
129129
enum { OMP_MAX_SIZE_H = 512 }; /*!< \brief Max. chunk size used in heavy parallel for loops. */
@@ -158,7 +158,10 @@ class CSysMatrix {
158158
const unsigned long* col_ind_ilu; /*!< \brief Column index for each of the elements in val() (ILU). */
159159
unsigned short ilu_fill_in; /*!< \brief Fill in level for the ILU preconditioner. */
160160

161-
ScalarType* invM; /*!< \brief Inverse of (Jacobi) preconditioner, or diagonal of ILU. */
161+
/*!< \brief Level structure for alternative shared memory parallelization of ILU. */
162+
CCompressedSparsePatternUL levels_ilu;
163+
164+
ScalarType* invM; /*!< \brief Inverse of (Jacobi) preconditioner. */
162165

163166
/*--- Temporary (hence mutable) working memory used in the Linelet preconditioner, outer vector is for threads ---*/
164167
mutable vector<vector<const ScalarType*> >

Common/include/toolboxes/graph_toolbox.hpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ T colorSparsePattern(const T& pattern, size_t groupSize = 1, bool includeOuterId
516516

517517
{
518518
/*--- For each color keep track of the inner indices that are in it. ---*/
519-
std::vector<std::vector<bool> > innerInColor;
519+
std::vector<std::vector<bool>> innerInColor;
520520
innerInColor.emplace_back(nInner, false);
521521

522522
/*--- Order in which we look for space in the colors to insert a new group. ---*/
@@ -672,4 +672,31 @@ su2double coloringEfficiency(const SparsePattern& coloring, int numThreads, int
672672
return ideal / real;
673673
}
674674

675+
/*!
676+
* \brief Compute the levels for the lower part of a sparse pattern.
677+
* For example, corresponding to the dependencies of forward substitution.
678+
*/
679+
template <class T>
680+
T computeLevels(const T& pattern) {
681+
using Index = typename T::IndexType;
682+
683+
std::vector<std::vector<Index>> levels;
684+
{
685+
const auto n = pattern.getOuterSize();
686+
su2vector<int> level(n);
687+
for (Index i = 0; i < n; ++i) {
688+
level(i) = 0;
689+
for (const auto j : pattern.getInnerIter(i)) {
690+
if (j >= i) continue;
691+
level(i) = std::max(level(i), level(j) + 1);
692+
}
693+
if (static_cast<std::size_t>(level(i) + 1) > levels.size()) {
694+
levels.emplace_back();
695+
}
696+
levels[level(i)].push_back(i);
697+
}
698+
}
699+
return T(levels);
700+
}
701+
675702
/// @}

Common/src/CConfig.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ CConfig::CConfig(char case_filename[MAX_STRING_SIZE], CConfig *config) {
244244
/*--- Update original config file ---*/
245245

246246
if (runtime_file) {
247-
if (all_options.find("TIME_ITER") == all_options.end())
247+
if (OptionIsSet("TIME_ITER"))
248248
config->SetnTime_Iter(nTimeIter);
249249
}
250250
}
@@ -1896,6 +1896,8 @@ void CConfig::SetConfig_Options() {
18961896
addUnsignedLongOption("LINEAR_SOLVER_ITER", Linear_Solver_Iter, 10);
18971897
/* DESCRIPTION: Fill in level for the ILU preconditioner */
18981898
addUnsignedShortOption("LINEAR_SOLVER_ILU_FILL_IN", Linear_Solver_ILU_n, 0);
1899+
/* DESCRIPTION: Use level scheduling for OMP parallelization of the ILU preconditioner */
1900+
addBoolOption("LINEAR_SOLVER_ILU_LEVEL_SCHEDULING", Linear_Solver_ILU_levels, false);
18991901
/* DESCRIPTION: Maximum number of iterations of the linear solver for the implicit formulation */
19001902
addUnsignedLongOption("LINEAR_SOLVER_RESTART_FREQUENCY", Linear_Solver_Restart_Frequency, 10);
19011903
/* DESCRIPTION: Number of vectors used for deflated restarts */
@@ -4047,7 +4049,13 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
40474049

40484050
/*--- Set the number of external iterations to 1 for the steady state problem ---*/
40494051

4050-
if (Kind_Solver == MAIN_SOLVER::FEM_ELASTICITY) nMGLevels = 0;
4052+
if (Kind_Solver == MAIN_SOLVER::FEM_ELASTICITY) {
4053+
nMGLevels = 0;
4054+
if (!OptionIsSet("LINEAR_SOLVER_ILU_LEVEL_SCHEDULING")) {
4055+
/*--- Different default behavior for this solver type. ---*/
4056+
Linear_Solver_ILU_levels = true;
4057+
}
4058+
}
40514059

40524060
Radiation = (Kind_Radiation != RADIATION_MODEL::NONE);
40534061

@@ -5746,11 +5754,11 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
57465754
/*--- Check that spark ignition has required parameters defined ---*/
57475755
if (flamelet_ParsedOptions.ignition_method == FLAMELET_INIT_TYPE::SPARK) {
57485756
/*--- Check if SPARK_INIT was explicitly set in config file ---*/
5749-
if (all_options.find("SPARK_INIT") != all_options.end()) {
5757+
if (!OptionIsSet("SPARK_INIT")) {
57505758
SU2_MPI::Error("FLAME_INIT_METHOD= SPARK requires SPARK_INIT to be defined in the config file.", CURRENT_FUNCTION);
57515759
}
57525760
/*--- Check if SPARK_REACTION_RATES was explicitly set in config file ---*/
5753-
if (all_options.find("SPARK_REACTION_RATES") != all_options.end()) {
5761+
if (!OptionIsSet("SPARK_REACTION_RATES")) {
57545762
SU2_MPI::Error("FLAME_INIT_METHOD= SPARK requires SPARK_REACTION_RATES to be defined in the config file.", CURRENT_FUNCTION);
57555763
}
57565764
if (flamelet_ParsedOptions.nspark < flamelet_ParsedOptions.n_scalars) {

Common/src/geometry/CGeometry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4524,7 +4524,7 @@ su2double NearestNeighborDistance(CGeometry* geometry, const CConfig* config, co
45244524
* Compute an alternative distance based on volume and wall area. ---*/
45254525

45264526
const auto nDim = geometry->GetnDim();
4527-
su2double Normal[3] = {};
4527+
su2double Normal[3] = {0, 0, 0};
45284528
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) {
45294529
if (!config->GetViscous_Wall(iMarker)) continue;
45304530

0 commit comments

Comments
 (0)