Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/base/inc/TROOT.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace Internal {
TParBranchProcessingRAII() { EnableParBranchProcessing(); }
~TParBranchProcessingRAII() { DisableParBranchProcessing(); }
};

// Manage parallel tree processing
void EnableParTreeProcessing();
void DisableParTreeProcessing();
Expand All @@ -95,6 +95,7 @@ namespace ROOT {
void DisableImplicitMT();
Bool_t IsImplicitMTEnabled();
UInt_t GetImplicitMTPoolSize();
UInt_t GetAvailableThreads();
}

class TROOT : public TDirectory {
Expand Down
15 changes: 15 additions & 0 deletions core/base/src/TROOT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,21 @@ namespace Internal {
#endif
}

////////////////////////////////////////////////////////////////////////////////
/// Returns the number of concurrent threads supported by the implementation.
/// In the IMT case returns the number of logical CPUs available to the current process in accordance with its TBB affinity mask.
UInt_t GetNThreadsAvailable()
{
#ifdef R__USE_IMT
static UInt_t (*sym)() = (UInt_t(*)())Internal::GetSymInLibImt("ROOT_TImplicitMT_GetNThreadsAvailable");
if (sym)
return sym();
else
return 0;
#else
return std::thread::hardware_concurrency();
#endif
}
}

TROOT *ROOT::Internal::gROOTLocal = ROOT::GetROOT();
Expand Down
5 changes: 5 additions & 0 deletions core/imt/inc/ROOT/TPoolManager.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace ROOT {
/// The number of threads will be able to change calling the factory function again after the last
/// remaining shared_ptr owning the object is destroyed or reasigned, which will trigger the destructor of the manager.
std::shared_ptr<TPoolManager> GetPoolManager(UInt_t nThreads = 0);


/// Get the number of logical CPUs in the system.
/// In case of having an affinity mask (TBB), return the number of logical CPUs available to the current process in accordance with it.
Int_t GetNThreadsAvailable();
}
}

Expand Down
4 changes: 4 additions & 0 deletions core/imt/src/TImplicitMT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ extern "C" UInt_t ROOT_TImplicitMT_GetImplicitMTPoolSize()
return ROOT::Internal::TPoolManager::GetPoolSize();
};

extern "C" UInt_t ROOT_TImplicitMT_GetNThreadsAvailable()
{
return ROOT::Internal::GetNThreadsAvailable();
};

extern "C" void ROOT_TImplicitMT_EnableParBranchProcessing()
{
Expand Down
5 changes: 5 additions & 0 deletions core/imt/src/TPoolManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ namespace ROOT {
}
return GetWP().lock();
}

Int_t GetNThreadsAvailable()
{
return tbb::task_scheduler_init::default_num_threads();
}
}
}