Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
concurrentfill.cxx File Reference

Detailed Description

/*************************************************************************
* Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "ROOT/RHist.hxx"
#include <iostream>
#include <future>
#include <random>
using namespace ROOT;
double wasteCPUTime(std::mt19937 &gen)
{
// Simulate number crunching through gen and ridiculous num bits
return std::generate_canonical<double, 100>(gen) + std::generate_canonical<double, 100>(gen) +
std::generate_canonical<double, 100>(gen) + std::generate_canonical<double, 100>(gen) +
std::generate_canonical<double, 100>(gen);
}
/// This function is called within each thread: it spends some CPU time and then
/// fills a number into the histogram, through the Filler_t. This is repeated
/// several times.
{
std::mt19937 gen;
for (int i = 0; i < 3000000; ++i)
filler.Fill({wasteCPUTime(gen), wasteCPUTime(gen)});
}
/// This example fills a histogram concurrently, from several threads.
{
// RHistConcurrentFillManager allows multiple threads to fill the histogram
// concurrently.
//
// Details: each thread's Fill() calls are buffered. once the buffer is full,
// the RHistConcurrentFillManager locks and flushes the buffer into the
// histogram.
std::array<std::thread, 8> threads;
// Let the threads fill the histogram concurrently.
for (auto &thr: threads) {
// Each thread calls fill(), passing a dedicated filler per thread.
thr = std::thread(theTask, fillMgr.MakeFiller());
}
// Join them.
for (auto &thr: threads)
thr.join();
}
{
// This histogram will be filled from several threads.
Experimental::RH2D hist{{100, 0., 1.}, {{0., 1., 2., 3., 10.}}};
std::cout << hist.GetEntries() << '\n';
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Manages the synchronization of calls to FillN().
Buffers a thread's Fill calls and submits them to the RHistConcurrentFillManager.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Date
2015-07-09
Warning
This is part of the experimental API, which might change in the future. Feedback is welcome!
Author
Axel Naumann axel@.nosp@m.cern.nosp@m..ch

Definition in file concurrentfill.cxx.