I’m running a simple Geant4 simulation to look at gamma rays from
targets illuminated by neutrons. The geometry is simple with a
monoenergetic general particle source, a block target of material a
distance away embedded in an air half space and a detector. Data is
collected when a gamma ray intersects the detector volume. Within
SteppingAction, I open a ROOT file and store various properties of the
gamma in it and then close the file. I have been using it in single
thread mode for a long time and it generates good results. I recently
recompiled Geant4 in multithreading mode and I decided to modify the
program to run in multithreaded mode. I had to modify the file
open/write/close by opening a separate file for each thread and adding a
mutex lock for the file open/write/close part. The rest of the changes
were straightforward (e.g., add an ActionInitialization module). Now
when I run it in multithreaded mode, my memory usage starts to rise
exponentially and freezes my computer if I do not terminate it. This
happens for a single user thread or multiple user threads. If I comment
out the line in main(0)
G4MTRunManager * runManager = new G4MTRunManager;
and replace it with
G4RunManager * runManager = new G4RunManager;
the memory problem does not happen.
I have already gone through my code ensuring that "new"s and "delete"s
are paired and I have run the program valgrind (which helps find memory
leaks) but it did not provide any useful information (to me at least). I
have run another program (not mine) which has this memory problem but I
have also run Geant4 code in multithreaded mode without this problem
occurring. I am running Geant4 10.5 patch 01 on an i7 PC with 16GB RAM
and 64bit Linux (Fedora 28).
I have not posted the code since there is a lot of it and I am not
asking anyone to debug my code. But if there are
obvious parts that should be posted, I will do so. However, I was
wondering if there are any obvious known areas where these kinds of
memory leaks/runaways occur in migrating code to multithreaded mode.
Any help is gratefully appreciated. Thanks.