Hello all,
I am running into an issue with multithreading and data storing. In particular, I was getting an error from my analysis class’ FillData function, specifically with lines like
SDman->GetCollectionID("correct collection name"))
First off, and probably most importantly, sometimes when I first run my executable, I get a segmentation error and/or double-free. When I re-enter the command, my run starts and errors eventually follow.
The errors include segmentation errors and lines like G4WT5 > < BCDHitsCollection> is not found across all my HitsCollections. Some threads don’t get this issue, others do. The segmentation errors eventually crash my run.
For example, Thread 4 will output these lines and then continue on with the rest of the FillData function, whereas Thread 10 will successfully find all collections. Shortly after, I will get a segmentation error, but with all threads outputting at the same time, it is hard for me to pinpoint what the cause is.
G4WT4 > Starting SDman->GetCollectionIDs
G4WT4 > <SCDHitsCollection> is not found.
G4WT4 > <TCDHitsCollection> is not found.
G4WT4 > <CalHitsCollection> is not found.
G4WT4 > <WHitsCollection> is not found.
G4WT4 > <NDHitsCollection> is not found.
G4WT4 > [SCD, TCD, BCD, CAL, W, ND] [-1, -1, 0, -1, -1, -1]
G4WT4 > FILLING PRIMARY NTUPLE…
G4WT10 > Starting SDman->GetCollectionIDs
G4WT10 > [SCD, TCD, BCD, CAL, W, ND] [4, 0, 1, 2, 3, 5]
G4WT10 > FILLING PRIMARY NTUPLE…
*Other threads also output, I just omitted them for readability.
Another interesting thing I noticed when I upped my verbosity was this output:
G4WT8 > In CALSD::ProcessHits()
G4WT9 > In CALSD::ProcessHits()
G4WT2 > In CALSD::ProcessHits()
… for over 100 lines in a row…
G4WT3 > In CALSD::ProcessHits()
G4WT6 > In CALSD::ProcessHits()
G4WT4 > In CALSD::ProcessHits()
G4WT8 > In CALSD::ProcessHits()
G4WT0 > In CALSD::ProcessHits()
… with the occasional…
G4WT1 > MyHit::MyHit():pLogV()
G4WT9 > In CALSD::ProcessHits()
… and on and on…
I have an idea that it may come from my calorimeter class, namely with the private variable
private:
int* CellID;
This variable is instantiated in my CALSD constructor,
CellID = new G4int[numberOfCells]; // numberOfCells is a G4int parameter
and later used in lines
if(CellID[copyID]==-1)
,
CellID[copyID] = (G4int) aHitCollection->insert( aHit ) - 1;
,
and MyHit* aHit = (*aHitCollection)[CellID[copyID]];
My worry is that this array used in my calorimeter is not thread-local, causing errors when multiple threads access it.
Any help would be appreciated, and I hope my message is detailed enough!
Thank you all very much,
Shivom
Geant4 Version: v11.3
Operating System: Linux