Skip to content

Commit

Permalink
change MPI_QUANTITIES to enum class (#2279)
Browse files Browse the repository at this point in the history
* change to enum class
  • Loading branch information
bigfooted committed May 14, 2024
1 parent ca12a5c commit 83cac12
Show file tree
Hide file tree
Showing 39 changed files with 282 additions and 282 deletions.
6 changes: 3 additions & 3 deletions Common/include/geometry/CGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class CGeometry {
* \param[out] COUNT_PER_POINT - Number of communicated variables per point.
* \param[out] MPI_TYPE - Enumerated type for the datatype of the quantity to be communicated.
*/
void GetCommCountAndType(const CConfig* config, unsigned short commType, unsigned short& COUNT_PER_POINT,
void GetCommCountAndType(const CConfig* config, MPI_QUANTITIES commType, unsigned short& COUNT_PER_POINT,
unsigned short& MPI_TYPE) const;

/*!
Expand All @@ -436,14 +436,14 @@ class CGeometry {
* \param[in] config - Definition of the particular problem.
* \param[in] commType - Enumerated type for the quantity to be communicated.
*/
void InitiateComms(CGeometry* geometry, const CConfig* config, unsigned short commType) const;
void InitiateComms(CGeometry* geometry, const CConfig* config, MPI_QUANTITIES commType) const;

/*!
* \brief Routine to complete the set of non-blocking communications launched by InitiateComms() and unpacking of the
* data into the geometry class. \param[in] geometry - Geometrical definition of the problem. \param[in] config -
* Definition of the particular problem. \param[in] commType - Enumerated type for the quantity to be unpacked.
*/
void CompleteComms(CGeometry* geometry, const CConfig* config, unsigned short commType);
void CompleteComms(CGeometry* geometry, const CConfig* config, MPI_QUANTITIES commType);

/*!
* \brief Get number of coordinates.
Expand Down
4 changes: 2 additions & 2 deletions Common/include/linear_algebra/CSysMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct CSysMatrixComms {
*/
template <class T>
static void Initiate(const CSysVector<T>& x, CGeometry* geometry, const CConfig* config,
unsigned short commType = SOLUTION_MATRIX);
MPI_QUANTITIES commType = MPI_QUANTITIES::SOLUTION_MATRIX);

/*!
* \brief Routine to complete the set of non-blocking communications launched by
Expand All @@ -104,7 +104,7 @@ struct CSysMatrixComms {
*/
template <class T>
static void Complete(CSysVector<T>& x, CGeometry* geometry, const CConfig* config,
unsigned short commType = SOLUTION_MATRIX);
MPI_QUANTITIES commType = MPI_QUANTITIES::SOLUTION_MATRIX);
};

