BioDynaMo  v1.05.120-25dc9790
simulation.cc
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #include "core/simulation.h"
16 
17 #include <cpptoml/cpptoml.h>
18 #include <omp.h>
19 #include <algorithm>
20 #include <cmath>
21 #include <cstdlib>
22 #include <filesystem>
23 #include <fstream>
24 #include <memory>
25 #include <ostream>
26 #include <sstream>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include "bdm_version.h"
39 #include "core/gpu/gpu_helper.h"
41 #include "core/param/param.h"
42 #include "core/resource_manager.h"
43 #include "core/scheduler.h"
44 #include "core/util/filesystem.h"
45 #include "core/util/io.h"
46 #include "core/util/log.h"
47 #include "core/util/string.h"
48 #include "core/util/thread_info.h"
49 #include "core/util/timing.h"
51 #include "memory_usage.h"
52 #ifdef USE_LIBGIT2
53 #include "core/util/git_tracker.h"
54 #endif // USE_LIBGIT2
55 
56 #include <TEnv.h>
57 #include <TROOT.h>
58 
59 namespace bdm {
60 
63 
64 std::atomic<uint64_t> Simulation::counter_;
65 
66 Simulation* Simulation::active_ = nullptr;
67 
69 
70 Simulation::Simulation(TRootIOCtor* p) {}
71 
72 Simulation::Simulation(int argc, const char** argv,
73  const std::vector<std::string>& config_files)
74  : Simulation(
75  argc, argv, [](auto* param) {}, config_files) {}
76 
77 Simulation::Simulation(const std::string& simulation_name,
78  const std::vector<std::string>& config_files)
79  : Simulation(
80  simulation_name, [](auto* param) {}, config_files) {}
81 
83  const std::vector<std::string>& config_files) {
84  Initialize(
85  clo, [](auto* param) {}, config_files);
86 }
87 
89  const std::function<void(Param*)>& set_param,
90  const std::vector<std::string>& config_files) {
91  Initialize(clo, set_param, config_files);
92 }
93 
94 Simulation::Simulation(int argc, const char** argv,
95  const std::function<void(Param*)>& set_param,
96  const std::vector<std::string>& config_files) {
97  auto options = CommandLineOptions(argc, argv);
98  Initialize(&options, set_param, config_files);
99 }
100 
101 Simulation::Simulation(const std::string& simulation_name,
102  const std::function<void(Param*)>& set_param,
103  const std::vector<std::string>& config_files) {
104  const char* argv[1] = {simulation_name.c_str()};
105  auto options = CommandLineOptions(1, argv);
106  Initialize(&options, set_param, config_files);
107 }
108 
109 void Simulation::Restore(Simulation&& restored) {
110  // random_
111  if (random_.size() != restored.random_.size()) {
112  Log::Warning("Simulation", "The restore file (", param_->restore_file,
113  ") was run with a different number of threads. Can't restore "
114  "complete random number generator state.");
115  uint64_t min = std::min(random_.size(), restored.random_.size());
116  for (uint64_t i = 0; i < min; i++) {
117  *(random_[i]) = *(restored.random_[i]);
118  }
119  } else {
120  for (uint64_t i = 0; i < random_.size(); i++) {
121  *(random_[i]) = *(restored.random_[i]);
122  }
123  }
124 
125  // param and rm
126  param_->Restore(std::move(*restored.param_));
127  restored.param_ = nullptr;
128  *rm_ = std::move(*restored.rm_);
129  restored.rm_ = nullptr;
130 
131  *time_series_ = std::move(*restored.time_series_);
132 
133  // name_ and unique_name_
134  InitializeUniqueName(restored.name_);
136 }
137 
138 std::ostream& operator<<(std::ostream& os, Simulation& sim) {
139  os << std::endl;
140 
141  os << "***********************************************" << std::endl;
142  os << "***********************************************" << std::endl;
143  os << "\033[1mSimulation Metadata:\033[0m" << std::endl;
144  os << "***********************************************" << std::endl;
145  os << std::endl;
146  os << "\033[1mGeneral\033[0m" << std::endl;
147  if (sim.command_line_parameter_str_ != "") {
148  os << "Command\t\t\t\t: " << sim.command_line_parameter_str_ << std::endl;
149  }
150  os << "Simulation name\t\t\t: " << sim.GetUniqueName() << std::endl;
151  os << "Total simulation runtime\t: " << (sim.dtor_ts_ - sim.ctor_ts_) << " ms"
152  << std::endl;
153  os << "Peak memory usage (MB)\t\t: " << (getPeakRSS() / 1048576.0)
154  << std::endl;
155  os << "Number of iterations executed\t: "
156  << sim.scheduler_->GetSimulatedSteps() << std::endl;
157  os << "Number of agents\t\t: " << sim.rm_->GetNumAgents() << std::endl;
158 
159  sim.rm_->ForEachDiffusionGrid([&os](auto* dgrid) { dgrid->PrintInfo(os); });
160 
161  os << "Output directory\t\t: " << sim.GetOutputDir() << std::endl;
162  os << " size\t\t\t\t: "
163  << gSystem->GetFromPipe(
164  Concat("du -sh ", sim.GetOutputDir(), " | cut -f1").c_str())
165  << std::endl;
166  os << "BioDynaMo version:\t\t: " << Version::String() << std::endl;
167  os << "BioDynaMo real type:\t\t: " << kRealtName << std::endl;
168  os << std::endl;
169  os << "***********************************************" << std::endl;
170  os << *(sim.scheduler_->GetOpTimes()) << std::endl;
171  os << "***********************************************" << std::endl;
172  os << std::endl;
173  os << "\033[1mThread Info\033[0m" << std::endl;
174  os << *ThreadInfo::GetInstance();
175  os << std::endl;
176  os << "***********************************************" << std::endl;
177  os << std::endl;
178  os << *(sim.rm_);
179  os << std::endl;
180  os << "***********************************************" << std::endl;
181  os << std::endl;
182  os << "\033[1mParameters\033[0m" << std::endl;
183  os << sim.param_->ToJsonString();
184  os << std::endl;
185  os << "***********************************************" << std::endl;
186  os << "***********************************************" << std::endl;
187 
188  return os;
189 }
190 
193 
194  if (param_ != nullptr && param_->statistics) {
195  std::stringstream sstr;
196  sstr << *this << std::endl;
197  std::cout << sstr.str() << std::endl;
198  // write to file
199  std::ofstream ofs(Concat(output_dir_, "/metadata"));
200  ofs << sstr.str() << std::endl;
201  }
202 #ifdef USE_LIBGIT2
203  if (param_ != nullptr && param_->track_git_changes) {
204  GitTracker git_tracker(output_dir_);
205  git_tracker.SaveGitDetails();
206  }
207 #endif // USE_LIBGIT2
208 
209  if (mem_mgr_) {
210  mem_mgr_->SetIgnoreDelete(true);
211  }
212  Simulation* tmp = nullptr;
213  if (active_ != this) {
214  tmp = active_;
215  }
216  active_ = this;
217 
218  delete rm_;
219  delete environment_;
220  delete scheduler_;
221  if (agent_uid_generator_ != nullptr) {
222  delete agent_uid_generator_;
223  }
224  delete param_;
225  for (auto* r : random_) {
226  delete r;
227  }
228  for (auto* ectxt : exec_ctxt_) {
229  delete ectxt;
230  }
231  if (mem_mgr_) {
232  delete mem_mgr_;
233  }
234  delete ocl_state_;
235  if (time_series_) {
236  delete time_series_;
237  }
238  active_ = tmp;
239 }
240 
241 void Simulation::Activate() { active_ = this; }
242 
245 
247  if (rm != rm_) {
248  delete rm_;
249  }
250  rm_ = rm;
251 }
252 
254 const Param* Simulation::GetParam() const { return param_; }
255 
257  return agent_uid_generator_;
258 }
259 
261 
263 
264 void Simulation::Simulate(uint64_t steps) { scheduler_->Simulate(steps); }
265 
267 Random* Simulation::GetRandom() { return random_[omp_get_thread_num()]; }
268 
269 std::vector<Random*>& Simulation::GetAllRandom() { return random_; }
270 
272  return exec_ctxt_[omp_get_thread_num()];
273 }
274 
275 std::vector<ExecutionContext*>& Simulation::GetAllExecCtxts() {
276  return exec_ctxt_;
277 }
278 
280 
282 const std::string& Simulation::GetUniqueName() const { return unique_name_; }
283 
285 const std::string& Simulation::GetOutputDir() const { return output_dir_; }
286 
288 
290  delete scheduler_;
291  scheduler_ = scheduler;
292 }
293 
295  const std::function<void(Param*)>& set_param,
296  const std::vector<std::string>& config_files) {
297  // Initialize a thread-safe ROOT instance
298  TROOT(name_.c_str(), "BioDynaMo");
299  ROOT::EnableThreadSafety();
300 
302  id_ = counter_++;
303  Activate();
304  if (!clo) {
305  Log::Fatal("Simulation::Initialize",
306  "CommandLineOptions argument was a nullptr!");
307  }
309  InitializeRuntimeParams(clo, set_param, config_files);
312 }
313 
315  if (param_->use_bdm_mem_mgr) {
319  }
321  if (param_->debug_numa) {
322  std::cout << "ThreadInfo:\n" << *ThreadInfo::GetInstance() << std::endl;
323  }
324 
325  random_.resize(omp_get_max_threads());
326 #pragma omp parallel for schedule(static, 1)
327  for (uint64_t i = 0; i < random_.size(); i++) {
328  random_[i] = new Random();
329  random_[i]->SetSeed(param_->random_seed * (i + 1));
330  }
331  exec_ctxt_.resize(omp_get_max_threads());
332  auto map = std::make_shared<
334 #pragma omp parallel for schedule(static, 1)
335  for (uint64_t i = 0; i < exec_ctxt_.size(); i++) {
336  exec_ctxt_[i] = new InPlaceExecutionContext(map);
337  }
338  rm_ = new ResourceManager();
339 
340  // Set the specified neighborhood search method
341  if (param_->environment == "kd_tree") {
343  } else if (param_->environment == "octree") {
345  } else if (param_->environment == "uniform_grid") {
347  } else {
348  Log::Error("Simulation::Initialize", "No such neighboring method '",
349  param_->environment, "'. Defaulting to 'uniform_grid'");
351  }
352  scheduler_ = new Scheduler();
354 }
355 
357  if (environment_ != nullptr && env != environment_) {
358  delete environment_;
359  }
360  environment_ = env;
361 }
362 
364  const std::vector<ExecutionContext*>& exec_ctxts) {
365  if (exec_ctxts.size() != exec_ctxt_.size()) {
366  Log::Error("Simulation::SetAllExecCtxts", "Size of exec_ctxts (",
367  exec_ctxts.size(), ") does not match the expected size (",
368  exec_ctxt_.size(), "). Operation aborted");
369  return;
370  }
371  for (uint64_t i = 0; i < exec_ctxt_.size(); ++i) {
372  auto* ctxt = exec_ctxt_[i];
373  if (ctxt != nullptr && ctxt != exec_ctxts[i]) {
374  delete ctxt;
375  }
376  exec_ctxt_[i] = exec_ctxts[i];
377  }
378 }
379 
381  CommandLineOptions* clo, const std::function<void(Param*)>& set_param,
382  const std::vector<std::string>& ctor_config_files) {
383  // Renew thread info just in case it has been initialised as static and a
384  // simulation calls e.g. `omp_set_num_threads()` within main.
386 
387  std::stringstream sstr;
388  sstr << (*clo);
389  command_line_parameter_str_ = sstr.str();
390 
391  param_ = new Param();
392 
393  // detect if the biodynamo environment has been sourced
394  if (std::getenv("BDMSYS") == nullptr) {
395  Log::Fatal(
396  "Simulation::InitializeRuntimeParams",
397  "The BioDynaMo environment is not set up correctly. Please execute "
398  "'source <path-to-bdm-installation>/bin/thisbdm.sh' and retry this "
399  "command.");
400  }
401 
402  static bool read_env = false;
403  if (!read_env) {
404  // Read, only once, bdm.rootrc to set BioDynaMo-related settings for ROOT
405  std::stringstream os;
406  os << std::getenv("BDMSYS") << "/etc/bdm.rootrc";
407  gEnv->ReadFile(os.str().c_str(), kEnvUser);
408  read_env = true;
409  }
410 
411  // Process `--config` arguments
412  LoadConfigFiles(ctor_config_files,
413  clo->Get<std::vector<std::string>>("config"));
414 
415  // Process `--inline-config` arguments
416  auto inline_configs = clo->Get<std::vector<std::string>>("inline-config");
417  if (inline_configs.size()) {
418  for (auto& inline_config : inline_configs) {
419  param_->MergeJsonPatch(inline_config);
420  }
421  }
422 
423  if (clo->Get<std::string>("backup") != "") {
424  param_->backup_file = clo->Get<std::string>("backup");
425  }
426  if (clo->Get<std::string>("restore") != "") {
427  param_->restore_file = clo->Get<std::string>("restore");
428  }
429 
430  // Handle "cuda" and "opencl" arguments
431  if (clo->Get<bool>("cuda")) {
432  param_->compute_target = "cuda";
433  }
434 
435  if (clo->Get<bool>("opencl")) {
436  param_->compute_target = "opencl";
437  }
438 
439  ocl_state_ = new OpenCLState();
440 
441  if (clo->Get<bool>("visualize")) {
443  param_->visualization_interval = clo->Get<uint32_t>("vis-frequency");
444  }
445 
446  set_param(param_);
447 
451  }
452 
453  // Removing this line causes an unexplainable segfault due to setting the
454  // gErrorIngoreLevel global parameter of ROOT. We need to log at least one
455  // thing before setting that parameter.
456  Log::Info("", "Initialize new simulation using BioDynaMo ",
457  Version::String());
458 }
459 
460 void Simulation::LoadConfigFiles(const std::vector<std::string>& ctor_configs,
461  const std::vector<std::string>& cli_configs) {
462  constexpr auto kTomlConfigFile = "bdm.toml";
463  constexpr auto kJsonConfigFile = "bdm.json";
464  constexpr auto kTomlConfigFileParentDir = "../bdm.toml";
465  constexpr auto kJsonConfigFileParentDir = "../bdm.json";
466  // find config file
467  std::vector<std::string> configs = {};
468  if (ctor_configs.size()) {
469  for (auto& ctor_config : ctor_configs) {
470  if (FileExists(ctor_config)) {
471  configs.push_back(ctor_config);
472  } else {
473  Log::Fatal("Simulation::LoadConfigFiles", "The config file ",
474  ctor_config,
475  " specified in the constructor of bdm::Simulation "
476  "could not be found.");
477  }
478  }
479  }
480  if (cli_configs.size()) {
481  for (auto& cli_config : cli_configs) {
482  if (FileExists(cli_config)) {
483  configs.push_back(cli_config);
484  } else {
485  Log::Fatal("Simulation::LoadConfigFiles", "The config file ",
486  cli_config,
487  " specified as command line argument "
488  "could not be found.");
489  }
490  }
491  }
492 
493  // no config file specified in ctor or cli -> look for default
494  if (!configs.size()) {
495  if (FileExists(kTomlConfigFile)) {
496  configs.push_back(kTomlConfigFile);
497  } else if (FileExists(kTomlConfigFileParentDir)) {
498  configs.push_back(kTomlConfigFileParentDir);
499  } else if (FileExists(kJsonConfigFile)) {
500  configs.push_back(kJsonConfigFile);
501  } else if (FileExists(kJsonConfigFileParentDir)) {
502  configs.push_back(kJsonConfigFileParentDir);
503  }
504  }
505 
506  // load config files
507  if (configs.size()) {
508  for (auto& config : configs) {
509  if (EndsWith(config, ".toml")) {
510  auto toml = cpptoml::parse_file(config);
511  param_->AssignFromConfig(toml);
512  } else if (EndsWith(config, ".json")) {
513  std::ifstream ifs(config);
514  std::stringstream buffer;
515  buffer << ifs.rdbuf();
516  param_->MergeJsonPatch(buffer.str());
517  }
518  Log::Info("Simulation::LoadConfigFiles",
519  "Processed config file: ", config);
520  }
521  } else {
522  Log::Info("Simulation::LoadConfigFiles", "Default config file ",
523  kTomlConfigFile, " or ", kJsonConfigFile,
524  " not found in `.` or `..` directory. No other config file was "
525  "specified as command line parameter or passed to the "
526  "constructor of bdm::Simulation.");
527  }
528 }
529 
530 void Simulation::InitializeUniqueName(const std::string& simulation_name) {
531  name_ = simulation_name;
532  std::stringstream stream;
533  stream << name_;
534  if (id_ > 0) {
535  stream << id_;
536  }
537  unique_name_ = stream.str();
538 }
539 
541  if (unique_name_ == "") {
543  } else {
545  }
546  // If we do not remove the output directory, we add a timestamp to the
547  // output directory to avoid overriding previous results.
549  time_t rawtime;
550  struct tm* timeinfo;
551  char buffer[80];
552  time(&rawtime);
553  timeinfo = localtime(&rawtime);
554  strftime(buffer, sizeof(buffer), "/%Y-%m-%d-%H:%M:%S", timeinfo);
555  output_dir_ += buffer;
556  }
557 
558  if (system(Concat("mkdir -p ", output_dir_).c_str())) {
559  Log::Fatal("Simulation::InitializeOutputDir",
560  "Failed to make output directory ", output_dir_);
561  }
562  if (!std::filesystem::is_empty(output_dir_)) {
565  } else {
566  // We throw a fatal because it will override previous results from a
567  // possibly expensive simulation. This should not happen
568  // unintentionally.
569  Log::Fatal(
570  "Simulation::InitializeOutputDir", "Output dir (", output_dir_,
571  ") is not empty. Previous result files would be overridden. Abort."
572  "Please set Param::remove_output_dir_contents to true to remove "
573  "files"
574  " automatically or clear the output directory by hand.");
575  }
576  }
577 }
578 
579 } // namespace bdm
in_place_exec_ctxt.h
bdm::Simulation::InitializeUniqueName
void InitializeUniqueName(const std::string &simulation_name)
This function initializes unique_name_
Definition: simulation.cc:530
adaptor.h
timing.h
filesystem.h
bdm::Param::remove_output_dir_contents
bool remove_output_dir_contents
Definition: param.h:149
bdm::Simulation::InitializeRuntimeParams
void InitializeRuntimeParams(CommandLineOptions *clo, const std::function< void(Param *)> &set_param, const std::vector< std::string > &ctor_config)
This function parses command line parameters and the configuration file.
Definition: simulation.cc:380
bdm::Simulation::environment_
Environment * environment_
Definition: simulation.h:162
kd_tree_environment.h
bdm::CommandLineOptions::GetSimulationName
std::string GetSimulationName() const
Return the simulation name that was parsed from argv[0].
Definition: command_line_options.cc:51
bdm::GpuHelper::GetInstance
static GpuHelper * GetInstance()
Definition: gpu_helper.cc:47
bdm::InPlaceExecutionContext::ThreadSafeAgentUidMap
Definition: in_place_exec_ctxt.h:56
bdm::ResourceManager::GetNumAgents
size_t GetNumAgents(int numa_node=-1) const
Definition: resource_manager.h:256
bdm::Simulation::Initialize
void Initialize(CommandLineOptions *clo, const std::function< void(Param *)> &set_param, const std::vector< std::string > &config_files)
Initialize Simulation.
Definition: simulation.cc:294
bdm::ThreadInfo::GetInstance
static ThreadInfo * GetInstance()
Definition: thread_info.cc:21
bdm::Simulation::GetTimeSeries
experimental::TimeSeries * GetTimeSeries()
Definition: simulation.cc:287
bdm::Simulation::Simulate
void Simulate(uint64_t steps)
Definition: simulation.cc:264
bdm::Simulation::output_dir_
std::string output_dir_
cached value where unique_name_ is appended to Param::output_dir
Definition: simulation.h:174
bdm
Definition: agent.cc:39
string.h
bdm::Simulation::ocl_state_
OpenCLState * ocl_state_
Definition: simulation.h:164
thread_info.h
bdm::MemoryManager::SetIgnoreDelete
void SetIgnoreDelete(bool value)
Definition: memory_manager.cc:402
bdm::Param::debug_numa
bool debug_numa
Definition: param.h:586
bdm::Param::ToJsonString
std::string ToJsonString() const
Definition: param.cc:108
bdm::Param::mem_mgr_aligned_pages_shift
uint64_t mem_mgr_aligned_pages_shift
Definition: param.h:499
bdm::Simulation::name_
std::string name_
Definition: simulation.h:161
bdm::UniformGridEnvironment
A class that represents Cartesian 3D grid.
Definition: uniform_grid_environment.h:58
bdm::Scheduler::GetOpTimes
TimingAggregator * GetOpTimes()
Definition: scheduler.cc:162
bdm::Simulation::mem_mgr_
MemoryManager * mem_mgr_
BioDynaMo memory manager. If nullptr, default allocator will be used.
Definition: simulation.h:179
bdm::Simulation::scheduler_
Scheduler * scheduler_
Definition: simulation.h:163
bdm::Param::use_bdm_mem_mgr
bool use_bdm_mem_mgr
Definition: param.h:487
bdm::ExecutionContext
Definition: execution_context.h:31
bdm::Simulation::InitializeMembers
void InitializeMembers()
Initialize data members that have a dependency on Simulation.
Definition: simulation.cc:314
bdm::Simulation::GetUniqueName
const std::string & GetUniqueName() const
Returns the name of the simulation.
Definition: simulation.cc:282
bdm::Simulation::Activate
void Activate()
Activates this simulation.
Definition: simulation.cc:241
bdm::Simulation::unique_name_
std::string unique_name_
Definition: simulation.h:172
bdm::InPlaceExecutionContext
Definition: in_place_exec_ctxt.h:54
bdm::Param::export_visualization
bool export_visualization
Definition: param.h:312
scheduler.h
bdm::Simulation::GetRandom
Random * GetRandom()
Returns a thread local random number generator.
Definition: simulation.cc:267
bdm::Simulation::exec_ctxt_
std::vector< ExecutionContext * > exec_ctxt_
Execution Context for each thread.
Definition: simulation.h:156
bdm::Param::backup_file
std::string backup_file
Definition: param.h:159
bdm::Random
Definition: random.h:262
bdm::Param::mem_mgr_max_mem_per_thread_factor
uint64_t mem_mgr_max_mem_per_thread_factor
Definition: param.h:522
bdm::Simulation::rm_
ResourceManager * rm_
Definition: simulation.h:158
bdm::Simulation::is_gpu_environment_initialized_
bool is_gpu_environment_initialized_
Definition: simulation.h:165
bdm::Simulation::SetEnvironment
void SetEnvironment(Environment *env)
Definition: simulation.cc:356
bdm::Simulation::random_
std::vector< Random * > random_
random number generator for each thread
Definition: simulation.h:153
uniform_grid_environment.h
bdm::Simulation::GetScheduler
Scheduler * GetScheduler()
Definition: simulation.cc:262
bdm::Simulation::id_
uint64_t id_
This id is unique for each simulation within the same process.
Definition: simulation.h:167
bdm::Simulation::GetAllRandom
std::vector< Random * > & GetAllRandom()
Returns all thread local random number generator.
Definition: simulation.cc:269
bdm::Param::compute_target
std::string compute_target
Definition: param.h:625
bdm::Param::mem_mgr_growth_rate
real_t mem_mgr_growth_rate
Definition: param.h:508
bdm::Log::Warning
static void Warning(const std::string &location, const Args &... parts)
Prints warning message.
Definition: log.h:67
bdm::Simulation::time_series_
experimental::TimeSeries * time_series_
Collects time series information during the simulation.
Definition: simulation.h:185
gpu_helper.h
time_series.h
bdm::MemoryManager
Definition: memory_manager.h:149
bdm::RemoveDirectoryContents
uint64_t RemoveDirectoryContents(const std::string &directory)
Definition: filesystem.cc:21
bdm::GpuHelper::InitializeGPUEnvironment
void InitializeGPUEnvironment()
Definition: gpu_helper.cc:244
bdm::Log::Info
static void Info(const std::string &location, const Args &... parts)
Prints information message.
Definition: log.h:55
bdm::Simulation::GetResourceManager
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
Definition: simulation.cc:244
bdm::Simulation::InitializeOutputDir
void InitializeOutputDir()
Initializes output_dir_ and creates dir if it does not exist.
Definition: simulation.cc:540
bdm::ResourceManager
Definition: resource_manager.h:53
bdm::OpenCLState
Definition: opencl_state.h:33
command_line_options.h
bdm::Scheduler::Simulate
void Simulate(uint64_t steps)
Simulate steps number of iterations.
Definition: scheduler.cc:130
bdm::kRealtName
constexpr const char * kRealtName
Definition: real_t.h:22
bdm::FileExists
bool FileExists(const std::string &file_name)
Definition: io.cc:78
bdm::Simulation::counter_
static std::atomic< uint64_t > counter_
Number of simulations in this process.
Definition: simulation.h:150
bdm::EndsWith
bool EndsWith(const std::string &str, const std::string &suffix)
Definition: string.h:25
bdm::Simulation::dtor_ts_
int64_t dtor_ts_
Timestep when destructor was called.
Definition: simulation.h:183
bdm::Simulation::SetAllExecCtxts
void SetAllExecCtxts(const std::vector< ExecutionContext * > &exec_ctxts)
Definition: simulation.cc:363
agent_uid_generator.h
bdm::Concat
std::string Concat(const Args &... parts)
Concatenates all arguments into a string. Equivalent to streaming all arguments into a stringstream a...
Definition: string.h:70
bdm::KDTreeEnvironment
Definition: kd_tree_environment.h:70
bdm::Param::MergeJsonPatch
void MergeJsonPatch(const std::string &patch)
Definition: param.cc:126
bdm::Simulation::Restore
void Restore(Simulation &&restored)
Definition: simulation.cc:109
bdm::Simulation::GetOpenCLState
OpenCLState * GetOpenCLState()
Return helper class for OpenCL environment.
Definition: simulation.cc:279
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
bdm::Log::Error
static void Error(const std::string &location, const Args &... parts)
Prints error message.
Definition: log.h:79
bdm::Simulation::command_line_parameter_str_
std::string command_line_parameter_str_
Definition: simulation.h:177
bdm::Simulation::GetAgentUidGenerator
AgentUidGenerator * GetAgentUidGenerator()
Definition: simulation.cc:256
bdm::experimental::TimeSeries
Definition: time_series.h:123
bdm::AgentUidGenerator
This class generates unique ids for agents.
Definition: agent_uid_generator.h:33
log.h
bdm::Param::AssignFromConfig
void AssignFromConfig(const std::shared_ptr< cpptoml::table > &)
Assign values from config file to variables.
Definition: param.cc:220
bdm::Simulation::Simulation
Simulation(TRootIOCtor *p)
Definition: simulation.cc:70
bdm::Param::random_seed
uint64_t random_seed
Definition: param.h:90
bdm::ThreadInfo::Renew
void Renew()
Definition: thread_info.h:78
bdm::Param::environment
std::string environment
Definition: param.h:122
octree_environment.h
bdm::Simulation::active_
static Simulation * active_
Currently active simulation.
Definition: simulation.h:148
bdm::ResourceManager::ForEachDiffusionGrid
void ForEachDiffusionGrid(TFunctor &&f) const
Definition: resource_manager.h:232
bdm::Simulation::ctor_ts_
int64_t ctor_ts_
Timestep when constructor was called.
Definition: simulation.h:181
git_tracker.h
bdm::operator<<
std::ostream & operator<<(std::ostream &o, const MathArray< T, N > &arr)
Definition: math_array.h:412
bdm::Simulation::GetExecutionContext
ExecutionContext * GetExecutionContext()
Returns a thread local execution context.
Definition: simulation.cc:271
bdm::Simulation::GetEnvironment
Environment * GetEnvironment()
Definition: simulation.cc:260
io.h
bdm::Simulation::ReplaceScheduler
void ReplaceScheduler(Scheduler *scheduler)
Definition: simulation.cc:289
environment.h
simulation.h
bdm::Param::visualization_interval
uint32_t visualization_interval
Definition: param.h:353
bdm::Simulation::GetParam
const Param * GetParam() const
Returns the simulation parameters.
Definition: simulation.cc:254
bdm::Simulation::SetResourceManager
void SetResourceManager(ResourceManager *rm)
Definition: simulation.cc:246
bdm::Param::output_dir
std::string output_dir
Definition: param.h:113
bdm::Simulation::GetAllExecCtxts
std::vector< ExecutionContext * > & GetAllExecCtxts()
Returns all thread local execution contexts.
Definition: simulation.cc:275
bdm::Timing::Timestamp
static int64_t Timestamp()
Definition: timing.h:33
bdm::Environment
Definition: environment.h:30
bdm::Simulation::LoadConfigFiles
void LoadConfigFiles(const std::vector< std::string > &ctor_configs, const std::vector< std::string > &cli_configs)
Definition: simulation.cc:460
resource_manager.h
param.h
bdm::Param::restore_file
std::string restore_file
Definition: param.h:169
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
bdm::OctreeEnvironment
Definition: octree_environment.h:43
bdm::Param
Definition: param.h:35
bdm::Simulation::~Simulation
~Simulation()
Definition: simulation.cc:191
bdm::Simulation::param_
Param * param_
Definition: simulation.h:159
bdm::Scheduler
Definition: scheduler.h:45
bdm::CommandLineOptions
Class to contain and parse command line options.
Definition: command_line_options.h:37
bdm::Simulation::GetOutputDir
const std::string & GetOutputDir() const
Returns the output directory for this specific simulation.
Definition: simulation.cc:285
bdm::Simulation
Definition: simulation.h:50
bdm::Param::statistics
bool statistics
Definition: param.h:568
bdm::Param::Restore
void Restore(Param &&other)
Definition: param.cc:57
bdm::Scheduler::GetSimulatedSteps
uint64_t GetSimulatedSteps() const
This function returns the number of simulated steps (=iterations).
Definition: scheduler.cc:158
bdm::Simulation::agent_uid_generator_
AgentUidGenerator * agent_uid_generator_
Definition: simulation.h:160