Giter Site home page Giter Site logo

geant4-multithreading's Introduction

Multi-Threading With Geant4 10.4

This reposity contains three examples how to interface Geant4 from your application and use its multi-threading capabilities:

  • g4-test-nomt: No multi-threading, using standard G4RunManager for sequential execution of events
  • g4-test-g4mt: Using the G4MTRunManager for Geant4-internal parallelization, seeting the number of threads from the command-line paramater
  • g4-test-ownmt: Implements threading independent from G4MTRunManager which gives the user more control over how and when events are executed.

Compile

mkdir build && cd build/
cmake ..
make

Structure

Geant4 Manager with no multithreading

main_nomt.cpp shows an example of using G4RunManager class. This class manages an event loop to execute a specified number of events. Each time the method BeamOn is called, the manager will initialize, run and terminate the event loop which run sequentially.

Geant4 MultiThreaded Manager

main_g4mt.cpp shows an example of using G4MTRunManager class. This class inherits G4RunManager but it acts as a thread pool and is often identified as master run manager. The actual work is offloaded to instances of G4WorkerRUnManager class which are called workers.

The master will create the specified number of threads and for each thread a worker instance. A call to BeamOn will result in the creation of such threads and workers, initialization of each worker to share the same geometry and physics setup, the execution of the event loop distributed on the specified number of workers, and finally the termination and destructions of the threads and workers.

Each worker will perform the same work as what a normal G4RunManager is expected to do. The only difference is that it shares the geometry construction with the master manager and it will only execute part of the event loop. The master manager is he who determines the workload each worker will do. It also makes sure workers random number generators are seeded in a way so that ensures results can be reproduced.

Custom Geant4 RunManager

main_ownmt.cpp shows an example of defining a custom run manager that doesn't control or spawn threads. On the otherhand, this manager works in accordance of a higher level framework that manages the event loop instead.

SimpleMasterRunManager.hpp defines an equivalent to G4MTRunManager except that it doesn't spawn its own threads. It only maintains a set of SimpleWokerRunManager.hpp which are the equivalent of G4WorkerRunManager for each thread.

The master manager expects to be used by a framework that defines its own event loop and as such its own threads. To handle this case, the master manager manipulates the G4MTRunManager API behaviour in a way that associates a worker manager for each calling thread. The event loop of the run manager is initialized early on, before calling BeamOn and a new method Run is defined which in turn call the BeamOn method on each worker.

geant4-multithreading's People

Contributors

mmoanis avatar simonspa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.