Skip to content

Commit

Permalink
[RF] Bugfix in RooFit driver: fix node computation order
Browse files Browse the repository at this point in the history
The RooFit driver got the order of the nodes wrong because the correct
order information got lost in the `std::unordered_map`. A new
`std::vector` is introduced to keep track of the evaluation order.
  • Loading branch information
guitargeek committed Aug 10, 2021
1 parent a0cdcdf commit 17735c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions roofit/roofitcore/inc/RooFitDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class RooFitDriver {
const RooNLLVarNew& _topNode;
const RooAbsData* const _data = nullptr;
const size_t _nEvents;

std::vector<const RooAbsReal*> _nodes;
std::unordered_map<const RooAbsReal*, NodeInfo> _nodeInfos;

//used for preserving resources
Expand Down
19 changes: 11 additions & 8 deletions roofit/roofitcore/src/RooFitDriver.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ RooFitDriver::RooFitDriver(const RooAbsData& data, const RooNLLVarNew& topNode,
}
else //this node needs evaluation, mark it's clients
{
_nodes.push_back(pAbsReal);

// If the node doesn't depend on any observables, there is no need to
// loop over events and we don't need to use the batched evaluation.
RooArgSet observablesForNode;
Expand Down Expand Up @@ -155,7 +157,8 @@ double RooFitDriver::getVal()
for (const auto& it:_nodeInfos)
if (it.second.remServers==0 && it.second.computeInGPU)
assignToGPU(it.first);



int nNodes = _nodeInfos.size();
while (nNodes)
{
Expand All @@ -171,22 +174,22 @@ double RooFitDriver::getVal()
}

// find next cpu node
auto it=_nodeInfos.begin();
for ( ; it!=_nodeInfos.end(); it++)
if (it->second.remServers==0 && !it->second.computeInGPU) break;
auto it = std::find_if(_nodes.begin(), _nodes.end(), [&](const RooAbsReal* a){
auto const& info = _nodeInfos[a]; return info.remServers==0 && !info.computeInGPU; });

// if no cpu node available sleep for a while to save cpu usage
if (it==_nodeInfos.end())
if (it==_nodes.end())
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue;
}

// compute next cpu node
const RooAbsReal* node = it->first;
NodeInfo& info = it->second;
const RooAbsReal* node = *it;
NodeInfo& info = _nodeInfos[*it];
info.remServers=-2; //so that it doesn't get picked again
nNodes--;

if (info.computeInScalarMode)
{
_nonDerivedValues.push_back(node->getVal(_data->get()));
Expand Down

0 comments on commit 17735c9

Please sign in to comment.