Skip to content

Commit a256d39

Browse files
Refactor probe value handling and memory allocation
1 parent f3ce25f commit a256d39

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

SU2_CFD/src/output/CFlowOutput.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ void CFlowOutput::SetCustomOutputs(const CSolver* const* solver, const CGeometry
838838
ADT overhead is only worth it for larger numbers of probes. ---*/
839839
unsigned long nProbes = 0;
840840
for (const auto& output : customOutputs) {
841-
if (!output.skip && output.type == OperationType::PROBE && output.varIndices.empty()) {
841+
if (!output.skip && output.type == OperationType::PROBE) {
842842
++nProbes;
843843
}
844844
}
@@ -1004,23 +1004,24 @@ void CFlowOutput::SetCustomOutputs(const CSolver* const* solver, const CGeometry
10041004
/*--- Batch AllReduce for all probe values to reduce MPI communication overhead. ---*/
10051005
if (nProbes > 0) {
10061006
/*--- Evaluate all probe values locally first. ---*/
1007-
vector<su2double> probeValues(nProbes);
1008-
unsigned long iProbe = 0;
1007+
vector<su2double> probeValues;
1008+
probeValues.reserve(nProbes);
10091009
for (auto& output : customOutputs) {
10101010
if (output.skip || output.type != OperationType::PROBE) continue;
10111011
su2double value = std::numeric_limits<su2double>::max();
10121012
if (output.iPoint != CustomOutput::PROBE_NOT_OWNED) {
10131013
value = output.Eval(GetPointValue(output, output.iPoint));
10141014
}
1015-
probeValues[iProbe++] = value;
1015+
probeValues.push_back(value);
10161016
}
10171017

10181018
/*--- Single AllReduce for all probe values. ---*/
1019-
vector<su2double> probeValuesGlobal(nProbes);
1020-
SU2_MPI::Allreduce(probeValues.data(), probeValuesGlobal.data(), nProbes, MPI_DOUBLE, MPI_MIN, SU2_MPI::GetComm());
1019+
unsigned long nProbesActual = probeValues.size();
1020+
vector<su2double> probeValuesGlobal(nProbesActual);
1021+
SU2_MPI::Allreduce(probeValues.data(), probeValuesGlobal.data(), nProbesActual, MPI_DOUBLE, MPI_MIN, SU2_MPI::GetComm());
10211022

10221023
/*--- Set history output values for all probes. ---*/
1023-
iProbe = 0;
1024+
unsigned long iProbe = 0;
10241025
for (auto& output : customOutputs) {
10251026
if (output.skip || output.type != OperationType::PROBE) continue;
10261027
SetHistoryOutputValue(output.name, probeValuesGlobal[iProbe++]);

0 commit comments

Comments
 (0)