BioDynaMo  v1.03.58-27764645
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 <experimental/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 
53 #include <TEnv.h>
54 #include <TROOT.h>
55 
56 namespace fs = std::experimental::filesystem;
57 
58 namespace bdm {
59 
62 
63 std::atomic<uint64_t> Simulation::counter_;
64 
65 Simulation* Simulation::active_ = nullptr;
66 
68 
69 Simulation::Simulation(TRootIOCtor* p) {}
70 
71 Simulation::Simulation(int argc, const char** argv,
72  const std::vector<std::string>& config_files)
73  : Simulation(
74  argc, argv, [](auto* param) {}, config_files) {}
75 
76 Simulation::Simulation(const std::string& simulation_name,
77  const std::vector<std::string>& config_files)
78  : Simulation(
79  simulation_name, [](auto* param) {}, config_files) {}
80 
82  const std::vector<std::string>& config_files) {
83  Initialize(
84  clo, [](auto* param) {}, config_files);
85 }
86 
88  const std::function<void(Param*)>& set_param,
89  const std::vector<std::string>& config_files) {
90  Initialize(clo, set_param, config_files);
91 }
92 
93 Simulation::Simulation(int argc, const char** argv,
94  const std::function<void(Param*)>& set_param,
95  const std::vector<std::string>& config_files) {
96  auto options = CommandLineOptions(argc, argv);
97  Initialize(&options, set_param, config_files);
98 }
99 
100 Simulation::Simulation(const std::string& simulation_name,
101  const std::function<void(Param*)>& set_param,
102  const std::vector<std::string>& config_files) {
103  const char* argv[1] = {simulation_name.c_str()};
104  auto options = CommandLineOptions(1, argv);
105  Initialize(&options, set_param, config_files);
106 }
107 
108 void Simulation::Restore(Simulation&& restored) {
109  // random_
110  if (random_.size() != restored.random_.size()) {
111  Log::Warning("Simulation", "The restore file (", param_->restore_file,
112  ") was run with a different number of threads. Can't restore "
113  "complete random number generator state.");
114  uint64_t min = std::min(random_.size(), restored.random_.size());
115  for (uint64_t i = 0; i < min; i++) {
116  *(random_[i]) = *(restored.random_[i]);
117  }
118  } else {
119  for (uint64_t i = 0; i < random_.size(); i++) {
120  *(random_[i]) = *(restored.random_[i]);
121  }
122  }
123 
124  // param and rm
125  param_->Restore(std::move(*restored.param_));
126  restored.param_ = nullptr;
127  *rm_ = std::move(*restored.rm_);
128  restored.rm_ = nullptr;
129 
130  *time_series_ = std::move(*restored.time_series_);
131 
132  // name_ and unique_name_
133  InitializeUniqueName(restored.name_);
135 }
136 
137 std::ostream& operator<<(std::ostream& os, Simulation& sim) {
138  std::vector<std::string> dgrid_names;
139  std::vector<size_t> dgrid_resolutions;
140  std::vector<std::array<int32_t, 3>> dgrid_dimensions;
141  std::vector<uint64_t> dgrid_voxels;
142 
143  sim.rm_->ForEachDiffusionGrid([&](auto* dgrid) {
144  dgrid_names.push_back(dgrid->GetSubstanceName());
145  dgrid_resolutions.push_back(dgrid->GetResolution());
146  dgrid_dimensions.push_back(dgrid->GetGridSize());
147  dgrid_voxels.push_back(dgrid->GetNumBoxes());
148  });
149 
150  os << std::endl;
151 
152  os << "***********************************************" << std::endl;
153  os << "***********************************************" << std::endl;
154  os << "\033[1mSimulation Metadata:\033[0m" << std::endl;
155  os << "***********************************************" << std::endl;
156  os << std::endl;
157  os << "\033[1mGeneral\033[0m" << std::endl;
158  if (sim.command_line_parameter_str_ != "") {
159  os << "Command\t\t\t\t: " << sim.command_line_parameter_str_ << std::endl;
160  }
161  os << "Simulation name\t\t\t: " << sim.GetUniqueName() << std::endl;
162  os << "Total simulation runtime\t: " << (sim.dtor_ts_ - sim.ctor_ts_) << " ms"
163  << std::endl;
164  os << "Peak memory usage (MB)\t\t: " << (getPeakRSS() / 1048576.0)
165  << std::endl;
166  os << "Number of iterations executed\t: "
167  << sim.scheduler_->GetSimulatedSteps() << std::endl;
168  os << "Number of agents\t\t: " << sim.rm_->GetNumAgents() << std::endl;
169 
170  if (dgrid_names.size() != 0) {
171  os << "Diffusion grids" << std::endl;
172  for (size_t i = 0; i < dgrid_names.size(); ++i) {
173  os << " " << dgrid_names[i] << ":" << std::endl;
174  auto& dim = dgrid_dimensions[i];
175  os << "\t"
176  << "Resolution\t\t: " << dgrid_resolutions[i] << std::endl;
177  os << "\t"
178  << "Size\t\t\t: " << dim[0] << " x " << dim[1] << " x " << dim[2]
179  << std::endl
180  << "\tVoxels\t\t\t: " << dgrid_voxels[i] << std::endl;
181  }
182  }
183 
184  os << "Output directory\t\t: " << sim.GetOutputDir() << std::endl;
185  os << " size\t\t\t\t: "
186  << gSystem->GetFromPipe(
187  Concat("du -sh ", sim.GetOutputDir(), " | cut -f1").c_str())
188  << std::endl;
189  os << "BioDynaMo version:\t\t: " << Version::String() << std::endl;
190  os << "BioDynaMo real type:\t\t: " << kRealtName << std::endl;
191  os << std::endl;
192  os << "***********************************************" << std::endl;
193  os << *(sim.scheduler_->GetOpTimes()) << std::endl;
194  os << "***********************************************" << std::endl;
195  os << std::endl;
196  os << "\033[1mThread Info\033[0m" << std::endl;
197  os << *ThreadInfo::GetInstance();
198  os << std::endl;
199  os << "***********************************************" << std::endl;
200  os << std::endl;
201  os << *(sim.rm_);
202  os << std::endl;
203  os << "***********************************************" << std::endl;
204  os << std::endl;
205  os << "\033[1mParameters\033[0m" << std::endl;
206  os << sim.param_->ToJsonString();
207  os << std::endl;
208  os << "***********************************************" << std::endl;
209  os << "***********************************************" << std::endl;
210 
211  return os;
212 }
213 
216 
217  if (param_ != nullptr && param_->statistics) {
218  std::stringstream sstr;
219  sstr << *this << std::endl;
220  std::cout << sstr.str() << std::endl;
221  // write to file
222  std::ofstream ofs(Concat(output_dir_, "/metadata"));
223  ofs << sstr.str() << std::endl;
224  }
225 
226  if (mem_mgr_) {
227  mem_mgr_->SetIgnoreDelete(true);
228  }
229  Simulation* tmp = nullptr;
230  if (active_ != this) {
231  tmp = active_;
232  }
233  active_ = this;
234 
235  delete rm_;
236  delete environment_;
237  delete scheduler_;
238  if (agent_uid_generator_ != nullptr) {
239  delete agent_uid_generator_;
240  }
241  delete param_;
242  for (auto* r : random_) {
243  delete r;
244  }
245  for (auto* ectxt : exec_ctxt_) {
246  delete ectxt;
247  }
248  if (mem_mgr_) {
249  delete mem_mgr_;
250  }
251  delete ocl_state_;
252  if (time_series_) {
253  delete time_series_;
254  }
255  active_ = tmp;
256 }
257 
258 void Simulation::Activate() { active_ = this; }
259 
262 
264  if (rm != rm_) {
265  delete rm_;
266  }
267  rm_ = rm;
268 }
269 
271 const Param* Simulation::GetParam() const { return param_; }
272 
274  return agent_uid_generator_;
275 }
276 
278 
280 
281 void Simulation::Simulate(uint64_t steps) { scheduler_->Simulate(steps); }
282 
284 Random* Simulation::GetRandom() { return random_[omp_get_thread_num()]; }
285 
286 std::vector<Random*>& Simulation::GetAllRandom() { return random_; }
287 
289  return exec_ctxt_[omp_get_thread_num()];
290 }
291 
292 std::vector<ExecutionContext*>& Simulation::GetAllExecCtxts() {
293  return exec_ctxt_;
294 }
295 
297 
299 const std::string& Simulation::GetUniqueName() const { return unique_name_; }
300 
302 const std::string& Simulation::GetOutputDir() const { return output_dir_; }
303 
305 
307  delete scheduler_;
308  scheduler_ = scheduler;
309 }
310 
312  const std::function<void(Param*)>& set_param,
313  const std::vector<std::string>& config_files) {
314  // Initialize a thread-safe ROOT instance
315  TROOT(name_.c_str(), "BioDynaMo");
316  ROOT::EnableThreadSafety();
317 
319  id_ = counter_++;
320  Activate();
321  if (!clo) {
322  Log::Fatal("Simulation::Initialize",
323  "CommandLineOptions argument was a nullptr!");
324  }
326  InitializeRuntimeParams(clo, set_param, config_files);
329 }
330 
332  if (param_->use_bdm_mem_mgr) {
336  }
338  if (param_->debug_numa) {
339  std::cout << "ThreadInfo:\n" << *ThreadInfo::GetInstance() << std::endl;
340  }
341 
342  random_.resize(omp_get_max_threads());
343 #pragma omp parallel for schedule(static, 1)
344  for (uint64_t i = 0; i < random_.size(); i++) {
345  random_[i] = new Random();
346  random_[i]->SetSeed(param_->random_seed * (i + 1));
347  }
348  exec_ctxt_.resize(omp_get_max_threads());
349  auto map = std::make_shared<
351 #pragma omp parallel for schedule(static, 1)
352  for (uint64_t i = 0; i < exec_ctxt_.size(); i++) {
353  exec_ctxt_[i] = new InPlaceExecutionContext(map);
354  }
355  rm_ = new ResourceManager();
356 
357  // Set the specified neighborhood search method
358  if (param_->environment == "kd_tree") {
360  } else if (param_->environment == "octree") {
362  } else if (param_->environment == "uniform_grid") {
364  } else {
365  Log::Error("Simulation::Initialize", "No such neighboring method '",
366  param_->environment, "'. Defaulting to 'uniform_grid'");
368  }
369  scheduler_ = new Scheduler();
371 }
372 
374  if (environment_ != nullptr && env != environment_) {
375  delete environment_;
376  }
377  environment_ = env;
378 }
379 
381  const std::vector<ExecutionContext*>& exec_ctxts) {
382  if (exec_ctxts.size() != exec_ctxt_.size()) {
383  Log::Error("Simulation::SetAllExecCtxts", "Size of exec_ctxts (",
384  exec_ctxts.size(), ") does not match the expected size (",
385  exec_ctxt_.size(), "). Operation aborted");
386  return;
387  }
388  for (uint64_t i = 0; i < exec_ctxt_.size(); ++i) {
389  auto* ctxt = exec_ctxt_[i];
390  if (ctxt != nullptr && ctxt != exec_ctxts[i]) {
391  delete ctxt;
392  }
393  exec_ctxt_[i] = exec_ctxts[i];
394  }
395 }
396 
398  CommandLineOptions* clo, const std::function<void(Param*)>& set_param,
399  const std::vector<std::string>& ctor_config_files) {
400  // Renew thread info just in case it has been initialised as static and a
401  // simulation calls e.g. `omp_set_num_threads()` within main.
403 
404  std::stringstream sstr;
405  sstr << (*clo);
406  command_line_parameter_str_ = sstr.str();
407 
408  param_ = new Param();
409 
410  // detect if the biodynamo environment has been sourced
411  if (std::getenv("BDMSYS") == nullptr) {
412  Log::Fatal(
413  "Simulation::InitializeRuntimeParams",
414  "The BioDynaMo environment is not set up correctly. Please execute "
415  "'source <path-to-bdm-installation>/bin/thisbdm.sh' and retry this "
416  "command.");
417  }
418 
419  static bool read_env = false;
420  if (!read_env) {
421  // Read, only once, bdm.rootrc to set BioDynaMo-related settings for ROOT
422  std::stringstream os;
423  os << std::getenv("BDMSYS") << "/etc/bdm.rootrc";
424  gEnv->ReadFile(os.str().c_str(), kEnvUser);
425  read_env = true;
426  }
427 
428  // Process `--config` arguments
429  LoadConfigFiles(ctor_config_files,
430  clo->Get<std::vector<std::string>>("config"));
431 
432  // Process `--inline-config` arguments
433  auto inline_configs = clo->Get<std::vector<std::string>>("inline-config");
434  if (inline_configs.size()) {
435  for (auto& inline_config : inline_configs) {
436  param_->MergeJsonPatch(inline_config);
437  }
438  }
439 
440  if (clo->Get<std::string>("backup") != "") {
441  param_->backup_file = clo->Get<std::string>("backup");
442  }
443  if (clo->Get<std::string>("restore") != "") {
444  param_->restore_file = clo->Get<std::string>("restore");
445  }
446 
447  // Handle "cuda" and "opencl" arguments
448  if (clo->Get<bool>("cuda")) {
449  param_->compute_target = "cuda";
450  }
451 
452  if (clo->Get<bool>("opencl")) {
453  param_->compute_target = "opencl";
454  }
455 
456  ocl_state_ = new OpenCLState();
457 
458  if (clo->Get<bool>("visualize")) {
460  param_->visualization_interval = clo->Get<uint32_t>("vis-frequency");
461  }
462 
463  set_param(param_);
464 
468  }
469 
470  // Removing this line causes an unexplainable segfault due to setting the
471  // gErrorIngoreLevel global parameter of ROOT. We need to log at least one
472  // thing before setting that parameter.
473  Log::Info("", "Initialize new simulation using BioDynaMo ",
474  Version::String());
475 }
476 
477 void Simulation::LoadConfigFiles(const std::vector<std::string>& ctor_configs,
478  const std::vector<std::string>& cli_configs) {
479  constexpr auto kTomlConfigFile = "bdm.toml";
480  constexpr auto kJsonConfigFile = "bdm.json";
481  constexpr auto kTomlConfigFileParentDir = "../bdm.toml";
482  constexpr auto kJsonConfigFileParentDir = "../bdm.json";
483  // find config file
484  std::vector<std::string> configs = {};
485  if (ctor_configs.size()) {
486  for (auto& ctor_config : ctor_configs) {
487  if (FileExists(ctor_config)) {
488  configs.push_back(ctor_config);
489  } else {
490  Log::Fatal("Simulation::LoadConfigFiles", "The config file ",
491  ctor_config,
492  " specified in the constructor of bdm::Simulation "
493  "could not be found.");
494  }
495  }
496  }
497  if (cli_configs.size()) {
498  for (auto& cli_config : cli_configs) {
499  if (FileExists(cli_config)) {
500  configs.push_back(cli_config);
501  } else {
502  Log::Fatal("Simulation::LoadConfigFiles", "The config file ",
503  cli_config,
504  " specified as command line argument "
505  "could not be found.");
506  }
507  }
508  }
509 
510  // no config file specified in ctor or cli -> look for default
511  if (!configs.size()) {
512  if (FileExists(kTomlConfigFile)) {
513  configs.push_back(kTomlConfigFile);
514  } else if (FileExists(kTomlConfigFileParentDir)) {
515  configs.push_back(kTomlConfigFileParentDir);
516  } else if (FileExists(kJsonConfigFile)) {
517  configs.push_back(kJsonConfigFile);
518  } else if (FileExists(kJsonConfigFileParentDir)) {
519  configs.push_back(kJsonConfigFileParentDir);
520  }
521  }
522 
523  // load config files
524  if (configs.size()) {
525  for (auto& config : configs) {
526  if (EndsWith(config, ".toml")) {
527  auto toml = cpptoml::parse_file(config);
528  param_->AssignFromConfig(toml);
529  } else if (EndsWith(config, ".json")) {
530  std::ifstream ifs(config);
531  std::stringstream buffer;
532  buffer << ifs.rdbuf();
533  param_->MergeJsonPatch(buffer.str());
534  }
535  Log::Info("Simulation::LoadConfigFiles",
536  "Processed config file: ", config);
537  }
538  } else {
539  Log::Info("Simulation::LoadConfigFiles", "Default config file ",
540  kTomlConfigFile, " or ", kJsonConfigFile,
541  " not found in `.` or `..` directory. No other config file was "
542  "specified as command line parameter or passed to the "
543  "constructor of bdm::Simulation.");
544  }
545 }
546 
547 void Simulation::InitializeUniqueName(const std::string& simulation_name) {
548  name_ = simulation_name;
549  std::stringstream stream;
550  stream << name_;
551  if (id_ > 0) {
552  stream << id_;
553  }
554  unique_name_ = stream.str();
555 }
556 
558  if (unique_name_ == "") {
560  } else {
562  }
563  // If we do not remove the output directory, we add a timestamp to the
564  // output directory to avoid overriding previous results.
566  time_t rawtime;
567  struct tm* timeinfo;
568  char buffer[80];
569  time(&rawtime);
570  timeinfo = localtime(&rawtime);
571  strftime(buffer, sizeof(buffer), "/%Y-%m-%d-%H:%M:%S", timeinfo);
572  output_dir_ += buffer;
573  }
574 
575  if (system(Concat("mkdir -p ", output_dir_).c_str())) {
576  Log::Fatal("Simulation::InitializeOutputDir",
577  "Failed to make output directory ", output_dir_);
578  }
579  if (!fs::is_empty(output_dir_)) {
582  } else {
583  // We throw a fatal because it will override previous results from a
584  // possibly expensive simulation. This should not happen unintentionally.
585  Log::Fatal(
586  "Simulation::InitializeOutputDir", "Output dir (", output_dir_,
587  ") is not empty. Previous result files would be overriden. Abort."
588  "Please set Param::remove_output_dir_contents to true to remove files"
589  " automatically or clear the output directory by hand.");
590  }
591  }
592 }
593 
594 } // namespace bdm
in_place_exec_ctxt.h
bdm::Simulation::InitializeUniqueName
void InitializeUniqueName(const std::string &simulation_name)
This function initialzes unique_name_
Definition: simulation.cc:547
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:397
bdm::Simulation::environment_
Environment * environment_
Definition: simulation.h:162
kd_tree_environment.h
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:184
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:311
bdm::ThreadInfo::GetInstance
static ThreadInfo * GetInstance()
Definition: thread_info.cc:21
bdm::Simulation::GetTimeSeries
experimental::TimeSeries * GetTimeSeries()
Definition: simulation.cc:304
bdm::Simulation::Simulate
void Simulate(uint64_t steps)
Definition: simulation.cc:281
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:575
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:497
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:164
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:485
bdm::ExecutionContext
Definition: execution_context.h:31
bdm::Simulation::InitializeMembers
void InitializeMembers()
Initialize data members that have a dependency on Simulation.
Definition: simulation.cc:331
bdm::Simulation::GetUniqueName
const std::string & GetUniqueName() const
Returns the name of the simulation.
Definition: simulation.cc:299
bdm::Simulation::Activate
void Activate()
Activates this simulation.
Definition: simulation.cc:258
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:310
scheduler.h
bdm::Simulation::GetRandom
Random * GetRandom()
Returns a thread local random number generator.
Definition: simulation.cc:284
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:520
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:373
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:279
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:286
bdm::Param::compute_target
std::string compute_target
Definition: param.h:607
bdm::Param::mem_mgr_growth_rate
real_t mem_mgr_growth_rate
Definition: param.h:506
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:23
bdm::GpuHelper::InitializeGPUEnvironment
void InitializeGPUEnvironment()
Definition: gpu_helper.cc:216
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:261
bdm::Simulation::InitializeOutputDir
void InitializeOutputDir()
Initializes output_dir_ and creates dir if it does not exist.
Definition: simulation.cc:557
bdm::ResourceManager
Definition: resource_manager.h:52
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:380
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:108
bdm::Simulation::GetOpenCLState
OpenCLState * GetOpenCLState()
Return helper class for OpenCL environment.
Definition: simulation.cc:296
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:273
bdm::experimental::TimeSeries
Definition: time_series.h:33
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::CommandLineOptions::GetSimulationName
std::string GetSimulationName()
Return the simulation name that was parsed from argv[0].
Definition: command_line_options.cc:51
bdm::Simulation::Simulation
Simulation(TRootIOCtor *p)
Definition: simulation.cc:69
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:176
bdm::Simulation::ctor_ts_
int64_t ctor_ts_
Timestep when constructor was called.
Definition: simulation.h:181
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:288
bdm::Simulation::GetEnvironment
Environment * GetEnvironment()
Definition: simulation.cc:277
io.h
bdm::Simulation::ReplaceScheduler
void ReplaceScheduler(Scheduler *scheduler)
Definition: simulation.cc:306
environment.h
simulation.h
bdm::Param::visualization_interval
uint32_t visualization_interval
Definition: param.h:351
bdm::Simulation::GetParam
const Param * GetParam() const
Returns the simulation parameters.
Definition: simulation.cc:271
bdm::Simulation::SetResourceManager
void SetResourceManager(ResourceManager *rm)
Definition: simulation.cc:263
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:292
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:477
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:67
bdm::OctreeEnvironment
Definition: octree_environment.h:43
bdm::Param
Definition: param.h:35
bdm::Simulation::~Simulation
~Simulation()
Definition: simulation.cc:214
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:302
bdm::Simulation
Definition: simulation.h:50
bdm::Param::statistics
bool statistics
Definition: param.h:566
bdm::Param::Restore
void Restore(Param &&other)
Definition: param.cc:57
bdm::Scheduler::GetSimulatedSteps
uint64_t GetSimulatedSteps() const
This function returns the numer of simulated steps (=iterations).
Definition: scheduler.cc:160
bdm::Simulation::agent_uid_generator_
AgentUidGenerator * agent_uid_generator_
Definition: simulation.h:160