Skip to content

Commit

Permalink
Fix thread fail (#7801)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Oct 4, 2016
1 parent c4d96fc commit c9635c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
13 changes: 8 additions & 5 deletions framework/include/vectorpostprocessors/VolumeHistogram.h
Expand Up @@ -32,10 +32,10 @@ class VolumeHistogram : public ElementVectorPostprocessor
public:
VolumeHistogram(const InputParameters & parameters);

virtual void initialize();
virtual void execute();
virtual void finalize();
virtual void threadJoin(const UserObject & y);
virtual void initialize() override;
virtual void execute() override;
virtual void finalize() override;
virtual void threadJoin(const UserObject & y) override;

protected:
/// compute the volume contribution at the current quadrature point
Expand All @@ -62,7 +62,10 @@ class VolumeHistogram : public ElementVectorPostprocessor
/// value mid point of the bin
VectorPostprocessorValue & _bin_center;

/// aggregated volume for the given bin
/// local thread copy of the volume vector
VectorPostprocessorValue _volume_tmp;

/// aggregated global volume vector
VectorPostprocessorValue & _volume;
};

Expand Down
21 changes: 14 additions & 7 deletions framework/src/vectorpostprocessors/VolumeHistogram.C
Expand Up @@ -36,6 +36,7 @@ VolumeHistogram::VolumeHistogram(const InputParameters & parameters) :
_deltaV((_max_value - _min_value) / _nbins),
_value(coupledValue("variable")),
_bin_center(declareVector(getVar("variable", 0)->name())),
_volume_tmp(_nbins),
_volume(declareVector("n"))
{
if (coupledComponents("variable") != 1)
Expand All @@ -51,7 +52,7 @@ void
VolumeHistogram::initialize()
{
// reset the histogram
_volume.assign(_nbins, 0.0);
_volume_tmp.assign(_nbins, 0.0);
}

void
Expand All @@ -64,25 +65,31 @@ VolumeHistogram::execute()
int bin = (_value[_qp] - _min_value) / _deltaV;

// add the volume contributed by the current quadrature point
if (bin >= 0 && bin < _nbins)
_volume[bin] += computeVolume();
if (bin >= 0 && bin < static_cast<int>(_nbins))
_volume_tmp[bin] += computeVolume();
}
}

void
VolumeHistogram::finalize()
{
gatherSum(_volume);
gatherSum(_volume_tmp);

// copy into the MOOSE administered vector postprocessor vector
_volume.resize(_nbins);
mooseAssert(uo._volume_tmp.size() == _nbins, "Inconsistent volume vector lengths.");
for (auto i = beginIndex(_volume_tmp); i < _volume_tmp.size(); ++i)
_volume[i] = _volume_tmp[i];
}

void
VolumeHistogram::threadJoin(const UserObject & y)
{
const VolumeHistogram & uo = static_cast<const VolumeHistogram &>(y);
mooseAssert(uo._volume.size() == _volume.size(), "Inconsistent volume vector lengths across threads.");
mooseAssert(uo._volume_tmp.size() == _volume_tmp.size(), "Inconsistent volume vector lengths across threads.");

for (unsigned int i = 0; i < _volume.size(); ++i)
_volume[i] += uo._volume[i];
for (auto i = beginIndex(_volume_tmp); i < _volume_tmp.size(); ++i)
_volume_tmp[i] += uo._volume_tmp[i];
}

Real
Expand Down

0 comments on commit c9635c9

Please sign in to comment.