Problem 2501

Summary: Concurrency issues with getenv calls in ParticleHP on Visual Studio
Product: Geant4 Reporter: Sergio Losilla <sergio.losilla>
Component: processes/hadronic/models/neutron_hpAssignee: dennis.herbert.wright
Status: RESOLVED FIXED    
Severity: normal    
Priority: P4    
Version: 11.0   
Hardware: All   
OS: All   

Description Sergio Losilla 2022-07-21 14:04:56 CEST
Applications using ParticleHP built on Visual Studio 2022 suffer a significant slowdown when running on 64 threads.

The culprit seems to be the numerous calls to std::getenv. The Visual C++ standard library implementation of std::getenv seems to be thread-safe, and the locks cause a very noticeable slowdown on a larger number of cores.

The main culprits seem to be:
* G4PHPTEST2, read eg in G4ParticleHPContAngularPar::BuildByInterpolation (source\processes\hadronic\models\particle_hp\src\G4ParticleHPContAngularPar.cc, line 874)
* G4PHPTEST, read eg in G4ParticleHPEnAngCorrelation::Sample (source\processes\hadronic\models\particle_hp\src\G4ParticleHPEnAngCorrelation.cc, line 143)
* NeutronHPCapture, read eg in G4ParticleHPCapture::ApplyYourself (source\processes\hadronic\models\particle_hp\src\G4ParticleHPCapture.cc, line 103)

The profiles I have run are not the most reproducible (I am using a virtual machine...) and this issue needs to be investigated further.
Comment 1 dennis.herbert.wright 2022-09-16 19:22:57 CEST
This is a known problem for ParticleHP and we are in the process of getting rid of as many getenvs as we can.   I'll have a look at the ones you list and see if they can be removed or replaced.
Comment 2 dennis.herbert.wright 2022-10-07 22:55:33 CEST
Environment variables G4PHPTEST, G4PHPTEST2, NeutronHPCapture and their corresponding getenv()s were no longer used, so they have been removed.