Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Gaussino
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tao Lin
Gaussino
Commits
17e9370e
Commit
17e9370e
authored
6 years ago
by
Dominik Muller
Browse files
Options
Downloads
Patches
Plain Diff
Fixed clean-up of thread-local objects
parent
409e241b
Branches
refactor
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Gen/LbPythia8/LbPythia8/Pythia8ProductionMT.h
+7
-12
7 additions, 12 deletions
Gen/LbPythia8/LbPythia8/Pythia8ProductionMT.h
Gen/LbPythia8/src/Lib/Pythia8ProductionMT.cpp
+16
-37
16 additions, 37 deletions
Gen/LbPythia8/src/Lib/Pythia8ProductionMT.cpp
with
23 additions
and
49 deletions
Gen/LbPythia8/LbPythia8/Pythia8ProductionMT.h
+
7
−
12
View file @
17e9370e
...
...
@@ -139,14 +139,7 @@ public:
// Members needed externally.
string
m_beamToolName
;
///< The name of the beam tool.
void
AddInstance
()
{
Instances
().
push_back
(
this
);
}
virtual
StatusCode
InitializeThread
();
virtual
StatusCode
FinalizeThread
();
static
std
::
vector
<
Pythia8ProductionMT
*>&
Instances
()
{
static
std
::
vector
<
Pythia8ProductionMT
*>
store
;
return
store
;
}
protected:
/**
...
...
@@ -182,16 +175,18 @@ protected:
{
public:
Pythia8ThreadManager
()
=
default
;
~
Pythia8ThreadManager
()
{
for
(
auto
&
tool
:
Pythia8ProductionMT
::
Instances
()
)
{
tool
->
debug
()
<<
"Finalizing in thread via manager"
<<
endmsg
;
tool
->
FinalizeThread
();
for
(
auto
[
pythia
,
hooks
,
lhaup
,
beam
]
:
store
)
{
if
(
pythia
)
delete
pythia
;
if
(
hooks
)
delete
hooks
;
if
(
lhaup
)
delete
lhaup
;
if
(
beam
)
delete
beam
;
}
}
std
::
vector
<
std
::
tuple
<
Pythia8
::
Pythia
*
,
Pythia8
::
UserHooks
*
,
Pythia8
::
LHAup
*
,
BeamToolForPythia8
*>>
store
;
};
static
thread_local
Pythia8ThreadManager
m_manager
;
Pythia8ThreadManager
*
m_manager
{
nullptr
}
;
private
:
unsigned
int
m_nThreads
{
0
};
...
...
This diff is collapsed.
Click to expand it.
Gen/LbPythia8/src/Lib/Pythia8ProductionMT.cpp
+
16
−
37
View file @
17e9370e
...
...
@@ -39,7 +39,6 @@
// 2007-07-31 : Arthur de Gromard, Philip Ilten
//-----------------------------------------------------------------------------
thread_local
Pythia8ProductionMT
::
Pythia8ThreadManager
Pythia8ProductionMT
::
m_manager
{};
std
::
mutex
Pythia8ProductionMT
::
m_pythia_lock
{};
//=============================================================================
// Default constructor.
...
...
@@ -147,16 +146,13 @@ StatusCode Pythia8ProductionMT::initialize()
StatusCode
sc
=
GaudiTool
::
initialize
();
if
(
sc
.
isFailure
()
)
Exception
(
"Failed to initialize the Gaudi tool."
);
// Add this to the global list for later per thread initialization
// by a ThreadInitTool. We <3 hacks
AddInstance
();
// Initialize the beam tool.
m_beamTool
=
tool
<
IBeamTool
>
(
m_beamToolName
,
this
);
if
(
!
m_beamTool
)
Exception
(
"Failed to initialize the IBeamTool."
);
// Initialze the XML log file.
m_xmlLogTool
=
tool
<
ICounterLogFile
>
(
"XmlCounterLogFile"
);
m_manager
=
new
Pythia8ThreadManager
{};
return
sc
;
}
...
...
@@ -240,11 +236,6 @@ StatusCode Pythia8ProductionMT::initializeGenerator()
return
Error
(
"Failed to initialize Pythia 8."
);
}
//=============================================================================
// Finalize the tool.
//=============================================================================
StatusCode
Pythia8ProductionMT
::
finalize
()
{
return
GaudiTool
::
finalize
();
}
//=============================================================================
// Generate an event.
//=============================================================================
...
...
@@ -546,40 +537,28 @@ StatusCode Pythia8ProductionMT::InitializeThread()
// GarbageBin<Pythia8::LHAup*>::Add( m_lhaup() );
// GarbageBin<BeamToolForPythia8*>::Add( m_pythiaBeamTool() );
// Push this into the manager for later merging and cleanup of the used pythia instances
std
::
lock_guard
<
std
::
mutex
>
l
{
m_pythia_lock
};
m_manager
->
store
.
emplace_back
(
m_pythia
(),
m_hooks
(),
m_lhaup
(),
m_pythiaBeamTool
()
);
return
StatusCode
::
SUCCESS
;
}
StatusCode
Pythia8ProductionMT
::
F
inalize
Thread
()
StatusCode
Pythia8ProductionMT
::
f
inalize
()
{
if
(
!
m_pythia
()
)
{
debug
()
<<
"Skipping finalization because no pythia instance set in thread."
<<
endmsg
;
return
StatusCode
::
SUCCESS
;
}
// Print the statistics.
std
::
lock_guard
guard
(
m_pythia_lock
);
m_pythia
->
stat
();
// Write the cross-sections to the XML log.
vector
<
int
>
codes
=
m_pythia
->
info
.
codesHard
();
for
(
unsigned
int
code
=
0
;
code
<
codes
.
size
();
++
code
)
m_xmlLogTool
->
addCrossSection
(
m_pythia
->
info
.
nameProc
(
codes
[
code
]
),
codes
[
code
],
m_pythia
->
info
.
nAccepted
(
codes
[
code
]
),
m_pythia
->
info
.
sigmaGen
(
codes
[
code
]
)
);
// Clean up.
if
(
m_lhaup
()
)
{
delete
m_lhaup
();
}
if
(
m_hooks
()
)
{
delete
m_hooks
();
}
if
(
m_pythia
()
)
{
delete
m_pythia
();
for
(
auto
[
pythia
,
hooks
,
lhaup
,
beam
]
:
m_manager
->
store
)
{
pythia
->
stat
();
// Write the cross-sections to the XML log.
vector
<
int
>
codes
=
pythia
->
info
.
codesHard
();
for
(
unsigned
int
code
=
0
;
code
<
codes
.
size
();
++
code
)
m_xmlLogTool
->
addCrossSection
(
pythia
->
info
.
nameProc
(
codes
[
code
]
),
codes
[
code
],
pythia
->
info
.
nAccepted
(
codes
[
code
]
),
pythia
->
info
.
sigmaGen
(
codes
[
code
]
)
);
}
if
(
m_pythiaBeamTool
()
)
{
delete
m_pythiaBeamTool
();
}
return
StatusCode
::
SUCCESS
;
// Clean up.
delete
m_manager
;
return
GaudiTool
::
finalize
();
}
//=============================================================================
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment