MultiThread shut down;

When I run with multiple threads, the program does not print out the information I set in the master thread, but runs directly to the end. This is my runaction.cc code

#include "RunAction.hh"
#include "PrimaryGeneratorAction.hh"
#include "DetectorConstruction.hh"
#include "DetectorConfig.hh"

#include "G4Run.hh"
#include "G4UnitsTable.hh"
#include "G4RunManager.hh"
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm> 

RunAction::RunAction(){

    G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();

    for (auto& accum : fTargetBinEdep){
        accumulableManager->RegisterAccumulable(accum);
    }
}

RunAction::~RunAction() {

}

void RunAction::BeginOfRunAction(const G4Run* run) {

    G4cout<<"run start"<<G4endl;
       
        G4RunManager::GetRunManager()->SetRandomNumberStore(false);
        G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
        accumulableManager->Reset();
    }


void RunAction::EndOfRunAction(const G4Run* run) {
  
    G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->Merge();
if (IsMaster()) {
G4cout<<"end of global run"<<G4endl;
}
   else {
G4cout<<"end fo local sum"<<G4endl;
}

}

And this is definition of fTargetBinEdep in the header file.


     static  const G4int fNbins = 19;   
    std::vector<G4Accumulable<G4double>> fTargetBinEdep = std::vector<G4Accumulable<G4double>>(fNbins, 0.0f); 

I’m not really clear on what output you’re actually getting versus what you expect to see. Could you clarify please?

In short, I divide a volume into some grids, store the energy deposition in each grid as B1, and finally output the grid data to a .txt file. The code I gave doesn 't contain the part of the output file;
The problem is ,even if the runaction contains only the code I gave, there is still a probability that the program will exit directly when multithreading runs, which is, it will not print ”end of global run”

The master thread in MT mode is not assigned any events to process. It delegates that to the workers and aggregates the results from the workers at the end. You should not expect it to process any events itself.

In short, I divide a volume into some grids, store the energy deposition in each grid as B1, and finally output the grid data to a .txt file. The code I gave doesn 't contain the part of the output file;
The problem is ,even if the runaction contains only the code I gave, there is still a probability that the program will exit directly when multithreading runs, which is, it will not print ”end of global run”

I understand that,but even if i don’t process any vibration in master thread as the code i put ,it still shut down