Geant4 Kernel

IEEE Nuclear Science Symposium and Medical Imaging Conference
Short Course
The Geant4 Simulation Toolkit
Sunanda Banerjee (Saha Inst. Nucl. Phys., Kolkata, India)
Min Cheol Han (Hanyang Univ., Seoul, Korea)
Steffen Hauf (XFEL, Hamburg, Germany)
Maria Grazia Pia (INFN Genova, Italy)
[email protected]
Seoul, 27 October 2013
http://www.ge.infn.it/geant4/events/nss2013/geant4course.html
This course encompasses training material developed by several Geant4
members:
thanks to all of them!
Geant4 MultiThreading
Evolution of Computer Technology
 Increase in CPU power used to be done by increasing frequency.
This has reached a plateau because of power needs. So
expectation in future trend in computer technology:
– No major increase in single core performance
– Many cores in a processor (double/2 year?)
– Less memory per core
 Need new software models to take these into account → increase
parallelism
 In Geant4 events are supposed to be independent.
– Each event can be simulated separately
– To keep backward compatibility with user code, multi-threading
at event level is a natural choice for parallelism
Geant4 Multithreading
3
What is a thread?
Sequential application
Start N copies of application in the cores
if they fit in memory
MT Application: master controls workers
that do simulation
Introduce shared objects to reduce overall
memory consumption
Geant4 Multithreading
4
Geant4 MT Model
 Steps to be taken
– Isolate static data structure from the dynamic one
– Protect dynamic part of memory which can be shared among the
working threads
 A Geant4 (with MT) application can be seen as simple finite state
machine
 Threads do not exist before /run/beamOn. Master writes shared
memory. When threads start they cannot change the shared memory
Geant4 Multithreading
No locking
5
Geant4 MT Model
Seeds pre-prepared per event
in a “queue”
Threads compete for next
event to be processed
Command line scoring and
G4tools merge results from
threads
Geant4 Multithreading
6
User Application in Sequential Model
Geant4 Multithreading
7
User Application in MT Mode
Geant4 Multithreading
8
Migration to MT (1)
 Move user action class from main() to a new ActionInitialization
class
Geant4 Multithreading
9
Migration to MT (2)
Geant4 Multithreading
10
Migration to MT (3)
 Instantiate G4MTRunManager and replace the code moved in
ActionInitialization with use of this class
 If sensitive detectors are present separate their creation in a new
function CreateSDandField()
– A new utility function can be used:
G4VUserDetectorConstruction::SetSensitiveDetector
 If magnetic field is present, move it to CreateSDandField()
Geant4 Multithreading
11
Migration to MT (4)
 Typically G4Allocator us used in Hit, Trajectory and TrajectoryPoint
classes
– Change static declarations to static G4ThreadLocal
Geant4 Multithreading
12
Computing Performance
Deviation from
linearity less
than 6%
Memory saving
is better than
40%
Geant4 Multithreading
13
Physics Performance
ATLAS
TileCal
MT reproduces sequential results faithfully
Geant4 Multithreading
14