File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
src/core/execution_context Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -140,15 +140,26 @@ void InPlaceExecutionContext::TearDownIterationAll(
140140}
141141
142142void InPlaceExecutionContext::SetupAgentOpsAll (
143- const std::vector<ExecutionContext*>& all_exec_ctxts) {}
143+ const std::vector<ExecutionContext*>& all_exec_ctxts) {
144+ auto * sim = Simulation::GetActive ();
145+ auto * env = sim->GetEnvironment ();
146+ auto * param = sim->GetParam ();
147+ for (auto * ec : all_exec_ctxts) {
148+ auto * ctxt = bdm_static_cast<InPlaceExecutionContext*>(ec);
149+ ctxt->cached_env_ = env;
150+ ctxt->cached_param_ = param;
151+ }
152+ }
144153
145154void InPlaceExecutionContext::TearDownAgentOpsAll (
146155 const std::vector<ExecutionContext*>& all_exec_ctxts) {}
147156
148157void InPlaceExecutionContext::Execute (
149158 Agent* agent, AgentHandle ah, const std::vector<Operation*>& operations) {
150- auto * env = Simulation::GetActive ()->GetEnvironment ();
151- auto * param = Simulation::GetActive ()->GetParam ();
159+ auto * env =
160+ cached_env_ ? cached_env_ : Simulation::GetActive ()->GetEnvironment ();
161+ auto * param =
162+ cached_param_ ? cached_param_ : Simulation::GetActive ()->GetParam ();
152163
153164 if (param->thread_safety_mechanism ==
154165 Param::ThreadSafetyMechanism::kUserSpecified ) {
Original file line number Diff line number Diff line change 3434
3535namespace bdm {
3636
37+ class Environment ;
38+ struct Param ;
39+
3740namespace in_place_exec_ctxt_detail {
3841class InPlaceExecutionContext_NeighborCacheValidity_Test ;
3942}
@@ -157,6 +160,11 @@ class InPlaceExecutionContext : public ExecutionContext {
157160 // / Cache the value of Param::cache_neighbors
158161 bool cache_neighbors_ = false ;
159162
163+ // / Cached pointers refreshed once per agent-ops phase in SetupAgentOpsAll,
164+ // / so Execute avoids per-agent Simulation::GetActive() lookups.
165+ Environment* cached_env_ = nullptr ;
166+ const Param* cached_param_ = nullptr ;
167+
160168 // / Check whether or not the neighbors in `neighbor_cache_` were queried with
161169 // / the same squared radius (`cached_squared_search_radius_`) as currently
162170 // / being queried with (`query_squared_radius_`)
You can’t perform that action at this time.
0 commit comments