Message: Re: Data file is re-written by all the threads in RunAction Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: Data file is re-written by all the threads in RunAction 

Forum: Multithreading
Re: Question Data file is re-written by all the threads in RunAction (Abhijit Bhattacharyya)
Re: Feedback Re: Data file is re-written by all the threads in RunAction (Jonathan Madsen)
Re: Feedback Re: Data file is re-written by all the threads in RunAction (Abhijit Bhattacharyya)
Date: 24 Aug, 2018
From: Jonathan Madsen <Jonathan Madsen>

Assuming you want the data combined from all the threads, then you want to save inside

if(IsMaster()) { save here }

The reason I commented about number of events is because you said that number was junk but correct when IsMaster() was false. Within the master, the number of events should add up to the sum of number of events each thread processed. EndOfRunAction on the master thread will be called after all the non-master threads have invoked EndOfRunAction but the non-master threads will invoke EndOfRunAction in a non-deterministic order and will often invoke this method concurrently so if you are doing file operations on non-master threads, you need to either guard the entire file operation with a G4Mutex (and append the file instead of clobbering) or have each thread write to a unique file/filename.

On Fri, 24 Aug 2018 08:15:03 GMT, Abhijit Bhattacharyya wrote:

> Hi!
> 
> Thanks.
> 
> I already have both NeutRun::RecordEvent() and NeutRun::Merge(). The
> question is whether shall I save inside if(ISMaster()){...} loop or
> outside it within NeutRunAction::EndOfRunAction().
> 
> Best
> 
> Abhijit
> 
> On Fri, 24 Aug 2018 02:09:28 GMT, Jonathan Madsen wrote:
> 
> > If your derived NeutRun on the master thread does not have the correct
> > number of events set, you are probably failing to call
> > G4Run::Merge(const G4Run*) in NeutRun::Merge(const G4Run*)
> > 
> >   void NeutRun::Merge(const G4Run* aRun)
> >   {
> >       // include this function call
> >       G4Run::Merge(aRun);
> > 
> >       // do the rest of the merge
> >       fNeutron_Leak += aRun->GetNeutLeakingFlux();
> >       fProton_Flux += aRun->fProton_Flux;
> >   }
> > 
> 

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

1 Agree: Re: Data file is re-written by all the threads in RunAction   (Abhijit Bhattacharyya - 27 Aug, 2018)
 Add Message Add Message
to: "Re: Data file is re-written by all the threads in RunAction"

 Subscribe Subscribe

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