BioDynaMo  v1.05.120-25dc9790
operation.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 
16 
17 namespace bdm {
18 
19 Operation::Operation(const std::string &name) : name_(name) {}
20 
21 Operation::Operation(const std::string &name, uint32_t frequency)
22  : frequency_(frequency), name_(name) {}
23 
25  for (auto *imp : implementations_) {
26  if (imp) {
27  delete imp;
28  }
29  }
30 }
31 
33  auto *clone = new Operation(*this);
34  // Deep copy of the implementations
35  int i = 0;
36  for (auto *imp : implementations_) {
37  if (imp) {
38  clone->implementations_[i] = imp->Clone();
39  } else {
40  clone->implementations_[i] = nullptr;
41  }
42  i++;
43  }
44  return clone;
45 }
46 
49 }
50 
52 
54  if (implementations_.size() < static_cast<size_t>(target + 1)) {
55  implementations_.resize(target + 1, nullptr);
56  }
57  implementations_[target] = impl;
58  impl->target_ = target;
59 }
60 
62  if (implementations_.size() < static_cast<size_t>(target + 1)) {
63  return false;
64  }
65  return implementations_[target] != nullptr;
66 }
67 
69  if (!IsComputeTargetSupported(target)) {
70  Log::Fatal("Operation::SelectComputeTarget",
71  "Compute target not supported");
72  }
73  active_target_ = target;
74 }
75 
77 
79 
80 } // namespace bdm
bdm::Operation::operator()
void operator()()
Definition: operation.cc:51
bdm
Definition: agent.cc:39
operation.h
bdm::OperationImpl
Definition: operation.h:46
bdm::Operation::SetUp
void SetUp()
Forwards call to implementation's Setup function.
Definition: operation.cc:76
bdm::Operation::Operation
Operation(const std::string &name)
Definition: operation.cc:19
bdm::Operation::implementations_
std::vector< OperationImpl * > implementations_
The different operation implementations for each supported compute target.
Definition: operation.h:202
bdm::Agent
Contains code required by all agents.
Definition: agent.h:79
bdm::Operation::Clone
Operation * Clone()
Definition: operation.cc:32
bdm::OpComputeTarget
OpComputeTarget
Definition: operation.h:31
bdm::Operation::TearDown
void TearDown()
Forwards call to implementation's TearDown function.
Definition: operation.cc:78
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
bdm::Operation::~Operation
~Operation()
Definition: operation.cc:24
bdm::Operation::IsComputeTargetSupported
bool IsComputeTargetSupported(OpComputeTarget target)
Definition: operation.cc:61
bdm::Operation
Definition: operation.h:99
bdm::OperationImpl::target_
OpComputeTarget target_
The target that this operation implementation is supposed to run on.
Definition: operation.h:72
bdm::Operation::SelectComputeTarget
void SelectComputeTarget(OpComputeTarget target)
Definition: operation.cc:68
bdm::Operation::active_target_
OpComputeTarget active_target_
The compute target that this operation will be executed on.
Definition: operation.h:200
bdm::Operation::AddOperationImpl
void AddOperationImpl(OpComputeTarget target, OperationImpl *impl)
Definition: operation.cc:53