Skip to content

Commit

Permalink
Use a thread-local volume cache rather than atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
amadio committed Oct 16, 2019
1 parent 6d4970c commit 510a62d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 0 additions & 2 deletions MagneticField/VolumeBasedEngine/interface/MagGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class MagGeometry {

bool inBarrel(float R, float Z) const;

mutable std::atomic<MagVolume const*> lastVolume; // Cache last volume found

std::vector<MagBLayer const*> theBLayers;
std::vector<MagESector const*> theESectors;

Expand Down
16 changes: 7 additions & 9 deletions MagneticField/VolumeBasedEngine/src/MagGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ MagGeometry::MagGeometry(int geomVersion,
const std::vector<MagESector const*>& tes,
const std::vector<MagVolume6Faces const*>& tbv,
const std::vector<MagVolume6Faces const*>& tev)
: lastVolume(nullptr),
theBLayers(tbl),
: theBLayers(tbl),
theESectors(tes),
theBVolumes(tbv),
theEVolumes(tev),
Expand Down Expand Up @@ -177,13 +176,12 @@ MagVolume const* MagGeometry::findVolume1(const GlobalPoint& gp, double toleranc

// Use hierarchical structure for fast lookup.
MagVolume const* MagGeometry::findVolume(const GlobalPoint& gp, double tolerance) const {
// Check volume cache
auto lastVolumeCheck = lastVolume.load(std::memory_order_acquire);
if (lastVolumeCheck != nullptr && lastVolumeCheck->inside(gp)) {
return lastVolumeCheck;
}
static thread_local MagVolume const* lastVolume = nullptr;

MagVolume const* result = lastVolume;

MagVolume const* result = nullptr;
if (result && result->inside(gp))
return result;

float R = gp.perp();
float Z = fabs(gp.z());
Expand Down Expand Up @@ -225,7 +223,7 @@ MagVolume const* MagGeometry::findVolume(const GlobalPoint& gp, double tolerance
}

if (cacheLastVolume)
lastVolume.store(result, std::memory_order_release);
lastVolume = result;

return result;
}
Expand Down

0 comments on commit 510a62d

Please sign in to comment.