Skip to content

Add TBB-based counter for global read-write lock#7260

Merged
pcanal merged 5 commits intoroot-project:masterfrom
bendavid:lockimprovementstbb
Mar 24, 2021
Merged

Add TBB-based counter for global read-write lock#7260
pcanal merged 5 commits intoroot-project:masterfrom
bendavid:lockimprovementstbb

Conversation

@bendavid
Copy link
Copy Markdown
Contributor

Adds TBB-based counter types for global read-write locks and use one by default when TBB is available.

This gives a 7% speedup in a medium sized test filling histograms from CMS NanoAOD with RDF and 256 threads.

This implements the last part of the improvements originally discussed in #6919

@phsft-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@oshadura
Copy link
Copy Markdown
Collaborator

oshadura commented Mar 4, 2021

@phsft-bot build!

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-fedora30/cxx14, ROOT-fedora31/noimt, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-performance-centos8-multicore/default.
Running on null:/data/sftnight/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-fedora30/cxx14.
Running on root-fedora30-2.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-1.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on mac1014/python3.
Running on macphsft17.dyndns.cern.ch:/build/jenkins/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-fedora31/noimt.
Running on root-fedora-31-2.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft23.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

@oshadura
Copy link
Copy Markdown
Collaborator

oshadura commented Mar 4, 2021

@bendavid

2:09:55    In file included from input_line_7:20:
12:09:55    In file included from C:/build/workspace/root-pullrequests-build/build/include\ROOT/TReentrantRWLock.hxx:26:
12:09:55    In file included from C:/build/workspace/root-pullrequests-build/build/include\tbb/enumerable_thread_specific.h:23:
12:09:55    In file included from C:/build/workspace/root-pullrequests-build/build/include\tbb/atomic.h:42:
12:09:55    In file included from C:/build/workspace/root-pullrequests-build/build/include\tbb/tbb_machine.h:113:
12:09:55    In file included from C:/build/workspace/root-pullrequests-build/build/include\tbb/tbb_stddef.h:119:
12:09:55  C:/build/workspace/root-pullrequests-build/build/include\tbb/internal/_tbb_windef.h(28,2): error GAAAB8493: TBB requires linkage with multithreaded C/C++ runtime library.        Choose multithreaded DLL runtime in project settings, or use /MD[d] compiler switch. [C:\build\workspace\root-pullrequests-build\build\core\thread\G__Thread.vcxproj]
12:09:55    #error TBB requires linkage with multithreaded C/C++ runtime library. \
12:09:55     ^
12:09:56  CUSTOMBUILD : error : C:/build/workspace/root-pullrequests-build/build/bin/rootcling_stage1.exe: compilation failure (C:/build/workspace/root-pullrequests-build/build/bin/libThreada1d22a0ca9_dictUmbrella.h) [C:\build\workspace\root-pullrequests-build\build\core\thread\G__Thread.vcxproj]
12:09:56    G__multimap2Dict.vcxproj -> C:\build\workspace\root-pullrequests-build\build\core\clingutils\G__multimap2Dict.dir\Release\G__multimap2Dict.lib
12:09:56    G__unordered_mapDict.vcxproj -> C:\build\workspace\root-pullrequests-build\build\core\clingutils\G__unordered_mapDict.dir\Release\G__unordered_mapDict.lib
12:09:57    G__forward_listDict.vcxproj -> C:\build\workspace\root-pullrequests-build\build\core\clingutils\G__forward_listDict.dir\Release\G__forward_listDict.lib
12:09:57  Command exited with the value: 1
12:09:57  MakeCommand:"C:\Program Files\CMake\bin\cmake.exe" --build . --config "Release" -- /maxcpucount:16
12:09:57  Error(s) when building project
12:09:57     2 Compiler errors

@bendavid
Copy link
Copy Markdown
Contributor Author

bendavid commented Mar 4, 2021

Currently the usage of TBB in core/thread is triggered by the availability of tbb in the build (standalone or builtin). Should the criteria be something different/more selective? (or is there some other switch which needs to be triggered in the windows build for this case?)

@bendavid
Copy link
Copy Markdown
Contributor Author

Alternatively this could be steered by whether the build is done with implicit multithreading enabled, rather than directly checking the availability of TBB (since this seems to not be sufficient in the windows case) Thoughts?

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Mar 15, 2021