/*!
Expand Down
2 changes: 1 addition & 1 deletion Common/include/option_structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,7 @@ enum PERIODIC_QUANTITIES {
/*!
* \brief Vertex-based quantities exchanged in MPI point-to-point communications.
*/
enum MPI_QUANTITIES {
enum class MPI_QUANTITIES {
SOLUTION , /*!< \brief Conservative solution communication. */
SOLUTION_OLD , /*!< \brief Conservative solution old communication. */
SOLUTION_GRADIENT , /*!< \brief Conservative solution gradient communication. */
Expand Down
40 changes: 20 additions & 20 deletions Common/src/geometry/CGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,29 +543,29 @@ void CGeometry::PostP2PSends(CGeometry* geometry, const CConfig* config, unsigne
END_SU2_OMP_MASTER
}

void CGeometry::GetCommCountAndType(const CConfig* config, unsigned short commType, unsigned short& COUNT_PER_POINT,
void CGeometry::GetCommCountAndType(const CConfig* config, MPI_QUANTITIES commType, unsigned short& COUNT_PER_POINT,
unsigned short& MPI_TYPE) const {
switch (commType) {
case COORDINATES:
case MPI_QUANTITIES::COORDINATES:
COUNT_PER_POINT = nDim;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case GRID_VELOCITY:
case MPI_QUANTITIES::GRID_VELOCITY:
COUNT_PER_POINT = nDim;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case COORDINATES_OLD:
case MPI_QUANTITIES::COORDINATES_OLD:
if (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND)
COUNT_PER_POINT = nDim * 2;
else
COUNT_PER_POINT = nDim;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case MAX_LENGTH:
case MPI_QUANTITIES::MAX_LENGTH:
COUNT_PER_POINT = 1;
MPI_TYPE = COMM_TYPE_DOUBLE;
break;
case NEIGHBORS:
case MPI_QUANTITIES::NEIGHBORS:
COUNT_PER_POINT = 1;
MPI_TYPE = COMM_TYPE_UNSIGNED_SHORT;
break;
Expand All @@ -575,7 +575,7 @@ void CGeometry::GetCommCountAndType(const CConfig* config, unsigned short commTy
}
}

void CGeometry::InitiateComms(CGeometry* geometry, const CConfig* config, unsigned short commType) const {
void CGeometry::InitiateComms(CGeometry* geometry, const CConfig* config, MPI_QUANTITIES commType) const {
if (nP2PSend == 0) return;

/*--- Local variables ---*/
Expand Down Expand Up @@ -633,15 +633,15 @@ void CGeometry::InitiateComms(CGeometry* geometry, const CConfig* config, unsign
buf_offset = (msg_offset + iSend) * COUNT_PER_POINT;

switch (commType) {
case COORDINATES:
case MPI_QUANTITIES::COORDINATES:
vector = nodes->GetCoord(iPoint);
for (iDim = 0; iDim < nDim; iDim++) bufDSend[buf_offset + iDim] = vector[iDim];
break;
case GRID_VELOCITY:
case MPI_QUANTITIES::GRID_VELOCITY:
vector = nodes->GetGridVel(iPoint);
for (iDim = 0; iDim < nDim; iDim++) bufDSend[buf_offset + iDim] = vector[iDim];
break;
case COORDINATES_OLD:
case MPI_QUANTITIES::COORDINATES_OLD:
vector = nodes->GetCoord_n(iPoint);
for (iDim = 0; iDim < nDim; iDim++) {
bufDSend[buf_offset + iDim] = vector[iDim];
Expand All @@ -653,10 +653,10 @@ void CGeometry::InitiateComms(CGeometry* geometry, const CConfig* config, unsign
}
}
break;
case MAX_LENGTH:
case MPI_QUANTITIES::MAX_LENGTH:
bufDSend[buf_offset] = nodes->GetMaxLength(iPoint);
break;
case NEIGHBORS:
case MPI_QUANTITIES::NEIGHBORS:
bufSSend[buf_offset] = geometry->nodes->GetnNeighbor(iPoint);
break;
default:
Expand All @@ -672,7 +672,7 @@ void CGeometry::InitiateComms(CGeometry* geometry, const CConfig* config, unsign
}
}

void CGeometry::CompleteComms(CGeometry* geometry, const CConfig* config, unsigned short commType) {
void CGeometry::CompleteComms(CGeometry* geometry, const CConfig* config, MPI_QUANTITIES commType) {
if (nP2PRecv == 0) return;

/*--- Local variables ---*/
Expand Down Expand Up @@ -734,21 +734,21 @@ void CGeometry::CompleteComms(CGeometry* geometry, const CConfig* config, unsign
/*--- Store the data correctly depending on the quantity. ---*/

switch (commType) {
case COORDINATES:
case MPI_QUANTITIES::COORDINATES:
for (iDim = 0; iDim < nDim; iDim++) nodes->SetCoord(iPoint, iDim, bufDRecv[buf_offset + iDim]);
break;
case GRID_VELOCITY:
case MPI_QUANTITIES::GRID_VELOCITY:
for (iDim = 0; iDim < nDim; iDim++) nodes->SetGridVel(iPoint, iDim, bufDRecv[buf_offset + iDim]);
break;
case COORDINATES_OLD:
case MPI_QUANTITIES::COORDINATES_OLD:
nodes->SetCoord_n(iPoint, &bufDRecv[buf_offset]);
if (config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND)
nodes->SetCoord_n1(iPoint, &bufDRecv[buf_offset + nDim]);
break;
case MAX_LENGTH:
case MPI_QUANTITIES::MAX_LENGTH:
nodes->SetMaxLength(iPoint, bufDRecv[buf_offset]);
break;
case NEIGHBORS:
case MPI_QUANTITIES::NEIGHBORS:
nodes->SetnNeighbor(iPoint, bufSRecv[buf_offset]);
break;
default:
Expand Down Expand Up @@ -2327,8 +2327,8 @@ void CGeometry::RegisterCoordinates() const {
}

void CGeometry::UpdateGeometry(CGeometry** geometry_container, CConfig* config) {
geometry_container[MESH_0]->InitiateComms(geometry_container[MESH_0], config, COORDINATES);
geometry_container[MESH_0]->CompleteComms(geometry_container[MESH_0], config, COORDINATES);
geometry_container[MESH_0]->InitiateComms(geometry_container[MESH_0], config, MPI_QUANTITIES::COORDINATES);
geometry_container[MESH_0]->CompleteComms(geometry_container[MESH_0], config, MPI_QUANTITIES::COORDINATES);

geometry_container[MESH_0]->SetControlVolume(config, UPDATE);
geometry_container[MESH_0]->SetBoundControlVolume(config, UPDATE);
Expand Down
4 changes: 2 additions & 2 deletions Common/src/geometry/CPhysicalGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6364,8 +6364,8 @@ void CPhysicalGeometry::SetMaxLength(CConfig* config) {
}
END_SU2_OMP_FOR

InitiateComms(this, config, MAX_LENGTH);
CompleteComms(this, config, MAX_LENGTH);
InitiateComms(this, config, MPI_QUANTITIES::MAX_LENGTH);
CompleteComms(this, config, MPI_QUANTITIES::MAX_LENGTH);
}

void CPhysicalGeometry::MatchActuator_Disk(const CConfig* config) {
Expand Down
4 changes: 2 additions & 2 deletions Common/src/grid_movement/CVolumetricMovement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void CVolumetricMovement::UpdateGridCoord(CGeometry* geometry, CConfig* config)
* Hence we still need a communication of the transformed coordinates, otherwise periodicity
* is not maintained. ---*/

geometry->InitiateComms(geometry, config, COORDINATES);
geometry->CompleteComms(geometry, config, COORDINATES);
geometry->InitiateComms(geometry, config, MPI_QUANTITIES::COORDINATES);
geometry->CompleteComms(geometry, config, MPI_QUANTITIES::COORDINATES);
}

void CVolumetricMovement::UpdateDualGrid(CGeometry* geometry, CConfig* config) {
Expand Down
22 changes: 11 additions & 11 deletions Common/src/linear_algebra/CSysMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void CSysMatrix<ScalarType>::Initialize(unsigned long npoint, unsigned long npoi

template <class T>
void CSysMatrixComms::Initiate(const CSysVector<T>& x, CGeometry* geometry, const CConfig* config,
unsigned short commType) {
MPI_QUANTITIES commType) {
if (geometry->nP2PSend == 0) return;

/*--- Local variables ---*/
Expand All @@ -236,13 +236,13 @@ void CSysMatrixComms::Initiate(const CSysVector<T>& x, CGeometry* geometry, cons

/*--- Create a boolean for reversing the order of comms. ---*/

const bool reverse = (commType == SOLUTION_MATRIXTRANS);
const bool reverse = (commType == MPI_QUANTITIES::SOLUTION_MATRIXTRANS);

/*--- Set the size of the data packet and type depending on quantity. ---*/

switch (commType) {
case SOLUTION_MATRIX:
case SOLUTION_MATRIXTRANS:
case MPI_QUANTITIES::SOLUTION_MATRIX:
case MPI_QUANTITIES::SOLUTION_MATRIXTRANS:
break;
default:
SU2_MPI::Error("Unrecognized quantity for point-to-point MPI comms.", CURRENT_FUNCTION);
Expand All @@ -265,7 +265,7 @@ void CSysMatrixComms::Initiate(const CSysVector<T>& x, CGeometry* geometry, cons

for (auto iMessage = 0; iMessage < geometry->nP2PSend; iMessage++) {
switch (commType) {
case SOLUTION_MATRIX: {
case MPI_QUANTITIES::SOLUTION_MATRIX: {
su2double* bufDSend = geometry->bufD_P2PSend;

/*--- Get the offset for the start of this message. ---*/
Expand Down Expand Up @@ -294,7 +294,7 @@ void CSysMatrixComms::Initiate(const CSysVector<T>& x, CGeometry* geometry, cons
break;
}

case SOLUTION_MATRIXTRANS: {
case MPI_QUANTITIES::SOLUTION_MATRIXTRANS: {
/*--- We are going to communicate in reverse, so we use the
recv buffer for the send instead. Also, all of the offsets
and counts are derived from the recv data structures. ---*/
Expand Down Expand Up @@ -341,7 +341,7 @@ void CSysMatrixComms::Initiate(const CSysVector<T>& x, CGeometry* geometry, cons
}

template <class T>
void CSysMatrixComms::Complete(CSysVector<T>& x, CGeometry* geometry, const CConfig* config, unsigned short commType) {
void CSysMatrixComms::Complete(CSysVector<T>& x, CGeometry* geometry, const CConfig* config, MPI_QUANTITIES commType) {
if (geometry->nP2PRecv == 0) return;

/*--- Local variables ---*/
Expand All @@ -366,7 +366,7 @@ void CSysMatrixComms::Complete(CSysVector<T>& x, CGeometry* geometry, const CCon
const auto source = status.MPI_SOURCE;

switch (commType) {
case SOLUTION_MATRIX: {
case MPI_QUANTITIES::SOLUTION_MATRIX: {
const su2double* bufDRecv = geometry->bufD_P2PRecv;

/*--- We know the offsets based on the source rank. ---*/
Expand Down Expand Up @@ -400,7 +400,7 @@ void CSysMatrixComms::Complete(CSysVector<T>& x, CGeometry* geometry, const CCon
break;
}

case SOLUTION_MATRIXTRANS: {
case MPI_QUANTITIES::SOLUTION_MATRIXTRANS: {
/*--- We are going to communicate in reverse, so we use the
send buffer for the recv instead. Also, all of the offsets
and counts are derived from the send data structures. ---*/
Expand Down Expand Up @@ -1197,8 +1197,8 @@ void CSysMatrix<ScalarType>::ComputePastixPreconditioner(const CSysVector<Scalar
/*--- Explicit instantiations ---*/

#define INSTANTIATE_COMMS(TYPE) \
template void CSysMatrixComms::Initiate<TYPE>(const CSysVector<TYPE>&, CGeometry*, const CConfig*, unsigned short); \
template void CSysMatrixComms::Complete<TYPE>(CSysVector<TYPE>&, CGeometry*, const CConfig*, unsigned short);
template void CSysMatrixComms::Initiate<TYPE>(const CSysVector<TYPE>&, CGeometry*, const CConfig*, MPI_QUANTITIES); \
template void CSysMatrixComms::Complete<TYPE>(CSysVector<TYPE>&, CGeometry*, const CConfig*, MPI_QUANTITIES);

#define INSTANTIATE_MATRIX(TYPE) \
template class CSysMatrix<TYPE>; \
Expand Down
16 changes: 8 additions & 8 deletions SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ class CFVMFlowSolverBase : public CSolver {

/*--- MPI parallelization ---*/

InitiateComms(geometry, config, MAX_EIGENVALUE);
CompleteComms(geometry, config, MAX_EIGENVALUE);
InitiateComms(geometry, config, MPI_QUANTITIES::MAX_EIGENVALUE);
CompleteComms(geometry, config, MPI_QUANTITIES::MAX_EIGENVALUE);
}

/*!
Expand Down Expand Up @@ -780,8 +780,8 @@ class CFVMFlowSolverBase : public CSolver {

/*--- MPI parallelization ---*/

InitiateComms(geometry, config, SENSOR);
CompleteComms(geometry, config, SENSOR);
InitiateComms(geometry, config, MPI_QUANTITIES::SENSOR);
CompleteComms(geometry, config, MPI_QUANTITIES::SENSOR);

}

Expand Down Expand Up @@ -871,8 +871,8 @@ class CFVMFlowSolverBase : public CSolver {

/*--- MPI solution ---*/

InitiateComms(geometry, config, SOLUTION);
CompleteComms(geometry, config, SOLUTION);
InitiateComms(geometry, config, MPI_QUANTITIES::SOLUTION);
CompleteComms(geometry, config, MPI_QUANTITIES::SOLUTION);

if (!adjoint) {
/*--- For verification cases, compute the global error metrics. ---*/
Expand Down Expand Up @@ -996,8 +996,8 @@ class CFVMFlowSolverBase : public CSolver {
CompletePeriodicComms(geometry, config, iPeriodic, PERIODIC_IMPLICIT);
}

InitiateComms(geometry, config, SOLUTION);
CompleteComms(geometry, config, SOLUTION);
InitiateComms(geometry, config, MPI_QUANTITIES::SOLUTION);
CompleteComms(geometry, config, MPI_QUANTITIES::SOLUTION);

/*--- For verification cases, compute the global error metrics. ---*/
ComputeVerificationError(geometry, config);
Expand Down
22 changes: 11 additions & 11 deletions SU2_CFD/include/solvers/CFVMFlowSolverBase.inl
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ void CFVMFlowSolverBase<V, R>::CommunicateInitialState(CGeometry* geometry, cons

/*--- Perform the MPI communication of the solution ---*/

InitiateComms(geometry, config, SOLUTION);
CompleteComms(geometry, config, SOLUTION);
InitiateComms(geometry, config, MPI_QUANTITIES::SOLUTION);
CompleteComms(geometry, config, MPI_QUANTITIES::SOLUTION);

/*--- Store the initial CFL number for all grid points. ---*/

Expand Down Expand Up @@ -383,7 +383,7 @@ void CFVMFlowSolverBase<V, R>::SetPrimitive_Gradient_GG(CGeometry* geometry, con
bool reconstruction) {
const auto& primitives = nodes->GetPrimitive();
auto& gradient = reconstruction ? nodes->GetGradient_Reconstruction() : nodes->GetGradient_Primitive();
const auto comm = reconstruction? PRIMITIVE_GRAD_REC : PRIMITIVE_GRADIENT;
const auto comm = reconstruction? MPI_QUANTITIES::PRIMITIVE_GRAD_REC : MPI_QUANTITIES::PRIMITIVE_GRADIENT;
const auto commPer = reconstruction? PERIODIC_PRIM_GG_R : PERIODIC_PRIM_GG;

computeGradientsGreenGauss(this, comm, commPer, *geometry, *config, primitives, 0, nPrimVarGrad, gradient);
Expand All @@ -408,7 +408,7 @@ void CFVMFlowSolverBase<V, R>::SetPrimitive_Gradient_LS(CGeometry* geometry, con
const auto& primitives = nodes->GetPrimitive();
auto& rmatrix = nodes->GetRmatrix();
auto& gradient = reconstruction ? nodes->GetGradient_Reconstruction() : nodes->GetGradient_Primitive();
const auto comm = reconstruction? PRIMITIVE_GRAD_REC : PRIMITIVE_GRADIENT;
const auto comm = reconstruction? MPI_QUANTITIES::PRIMITIVE_GRAD_REC : MPI_QUANTITIES::PRIMITIVE_GRADIENT;

computeGradientsLeastSquares(this, comm, commPer, *geometry, *config, weighted,
primitives, 0, nPrimVarGrad, gradient, rmatrix);
Expand All @@ -423,7 +423,7 @@ void CFVMFlowSolverBase<V, R>::SetPrimitive_Limiter(CGeometry* geometry, const C
auto& primMax = nodes->GetSolution_Max();
auto& limiter = nodes->GetLimiter_Primitive();

computeLimiters(kindLimiter, this, PRIMITIVE_LIMITER, PERIODIC_LIM_PRIM_1, PERIODIC_LIM_PRIM_2, *geometry, *config, 0,
computeLimiters(kindLimiter, this, MPI_QUANTITIES::PRIMITIVE_LIMITER, PERIODIC_LIM_PRIM_1, PERIODIC_LIM_PRIM_2, *geometry, *config, 0,
nPrimVarGrad, primitives, gradient, primMin, primMax, limiter);
}

Expand Down Expand Up @@ -929,8 +929,8 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
/*--- Compute the grid velocities on the coarser levels. ---*/
if (iMesh) geometry[iMesh]->SetRestricted_GridVelocity(geometry[iMesh - 1]);
else {
geometry[MESH_0]->InitiateComms(geometry[MESH_0], config, GRID_VELOCITY);
geometry[MESH_0]->CompleteComms(geometry[MESH_0], config, GRID_VELOCITY);
geometry[MESH_0]->InitiateComms(geometry[MESH_0], config, MPI_QUANTITIES::GRID_VELOCITY);
geometry[MESH_0]->CompleteComms(geometry[MESH_0], config, MPI_QUANTITIES::GRID_VELOCITY);
}
}
}
Expand All @@ -941,8 +941,8 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
on the fine level in order to have all necessary quantities updated,
especially if this is a turbulent simulation (eddy viscosity). ---*/

solver[MESH_0][FLOW_SOL]->InitiateComms(geometry[MESH_0], config, SOLUTION);
solver[MESH_0][FLOW_SOL]->CompleteComms(geometry[MESH_0], config, SOLUTION);
solver[MESH_0][FLOW_SOL]->InitiateComms(geometry[MESH_0], config, MPI_QUANTITIES::SOLUTION);
solver[MESH_0][FLOW_SOL]->CompleteComms(geometry[MESH_0], config, MPI_QUANTITIES::SOLUTION);

/*--- For turbulent/species simulations the flow preprocessing is done by the turbulence/species solver
* after it loads its variables (they are needed to compute flow primitives). In case turbulence and species, the
Expand All @@ -957,8 +957,8 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
for (auto iMesh = 1u; iMesh <= config->GetnMGLevels(); iMesh++) {
MultigridRestriction(*geometry[iMesh - 1], solver[iMesh - 1][FLOW_SOL]->GetNodes()->GetSolution(),
*geometry[iMesh], solver[iMesh][FLOW_SOL]->GetNodes()->GetSolution());
solver[iMesh][FLOW_SOL]->InitiateComms(geometry[iMesh], config, SOLUTION);
solver[iMesh][FLOW_SOL]->CompleteComms(geometry[iMesh], config, SOLUTION);
solver[iMesh][FLOW_SOL]->InitiateComms(geometry[iMesh], config, MPI_QUANTITIES::SOLUTION);
solver[iMesh][FLOW_SOL]->CompleteComms(geometry[iMesh], config, MPI_QUANTITIES::SOLUTION);

if (config->GetKind_Turb_Model() == TURB_MODEL::NONE &&
config->GetKind_Species_Model() == SPECIES_MODEL::NONE) {
Expand Down
Loading

0 comments on commit 83cac12

Please sign in to comment.