Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/core/execution_context/in_place_exec_ctxt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,26 @@ void InPlaceExecutionContext::TearDownIterationAll(
}

void InPlaceExecutionContext::SetupAgentOpsAll(
const std::vector<ExecutionContext*>& all_exec_ctxts) {}
const std::vector<ExecutionContext*>& all_exec_ctxts) {
auto* sim = Simulation::GetActive();
auto* env = sim->GetEnvironment();
auto* param = sim->GetParam();
for (auto* ec : all_exec_ctxts) {
auto* ctxt = bdm_static_cast<InPlaceExecutionContext*>(ec);
ctxt->cached_env_ = env;
ctxt->cached_param_ = param;
}
}

void InPlaceExecutionContext::TearDownAgentOpsAll(
const std::vector<ExecutionContext*>& all_exec_ctxts) {}

void InPlaceExecutionContext::Execute(
Agent* agent, AgentHandle ah, const std::vector<Operation*>& operations) {
auto* env = Simulation::GetActive()->GetEnvironment();
auto* param = Simulation::GetActive()->GetParam();
auto* env =
cached_env_ ? cached_env_ : Simulation::GetActive()->GetEnvironment();
auto* param =
cached_param_ ? cached_param_ : Simulation::GetActive()->GetParam();

if (param->thread_safety_mechanism ==
Param::ThreadSafetyMechanism::kUserSpecified) {
Expand Down
8 changes: 8 additions & 0 deletions src/core/execution_context/in_place_exec_ctxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

namespace bdm {

class Environment;
struct Param;

namespace in_place_exec_ctxt_detail {
class InPlaceExecutionContext_NeighborCacheValidity_Test;
}
Expand Down Expand Up @@ -157,6 +160,11 @@ class InPlaceExecutionContext : public ExecutionContext {
/// Cache the value of Param::cache_neighbors
bool cache_neighbors_ = false;

/// Cached pointers refreshed once per agent-ops phase in SetupAgentOpsAll,
/// so Execute avoids per-agent Simulation::GetActive() lookups.
Environment* cached_env_ = nullptr;
const Param* cached_param_ = nullptr;

/// Check whether or not the neighbors in `neighbor_cache_` were queried with
/// the same squared radius (`cached_squared_search_radius_`) as currently
/// being queried with (`query_squared_radius_`)
Expand Down
Loading