Skip to content

Commit

Permalink
Allocate SimpleCalo storage at construction time
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Nov 22, 2023
1 parent bf5c61b commit 52fe67f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 32 deletions.
34 changes: 4 additions & 30 deletions src/accel/GeantSimpleCalo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
//---------------------------------------------------------------------------//
#include "GeantSimpleCalo.hh"

#include <mutex>

#include "corecel/cont/Range.hh"
#include "corecel/io/Logger.hh"
#include "celeritas/ext/GeantGeoParams.hh"
Expand Down Expand Up @@ -83,6 +81,10 @@ GeantSimpleCalo::GeantSimpleCalo(std::string name,
<< this->label() << "'");
}

// Resize data
storage_->num_threads = params_->num_streams();
storage_->data.resize(storage_->num_threads);

CELER_ENSURE(!storage_->name.empty());
CELER_ENSURE(storage_->volume_to_index.size() == volumes_.size());
}
Expand All @@ -93,8 +95,6 @@ GeantSimpleCalo::GeantSimpleCalo(std::string name,
*/
auto GeantSimpleCalo::MakeSensitiveDetector() -> UPSensitiveDetector
{
this->setup_storage();

UPSensitiveDetector detector;

// Get thread ID
Expand Down Expand Up @@ -218,31 +218,5 @@ void GeantSimpleCalo::output(JsonPimpl* j) const
#endif
}

//---------------------------------------------------------------------------//
/*!
* Allocate storage space for all threads.
*/
void GeantSimpleCalo::setup_storage()
{
if (storage_->num_threads == 0)
{
// Lock and check again
static std::mutex setup_mutex;
std::lock_guard scoped_lock{setup_mutex};
if (storage_->num_threads == 0)
{
// Resize data
storage_->num_threads = params_->num_streams();
storage_->data.resize(storage_->num_threads);

CELER_LOG_LOCAL(debug) << "Resized storage for '" << storage_->name
<< "' to " << storage_->num_threads;
}
}

CELER_ENSURE(storage_->num_threads != 0);
CELER_ENSURE(storage_->data.size() == storage_->num_threads);
}

//---------------------------------------------------------------------------//
} // namespace celeritas
2 changes: 0 additions & 2 deletions src/accel/GeantSimpleCalo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ class GeantSimpleCalo final : public OutputInterface
SPConstParams params_;
VecLV volumes_;
SPStorage storage_;

void setup_storage();
};

//---------------------------------------------------------------------------//
Expand Down

0 comments on commit 52fe67f

Please sign in to comment.