| Summary: | HepRotation::rotateAxes: bad axis vectors when running multiple threads | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | davidl |
| Component: | geometry/divisions | Assignee: | Pedro.Arce |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | normal | CC: | Gabriele.Cosmo, richard.t.jones |
| Priority: | P5 | ||
| Version: | 10.1 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: | Patched 'divisions' module to be applied on top of 10.1.p02 | ||
I am seeing this error as well. I believe that it is related to the patch applied to G4VDivisionParameterisation.cc in release 4.10.01.p02. That patch gets rid of the double-delete fault that was caused by the original code, but it does not solve the root problem that underlies it. I think the root problem is that G4VDivisionParameterisation needs to have thread-local allocation for its member fRotMatrix. In the p02 release code, that member is shared between all threads for a single division volume. BUT it is being dynamically updated during the tracking. Each thread is dynamically updating the shared copy, and eventually the threads collide. This is inevitable, and I have verified it is actually happening using gdb with multiple threads running. Just so I can move on, I am modifying a private copy of G4VDivisionParameterisation to make it fetch fRotMatrix from the thread-local data member frot in the underlying G4PVDivision object instead of trying to create and modify its own (shared) fRotMatrix. I then add a loop inside my ConstructSDandField to call SetRotation(new G4RotationMatrix) on all G4PVDivision objects iff we are running in a worker thread. That way each thread has its own fRotMatrix to work with, and there will be no memleak or double-free at the end because the master thread objects have been unchanged. I know this is a kludge, but it gets me going. This bug should really be fixed in a more satisfactory way, but at least this solves the problem for me. Hi David, Richard,
can you try and see if this implementation of ChangeRotMatrix() in G4VDivisionParameterisation works?
void
G4VDivisionParameterisation::
ChangeRotMatrix( G4VPhysicalVolume *physVol, G4double rotZ ) const
{
static G4ThreadLocal G4RotationMatrix* rm = 0;
rm = new G4RotationMatrix();
rm->rotateZ( rotZ );
delete physVol->GetRotation();
physVol->SetRotation(rm);
}
Thanks,
Gabriele
Created attachment 359 [details]
Patched 'divisions' module to be applied on top of 10.1.p02
Attached refined fix to be included in next patch-release.
Attached patch to be applied on top of 10.1.p02. *** This problem has been marked as a duplicate of problem 1743 *** |
I am using geant4.10.01.p01 built with multi-threading support but modified using the G4VDivisionParameterisation header and implementation files that are attached to bug report 1743 (these were attached by Pedro as the fix to the bug). That modification does allow the program to run without crashing when using more than one thread. However, if I use more than 1 thread the following message is printed quite often (it does not print this message when running with only 1 thread): HepRotation::rotateAxes: bad axis vectors This is coming from source/externals/clhep/src/Rotation.cc. I temporarily modified this to throw an exception right after printing the message so that I could get a stack trace which I've copied below. Below that is the output from gdb's "info threads" in case it helps to see where the other threads are. I have tested this on both Mac OS X 10.9 and Linux CentOS 6.5 and both give the same behavior. The traces below are from Linux. =============== Stack Trace ================ (gdb) bt #0 0x0000003624a32625 in raise () from /lib64/libc.so.6 #1 0x0000003624a33e05 in abort () from /lib64/libc.so.6 #2 0x00000036292bea5d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib64/libstdc++.so.6 #3 0x00000036292bcbe6 in ?? () from /usr/lib64/libstdc++.so.6 #4 0x00000036292bcc13 in std::terminate() () from /usr/lib64/libstdc++.so.6 #5 0x00000036292bcd0e in __cxa_throw () from /usr/lib64/libstdc++.so.6 #6 0x00007fdc4beb5ef1 in CLHEP::HepRotation::rotateAxes (this=<value optimized out>, newX=<value optimized out>, newY=<value optimized out>, newZ=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/externals/clhep/src/Rotation.cc:122 #7 0x00007fdc4cf28cc6 in NetRotation (this=0x7fdc30509318, history=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/geometry/management/include/G4AffineTransform.icc:368 #8 G4TouchableHistory::G4TouchableHistory (this=0x7fdc30509318, history=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/geometry/volumes/src/G4TouchableHistory.cc:52 #9 0x00007fdc4e8951f1 in CreateTouchableHistory (this=0x7fdc30163b10, track=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/geometry/navigation/include/G4Navigator.icc:266 #10 LocateGlobalPointAndUpdateTouchableHandle (this=0x7fdc30163b10, track=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/geometry/navigation/include/G4Navigator.icc:297 #11 G4Transportation::PostStepDoIt (this=0x7fdc30163b10, track=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/processes/transportation/src/G4Transportation.cc:673 #12 0x00007fdc4f2c902b in G4SteppingManager::InvokePSDIP (this=0x7fdc3006b7e0, np=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/tracking/src/G4SteppingManager2.cc:530 #13 0x00007fdc4f2c943d in G4SteppingManager::InvokePostStepDoItProcs (this=0x7fdc3006b7e0) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/tracking/src/G4SteppingManager2.cc:502 #14 0x00007fdc4f2c72b5 in G4SteppingManager::Stepping (this=0x7fdc3006b7e0) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/tracking/src/G4SteppingManager.cc:209 #15 0x00007fdc4f2cfd9c in G4TrackingManager::ProcessOneTrack (this=0x7fdc3006b7a0, apValueG4Track=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/tracking/src/G4TrackingManager.cc:126 #16 0x00007fdc4f501cce in G4EventManager::DoProcessing (this=0x7fdc3006b710, anEvent=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/event/src/G4EventManager.cc:185 #17 0x00007fdc4f7861dc in G4WorkerRunManager::ProcessOneEvent (this=0x7fdc3006b510, i_event=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/run/src/G4WorkerRunManager.cc:251 #18 0x00007fdc4f786849 in G4WorkerRunManager::DoEventLoop (this=0x7fdc3006b510, n_event=<value optimized out>, macroFile=0x0, n_select=-1) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/run/src/G4WorkerRunManager.cc:229 #19 0x00007fdc4f77ccac in G4RunManager::BeamOn (this=0x7fdc3006b510, n_event=1000, macroFile=0x0, n_select=-1) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/run/src/G4RunManager.cc:273 #20 0x00007fdc4f78ecb0 in G4MTRunManagerKernel::StartThread (context=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/run/src/G4MTRunManagerKernel.cc:249 #21 0x00000036256079d1 in start_thread () from /lib64/libpthread.so.0 #22 0x0000003624ae88fd in clone () from /lib64/libc.so.6 ======== Thread Info ========== (gdb) info threads 11 Thread 0x7fdc22ffe700 (LWP 42182) operator= (this=0x7fdc183a7980, bullet=<value optimized out>, target=0x7fdc183a6918, output=...) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/externals/clhep/include/CLHEP/Vector/ThreeVector.icc:129 10 Thread 0x7fdc23fff700 (LWP 42181) 0x000000362560e264 in __lll_lock_wait () from /lib64/libpthread.so.0 9 Thread 0x7fdc3dffd700 (LWP 42180) CLHEP::HepLorentzVector::boost (this=0x7fdc3df93a60, bx=<value optimized out>, by=<value optimized out>, bz=<value optimized out>) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/externals/clhep/src/LorentzVector.cc:65 8 Thread 0x7fdc3effe700 (LWP 42179) 0x0000003624a7831f in _int_free () from /lib64/libc.so.6 7 Thread 0x7fdc459ae700 (LWP 42178) 0x000000362560e264 in __lll_lock_wait () from /lib64/libpthread.so.0 * 6 Thread 0x7fdc469af700 (LWP 42177) 0x0000003624a32625 in raise () from /lib64/libc.so.6 5 Thread 0x7fdc3ffff700 (LWP 42176) 0x00007fdc4e356dde in m2 (this=0x7fdc2c3941e8) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/externals/clhep/include/CLHEP/Vector/LorentzVector.icc:154 4 Thread 0x7fdc479b0700 (LWP 42175) 0x000000362560e264 in __lll_lock_wait () from /lib64/libpthread.so.0 3 Thread 0x7fdc489b1700 (LWP 42174) 0x000000362560e75d in read () from /lib64/libpthread.so.0 2 Thread 0x7fdc4a632700 (LWP 42173) 0x00007fdc4e26e30e in G4ChipsProtonElasticXS::GetTabValues ( this=0x7fdc402c3000, lp=1.2465928376848317e-28, PDG=<value optimized out>, tgZ=<value optimized out>, tgN=10) at /group/halld/Software/ExternalPackages/GEANT4/geant4.10.01.p01/source/processes/hadronic/cross_sections/src/G4ChipsProtonElasticXS.cc:822 1 Thread 0x7fdc4b198180 (LWP 41961) 0x000000362560b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0