Message: Re: Get intital particle energy in master thread Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Get intital particle energy in master thread 

Forum: Multithreading
Re: Question Get intital particle energy in master thread (William Donahue)
Date: 05 Jul, 2014
From: Andrea Dotti <Andrea Dotti>

Hello, the most correct way to do that is to extend G4Run class, however it is also true that other solutions exist.. For example, consider modifying your PrimaryGeneratorAction class like this:

PrimaryGeneratorAction.hh:

class PrimaryGenrartorAction : public G4VUserPrimaryGeneratorAction {
[...]
 public: 
     static G4double GetPrimaryEne();
     static void SetPrimaryEne( G4double val );
private:
    static G4double ene;   
};  

PrimaryGeneratorAction.cc:

#include "G4AutoLock.hh"
G4double PrimaryGeneratorAction::ene = 0;
namespace {
   G4Mutex aMutex=G4MUTEX_INITIALIZER;
}

void PrimaryGeneratorAction::SetPrimaryEne( G4double val ) { 
    G4AutoLock l(&aMutes);
    ene = val;
}

void PrimaryGeneratorAction::GetPrimaryEne() {
   G4Autolock l(&aMutex);
   return ene;
}

Call SetPrimaryEne from worker threads and the master thread can do a direct call to the static function to get the energy:

masterThread:
{
   [...]
   G4double ene = G4PrimaryGeneratorAction::GetPrimaryEne();
}

As I said this is not very elegant, but for a very simple use case like yours it is probably the easy solution.

Note that: 1- All threads needs to use the same energy for primaries, to have correct behavior 2- It is important that firsts threads setup the correct value for "ene" and only after that the master thread gets the value back

Andrea

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

1 Question: Re: Get intital particle energy in master thread   (William Donahue - 05 Jul, 2014)
(_ Feedback: Re: Get intital particle energy in master thread   (Andrea Dotti - 05 Jul, 2014)
(_ None: Re: Get intital particle energy in master thread   (William Donahue - 17 Dec, 2014)
 Add Message Add Message
to: "Re: Get intital particle energy in master thread"

 Subscribe Subscribe

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