Message: gross inefficiency in examples/extended/field/field04 Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Warning gross inefficiency in examples/extended/field/field04 

Forum: Documentation and Examples
Date: 30 Jul, 2010
From: Tom Roberts <Tom Roberts>

In UserSteppingAction() the code does:

    if (thePrePVname  != "TestPlane" &&
          thePostPVname == "TestPlane") { ... }

This is grossly inefficient, as it performs two G4String constructors and two string comparisons at every step for every track. It is MUCH better to keep the physical volume pointers and compare pointers rather than comparing names. Then one does this:

    if(thePostPV == pvTestPlane && thePrePV != pvTestPlane) { ... }

Note that inverting the order also improves efficiency (but for pointers it is negligible as they are essentially single-instruction compares).

There may be some cases for which physical-volume pointers are not easily available, or there are a lot of them with the same name. In the latter case I construct a std::set<G4VPhysicalVolume*> in advance.

In general, one should take care to not perform any string operations while tracking. I once sped a simulation up by a factor of 20 by eliminating one inadvertent strtol() in UserSteppingAction().

This probably occurs in other examples; I have not looked.

 Add Message Add Message
to: "gross inefficiency in examples/extended/field/field04"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]