Message: Re: Setting RNG Seeds in MT main() not working Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Note Re: Setting RNG Seeds in MT main() not working 

Forum: Multithreading
Re: None Setting RNG Seeds in MT main() not working (William Donahue)
Re: None Re: Setting RNG Seeds in MT main() not working (William Donahue)
Date: 27 Aug, 2018
From: William Donahue <William Donahue>

Ok I hope everyone who is searching for this issue will find it.

The solution to set a random seed for Geant4 when multithreading appears to be setting up the RNG before creating the MTRunManager Instance. This is because the Default constructor the MTRunManager creates a default initialized RNG for use if there is not one in existence.

If this was stated before, I apologize for stating it again. However, in all the documentation and forum posts this was not made clear. After fighting with this for the past two weeks this solution was nice because it prevented me from having to create a custom MTRunManager Class (which ended up leading to runtime issues).

Below is the new beginning to my main file, each time the events kick off with new random seeds. {

int main(int argc, char **argv) {

    std::random_device r;
    std::seed_seq seed2{r(), r(), r(), r(), r(), r(), r(), r()};
    std::mt19937 e2(seed2);
    G4long seeds[2];
    seeds[0] = (long) e2();
    seeds[1] = (long) e2();
    auto *randomEngine = new CLHEP::MixMaxRng();

    G4Random::setTheEngine(randomEngine);
    G4Random::setTheSeed(e2());

    //Construct the default run manager
#ifdef G4MULTITHREADED
    //G4RunManager* runManager = new G4RunManager;
    G4MTRunManager *runManager = new G4MTRunManager;
    //G4MTRunManager* runManager = new CustomMTRunManager;
    G4int cores = G4Threading::G4GetNumberOfCores();
    runManager->SetNumberOfThreads(cores);
#else
    G4RunManager* runManager = new G4RunManager;
#endif

//...continue with file } }

 Add Message Add Message
to: "Re: Setting RNG Seeds in MT main() not working"

 Subscribe Subscribe

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