Multithreading application hangs

Dear Geant4 experts and users,

I am writing a simulation code to calculate the patient dose based on the DICOM example in Geant4. So I creat the voxelized phantom using the nested parameterised volume. The compiling is OK. In order to obtain the total patient dose from multiple irradiation settings, I run the code in a batch mode, so I basically I write a simple bash script to run the code many times with different argument. However, I always find a weird problem that sometimes the code hangs there and nothing moves. This is not happening for every simulation in the batch run, but every a few of them may have that hanging issue.

I googled this online, and I found a similar forum post in the old hypernew forum talking about the similar problem( In that post Andrea said it may be related to the multithreading issue for the nest parameterised geometry. There was not final solution posted for the old forum thread. But I want to know that does anyone encounters this similar problem? If so, how do you handle this problem?

Thank you very much.


It has been many days since you asked this.

I had a similar problem when I did not check properly for overlapping geometries in my detector construction. I think the run might hang every time there is a hit in the overlapping volume.

Since the overlap is possibly small (if not you would have noticed it by simple visualisation) and possibly does not occur in all detector parameterisations, the random hangs happen in those random cases when a hit happens in the overlapping volume.

Removing the overlap helped me fix this problem. Hopefully, it helps you too.

Hi nirmaliyer, thank you very much for replying my post. I did find the reason why it hangs. It turns out it is related to the multithreading issue. In my old design, I created a global static map to store the dose information for each voxel created from DICOM images. It seems that for the global variable, we must use G4Mutex to handle the race issue in multithreading mode. So after I handle this, the code goes well, and never hangs anymore.