-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rivet ParticleLevelProducer and HTXS multi-threading #30888
Merged
cmsbuild
merged 9 commits into
cms-sw:master
from
mseidel42:rivet_fastjet_contrib_update
Sep 1, 2020
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4b098c7
Rivet ParticleLevelProducer and HTXS multi-threading
mseidel42 fe60c1a
Check if FS projection is registered, otherwise re-init
mseidel42 86e34d1
Apply code-format
mseidel42 03bf652
Add reinit for HTXS, delete discarded pointers
mseidel42 7748360
Code-checks, no need to check for nullptr
mseidel42 ad8b62f
Make these one producers again until Rivet becomes really thread-safe
mseidel42 b053a1e
Use unique_ptr where possible
mseidel42 c2d8c19
Remove deletes
mseidel42 313863a
Apply code-checks/format
mseidel42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the
ProjectionHandler::getInstance()
is called in the constructor ofProjectionApplier
, andAnalysis
inherits fromProjectionApplier
, and ourRivetAnalysis
inherits fromAnalysis
.Does anything inside
AnalysisHandler
object (RivetAnalysis
,Analysis
,ProjectionApplier
, or any helper class they use) rely that exactly the sameProjectionHandler
object is used every time?Or actually conversely, can it be "proven" that for a given
AnalysisHandler
object, it does not matter whichProjectionHandler
object it uses (i.e. they could be cached in arbitrary way) as long as the same one is used for the whole duration of theAnalysisHandle::analyze()
call? I.e. essentially theProjectionApplier
could be changed to replaceProjectionHandler
member with always callingProjectionHandler::getInstance()
? (I'm not actually suggesting that, it's just an attempt to help to think about consequences)I'm asking because we do not guarantee an instance of a
edm::stream
module to be run on any specific thread. A module instance could run on a different thread on each event than on the previous event.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a further thought, I suspect this approach won't work in general with TBB. The approach would probably work if each instance of the
edm::stream
module would process the first event in a different thread wrt others because of this assignment in the constructor ofProjectionApplier
https://gitlab.com/hepcedar/rivet/-/blob/release-3-1-x/src/Core/ProjectionApplier.cc#L13
But we don't guarantee that. If two instances process the first event on the same thread, their
RivetAnalysis
objects will hold a reference to the sameProjectionHandler
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Matti,
I think the
ProjectionHandler
objects are in principle interchangeable, they should just not be used at the same time.If you have a patch to Rivet in mind I could try it out.
Is there any way to provoke that behavior for testing?
I modified this PR to re-init when the standard "FS" projection is not found. But I am not sure if that would solve the problem that you described.
Cheers,
Markus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Markus,
That's good.
I don't, but to me the solution the authors outlined in https://gitlab.com/hepcedar/rivet/-/issues/84, i.e. each
AnalysisHandler
having its ownProjectionHandler
object would be the best.We don't need
AnalysisHandler
to be thread-safe by itself, avoiding any global state (which now occurs throughProjectionHandler::getInstance()
for it to be thread-friendly would be sufficient.With a minimal configuration of just the
ParticleLevelProducer
and whatever modules it requires it could be possible to hack alongParticleLevelProducer
in a Path in the order ofcms.Path(spinningModule, particleLevelProducer)
spinningModule
Then it could happen that many or all of the
ParticleLevelProducer
stream instances get run in the same thread (becausespinningModule
is keeping the other threads busy).I suspect it will not solve that particular problem. Or at least I'd assume if two
RivetAnalysis
's are initialized with the sameProjectionHandler
, thehasProjection("FS")
would returntrue
for both of them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Matti,
I think the calls to getProjection (when a projection is applied) and hasProjection follow the same structure, see below.
Thus, the hasProjection should return false when the ProjectionHandler for a specific thread was not initialized (or initialized in another thread). In that case, the re-initialization should fix the problem.
Best,
Markus
This is the part of the code throwing the error:
called by ProjectionApplier/Analysis here:
The
hasProjection
goes through very similar code:called by this function in ProjectionApplier/Analysis:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behavior breaks already with
ProjectionApplier::getProjHandle()
where
_projhandler
is initialized in the constructorTherefore, if two
ProjectionApplier
objects are created in the same thread, they get the sameProjectionHandler
object. If theseProjectionApplier
objects are later used in different threads, theirgetProjHandler()
continue to return a reference to the same (shared)ProjectionHandler
object, and theProjectionHandler::hasProjection()
will give the same answer to both (unless its internal state has already broken because of the data races).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, and if we patch Rivet to use gettimeofday microseconds instead of the thread id? That should give as a unique ProjectionHandler for each stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would much rather see the "proper fix" suggested in https://gitlab.com/hepcedar/rivet/-/issues/84#note_341649903, i.e. each
ProjectionApplier
object just having its ownPojectionHandler
object. It is simpler and works correctly. If we go to patch Rivet, we could even contribute it to upstream and help to close that issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's see if that can be done, I hope there is no major roadblock for that.
Otherwise, we may just make this a
one
module again.