I suspect that instead we should still rely on detecting the availability of TBB but disable this feature on Windows, at least for now. (I.e. the condition is "has a TBB and not on Windows").

@bendavid
Copy link
Copy Markdown
Contributor Author

Alright, done.

ROOT_ADD_UNITTEST_DIR(Core Thread Hist ${TBB_LIBRARIES})

ROOT_ADD_GTEST(testTThreadedObject testTThreadedObject.cxx LIBRARIES Hist)
ROOT_ADD_GTEST(testTThreadedObject testTThreadedObject.cxx LIBRARIES Hist ${TBB_LIBRARIES})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Isn't tbb already linked through libThread (and/or libImt)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think you're right, will remove it.

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Mar 16, 2021

@phsft-bot build with flags -DCTEST_TEST_EXCLUDE_NONE=On

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-fedora30/cxx14, ROOT-fedora31/noimt, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14 with flags -DCTEST_TEST_EXCLUDE_NONE=On
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-1.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Failing tests:

@bendavid bendavid force-pushed the lockimprovementstbb branch from bc19562 to da2cf1b Compare March 18, 2021 20:05
@bendavid
Copy link
Copy Markdown
Contributor Author

Updated to remove the unnecessary bits from the CMakeLists for the tests.

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Mar 22, 2021

@bendavid I think this is good to go except for adding some trace in the repository (either commit or, probably better, in the release notes) of the performance improvement.

@bendavid
Copy link
Copy Markdown
Contributor Author

Thanks, I propose to add the relevant information to the release notes in a separate PR (mainly to avoid an otherwise unnecessary rebase before merging)

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Mar 24, 2021

Fair enough :)

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Mar 24, 2021

In the subsequent PR, consider also applying the formatting recommendation at: https://travis-ci.org/github/root-project/root/jobs/763450064

@pcanal pcanal merged commit 9e6f2b9 into root-project:master Mar 24, 2021
bendavid added a commit to bendavid/root that referenced this pull request Mar 24, 2021
eguiraud pushed a commit that referenced this pull request Mar 25, 2021
eguiraud pushed a commit to eguiraud/root that referenced this pull request Mar 25, 2021
eguiraud pushed a commit that referenced this pull request Mar 25, 2021
nicknagi pushed a commit to nicknagi/root that referenced this pull request Mar 30, 2021
guitargeek added a commit to guitargeek/root that referenced this pull request Nov 28, 2025
A long time ago, ROOT had a `tbb` build option, but it was removed in
the ROOT 6.08 development cycle in dd899a5 from 2015, by @peremato.

However, some build configurations still use it, like CMSSW and Conda:
  * https://github.com/cms-sw/cmsdist/blob/IB/CMSSW_15_1_X/master/root.spec#L78
  * https://github.com/conda-forge/root-feedstock/blob/main/recipe/build_root.sh#L342

That would not be a problem per se, but then, in 2021, @bendavid
introduced a new optimization that is enabled only with the long-time
removed `tbb` flag (or `builtin_tbb`), in 6c8b77d:

  * root-project#7260

So we ended up with a secret `tbb=ON` configuration that our CI doesn't
test, and a CMake configuration option that has a pretty fundamental
effect but is not documented.

In the discussions in root-project#19798 with @bendavid, we concluded that it would
not be a problem to enable the optimized locks with TBB always when TBB
is available during the ROOT build. See:
root-project#19798 (comment)

Closes root-project#19798.
guitargeek added a commit that referenced this pull request Nov 29, 2025
A long time ago, ROOT had a `tbb` build option, but it was removed in
the ROOT 6.08 development cycle in dd899a5 from 2015, by @peremato.

However, some build configurations still use it, like CMSSW and Conda:
  * https://github.com/cms-sw/cmsdist/blob/IB/CMSSW_15_1_X/master/root.spec#L78
  * https://github.com/conda-forge/root-feedstock/blob/main/recipe/build_root.sh#L342

That would not be a problem per se, but then, in 2021, @bendavid
introduced a new optimization that is enabled only with the long-time
removed `tbb` flag (or `builtin_tbb`), in 6c8b77d:

  * #7260

So we ended up with a secret `tbb=ON` configuration that our CI doesn't
test, and a CMake configuration option that has a pretty fundamental
effect but is not documented.

In the discussions in #19798 with @bendavid, we concluded that it would
not be a problem to enable the optimized locks with TBB always when TBB
is available during the ROOT build. See:
#19798 (comment)

Closes #19798.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants