Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:48

0001 // @(#)root/thread:$Id$
0002 // // Author: Xavier Valls Pla   08/05/20
0003 //
0004 /*************************************************************************
0005  * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 //////////////////////////////////////////////////////////////////////////
0013 //                                                                      //
0014 // RTaskArena                                                           //
0015 //                                                                      //
0016 // This file implements the method to initialize and retrieve ROOT's    //
0017 // global task arena, together with a method to check for active        //
0018 // CPU bandwith control, and a class to wrap the tbb task arena with    //
0019 // the purpose of keeping tbb off the installed headers                 //
0020 //                                                                      //
0021 //////////////////////////////////////////////////////////////////////////
0022 
0023 #ifndef ROOT_RTaskArena
0024 #define ROOT_RTaskArena
0025 
0026 #include "RConfigure.h"
0027 #include <memory>
0028 
0029 // exclude in case ROOT does not have IMT support
0030 #ifndef R__USE_IMT
0031 // No need to error out for dictionaries.
0032 # if !defined(__ROOTCLING__) && !defined(G__DICTIONARY)
0033 #  error "Cannot use ROOT::Internal::RTaskArenaWrapper if build option imt=OFF."
0034 # endif
0035 #else
0036 
0037 /// tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow
0038 /// to forward declare tbb::task_arena without forward declaring tbb::interface7
0039 
0040 namespace ROOT {
0041 
0042 class ROpaqueTaskArena;
0043 
0044 namespace Internal {
0045 
0046 ////////////////////////////////////////////////////////////////////////////////
0047 /// Returns the available number of logical cores.
0048 ///
0049 ///  - Checks if there is CFS bandwidth control in place (linux, via cgroups,
0050 ///    assuming standard paths)
0051 ///  - Otherwise, returns the number of logical cores provided by
0052 ///    std::thread::hardware_concurrency()
0053 ////////////////////////////////////////////////////////////////////////////////
0054 int LogicalCPUBandwidthControl();
0055 
0056 
0057 ////////////////////////////////////////////////////////////////////////////////
0058 /// Wrapper for tbb::task_arena.
0059 ///
0060 /// Necessary in order to keep tbb away from ROOT headers.
0061 /// This class is thought out to be used as a singleton.
0062 ////////////////////////////////////////////////////////////////////////////////
0063 class RTaskArenaWrapper {
0064 public:
0065    ~RTaskArenaWrapper(); // necessary to set size back to zero
0066    static unsigned TaskArenaSize(); // A static getter lets us check for RTaskArenaWrapper's existence
0067    ROOT::ROpaqueTaskArena &Access();
0068 private:
0069    RTaskArenaWrapper(unsigned maxConcurrency = 0);
0070    friend std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned maxConcurrency);
0071    std::unique_ptr<ROOT::ROpaqueTaskArena> fTBBArena;
0072    static unsigned fNWorkers;
0073 };
0074 
0075 
0076 ////////////////////////////////////////////////////////////////////////////////
0077 /// Factory function returning a shared pointer to the instance of the global
0078 /// RTaskArenaWrapper.
0079 ///
0080 /// Allows for reinstantiation of the global RTaskArenaWrapper once all the
0081 /// references to the previous one are gone and the object destroyed.
0082 ////////////////////////////////////////////////////////////////////////////////
0083 std::shared_ptr<ROOT::Internal::RTaskArenaWrapper> GetGlobalTaskArena(unsigned maxConcurrency = 0);
0084 
0085 } // namespace Internal
0086 } // namespace ROOT
0087 
0088 #endif   // R__USE_IMT
0089 #endif   // ROOT_RTaskArena