Message: Re: Integrating a class into a G4 MT enviorment Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Integrating a class into a G4 MT enviorment 

Forum: Multithreading
Re: None Integrating a class into a G4 MT enviorment (William Donahue)
Date: 28 Apr, 2014
From: Andrea Dotti <Andrea Dotti>

Hello, In the following I assume you have already evaluated that what you want to do cannot be obtained with built-in functionalities of Geant4 and thus an ad-hoc analysis type class is the best for your use case.

Said this consider that to make a new "piece of software" integrated with MT you need to identify if this element is shared among threads or is "thread-private" (e.g. each thread has its won copy). I suggest you to consider the seconda case (unless it is expected that this element will use a very large, O(100MB), fraction of the memory of your system). I will consider here the second case, because this is the typical one and the simpler. It is relatively simple to add it to a MT application: in principle no changes are needed to your class specific code. There is no need to add G4ThreadLocal anywhere, unless you have static or global variables in your code (in such a case consult ).

My suggestion is that you instantiate your sphereDetect object via run and run action. The idea is that you can sub-class from G4Run and create your specific type of run. This new class can have, as a data-member an instance of sphereDetect. Since each thread has an instance of G4Run (or inherited as in this case), each thread will have its own sphereDetect. You need also to implement a Merge(G4Run*) method that implements the logic of reduction of sphereDetect into a single object (the master one). See

Summarizing: 1- Create a Run class inheriting from G4Run that own sphereDetect instance 2- Implement the reduction in G4Run::Merge 3- Create a RunAction class that instantiate your run in GenerateRun() method 4- Remember to instantiate this RunAction class for both master and workers in Build() and BuildForMaster() methods of your ActionInitialization class

You can see an example of all these in action in basic example basic/B1 (B1Run, B1RunAction and B1ActionInitialization classes)

A tutorial/manual for MT describing all this can be found here:

Regards, Andrea

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: Integrating a class into a G4 MT enviorment   (William Donahue - 28 Apr, 2014)
2 None: Re: Integrating a class into a G4 MT enviorment   (William Donahue - 28 Apr, 2014)
 Add Message Add Message
to: "Re: Integrating a class into a G4 MT enviorment"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews