Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDFHelpers.cxx
Go to the documentation of this file.
1// Author: Stefan Wunsch, Enrico Guiraud CERN 09/2020
2
3/*************************************************************************
4 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "ROOT/RDFHelpers.hxx"
12#include "TROOT.h" // IsImplicitMTEnabled
13#include "TError.h" // Warning
14#include "TStopwatch.h"
15#include "RConfigure.h" // R__USE_IMT
16#include "ROOT/RLogger.hxx"
17#include "ROOT/RDF/RLoopManager.hxx" // for RLoopManager
18#include "ROOT/RDF/Utils.hxx"
19#include "ROOT/RResultHandle.hxx" // for RResultHandle, RunGraphs
20#ifdef R__USE_IMT
22#endif // R__USE_IMT
23
24#include <algorithm>
25#include <set>
26
28
29void ROOT::RDF::RunGraphs(std::vector<RResultHandle> handles)
30{
31 if (handles.empty()) {
32 Warning("RunGraphs", "Got an empty list of handles, now quitting.");
33 return;
34 }
35
36 // Check that there are results which have not yet been run
37 const unsigned int nToRun =
38 std::count_if(handles.begin(), handles.end(), [](const auto &h) { return !h.IsReady(); });
39 if (nToRun < handles.size()) {
40 Warning("RunGraphs", "Got %lu handles from which %lu link to results which are already ready.", handles.size(),
41 handles.size() - nToRun);
42 }
43 if (nToRun == 0u)
44 return;
45
46 // Find the unique event loops
47 auto sameGraph = [](const RResultHandle &a, const RResultHandle &b) { return a.fLoopManager < b.fLoopManager; };
48 std::set<RResultHandle, decltype(sameGraph)> s(handles.begin(), handles.end(), sameGraph);
49 std::vector<RResultHandle> uniqueLoops(s.begin(), s.end());
50
51 // Trigger jitting. One call is enough to jit the code required by all computation graphs.
52 TStopwatch sw;
53 sw.Start();
54 {
55 const auto effectiveVerbosity =
58 if (effectiveVerbosity >= ROOT::Experimental::ELogLevel::kDebug + 10) {
59 // a very high verbosity was requested, let's not silence anything
60 uniqueLoops[0].fLoopManager->Jit();
61 } else {
62 // silence logs from RLoopManager::Jit: RunGraphs does its own logging
65 uniqueLoops[0].fLoopManager->Jit();
66 }
67 }
68 sw.Stop();
70 << "Just-in-time compilation phase for RunGraphs (" << uniqueLoops.size()
71 << " unique computation graphs) completed"
72 << (sw.RealTime() > 1e-3 ? " in " + std::to_string(sw.RealTime()) + " seconds." : " in less than 1ms.");
73
74 // Trigger the unique event loops
75 auto run = [](RResultHandle &h) {
76 if (h.fLoopManager)
77 h.fLoopManager->Run(/*jit=*/false);
78 };
79
80 sw.Start();
81#ifdef R__USE_IMT
83 ROOT::TThreadExecutor{}.Foreach(run, uniqueLoops);
84 } else {
85#endif
86 std::for_each(uniqueLoops.begin(), uniqueLoops.end(), run);
87#ifdef R__USE_IMT
88 }
89#endif
90 sw.Stop();
92 << "Finished RunGraphs run (" << uniqueLoops.size() << " unique computation graphs, " << sw.CpuTime() << "s CPU, "
93 << sw.RealTime() << "s elapsed).";
94}
#define R__LOG_INFO(...)
Definition RLogger.hxx:364
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
#define e(i)
Definition RSha256.hxx:103
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:241
ELogLevel GetEffectiveVerbosity(const RLogManager &mgr) const
Definition RLogger.hxx:313
static RLogManager & Get()
Definition RLogger.cxx:62
Change the verbosity level (global or specific to the RLogChannel passed to the constructor) for the ...
Definition RLogger.hxx:243
This class provides a simple interface to execute the same task multiple times in parallel threads,...
void Foreach(F func, unsigned nTimes, unsigned nChunks=0)
Execute a function without arguments several times in parallel, dividing the execution in nChunks.
Stopwatch class.
Definition TStopwatch.h:28
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.
ROOT::Experimental::RLogChannel & RDFLogChannel()
Definition RDFUtils.cxx:37
RLogChannel & GetChannelOrManager()
Definition RLogger.hxx:302
@ kDebug
Debug information; only useful for developers; can have added verbosity up to 255-kDebug.
void RunGraphs(std::vector< RResultHandle > handles)
Trigger the event loop of multiple RDataFrames concurrently.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
Definition TROOT.cxx:558