Message: 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

Question Data file is re-written by all the threads in RunAction 

Forum: Multithreading
Date: 23 Aug, 2018
From: Abhijit Bhattacharyya <Abhijit Bhattacharyya>

In the EndOfRunAction(), I want to save some some variables like "protonFlux", "neutronFlux" etc for which I have written snippets like:

void NeutRunAction::EndOfRunAction(const G4Run* aRun) {
  ...
  G4int evtNum = aRun->GetNumberOfEvent();
  std::ofstream trackout("trackData.dat", std::ios:out);

  const NeutRun* thisRun  =static_cast<const NeutRun*>(aRun);
  trackout << "Leaking flux / event: " << thisRun->GetNeutLeakingFlux() / evtNum << G4endl;
  trackout << "Proton Flux / event: " << thisRun->fProton_Flux / evtNum << G4endl;
  trackout.close()
...
...
}

First thing is that, evtNum is not returning any number while run shows all the events processed. Secondly I see that for 4 threads in my laptop, the file is being written by all local threads. If I put the storing in if (IsMaster()) then evtNum becomes a garbage.

How may I tackle this issue? Thank You

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

1 Feedback: Re: Data file is re-written by all the threads in RunAction   (Jonathan Madsen - 23 Aug, 2018)
(_ Feedback: Re: Data file is re-written by all the threads in RunAction   (Abhijit Bhattacharyya - 24 Aug, 2018)
(_ Feedback: Re: Data file is re-written by all the threads in RunAction   (Jonathan Madsen - 24 Aug, 2018)
(_ Agree: Re: Data file is re-written by all the threads in RunAction   (Abhijit Bhattacharyya - 27 Aug, 2018)
 Add Message Add Message
to: "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