Message: Re: Multithreading and random generators Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Multithreading and random generators 

Forum: Multithreading
Re: Question Multithreading and random generators (Stefano Caiazza)
Date: 06 Jun, 2014
From: Andrea Dotti <Andrea Dotti>

Hello Stefano,

you are right: at the moment the engines treatment in MT is probably not-optimal. This is because we use internally CLHEP that does not support cloning mechanism. We are reviewing use of RNG for future releases and this mechanism may change but this will come only on a months timescale.

However we have designed this part of the code with a solution in mind. Please consider the comments in the header file:
 http://www-geant4.kek.jp/lxr/source/run/include/G4UserWorkerThreadInitialization.hh

This is a user class, meaning that you should sub-class it and reimplement the method you need with your "cloning".

What you have to do is quite straightforward, you can add these lines in the main function file (I leave to you to add the correct #include):

class MyThreadInit : public G4UserWorkerThreadInitialization {
public:
     void SetupRNGEngine(const CLHEP::HepRandomEngine* /*aRNGEngine*/) const {
              //You may need locks
              G4Random::setTheEngine( new MYRNG );
     }
};

int main(int,char**) {
      //...
      G4Random::SetTheEngine( new MYRNG );
      G4MTRunManager* rm = new G4MTRunManager();
      rm->SetUserInitialization( new MyThreadInit );
      //...
}

Some additional information is also described here: https://twiki.cern.ch/twiki/bin/view/Geant4/Geant4MTAdvandedTopicsForApplicationDevelopers#Worker_thread_specific_initializ

Regards, Andrea

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

1 Ok: Re: Multithreading and random generators   (Stefano Caiazza - 06 Jun, 2014)
(_ Question: Re: Multithreading and random generators   (panda - 11 Dec, 2016)
 Add Message Add Message
to: "Re: Multithreading and random generators"

 Subscribe Subscribe

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