Skip to content

Commit

Permalink
Minor code quality improvements (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDuswald authored Mar 18, 2022
1 parent ebeeb7e commit 862a1b0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/core/agent/agent_uid_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class AgentUidGenerator {
}
if (search_index_ < map_->size()) {
auto* scheduler = Simulation::GetActive()->GetScheduler();
return AgentUid(search_index_++, scheduler->GetSimulatedSteps());
return AgentUid(search_index_++, static_cast<AgentUid::Reused_t>(
scheduler->GetSimulatedSteps()));
}
// didn't find any empty slots -> disable defragmentation mode
DisableDefragmentation();
Expand All @@ -74,7 +75,7 @@ class AgentUidGenerator {

void DisableDefragmentation() {
if (map_ != nullptr) {
counter_ = map_->size();
counter_ = static_cast<AgentUid::Index_t>(map_->size());
}
map_ = nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/environment/uniform_grid_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ class UniformGridEnvironment : public Environment {
std::sort(mutex_indices_.begin(), mutex_indices_.end());
}

virtual ~GridNeighborMutex() = default;
~GridNeighborMutex() override = default;

void lock() override { // NOLINT
for (auto idx : mutex_indices_) {
Expand Down Expand Up @@ -576,7 +576,7 @@ class UniformGridEnvironment : public Environment {
std::atomic_flag mutex_ = ATOMIC_FLAG_INIT;
};

virtual ~GridNeighborMutexBuilder() = default;
~GridNeighborMutexBuilder() override = default;

void Update() {
auto* grid = static_cast<UniformGridEnvironment*>(
Expand Down
17 changes: 10 additions & 7 deletions src/core/resource_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class ResourceManager {
uid_ah_map_.clear();
auto* agent_uid_generator = Simulation::GetActive()->GetAgentUidGenerator();
uid_ah_map_.resize(agent_uid_generator->GetHighestIndex() + 1);
for (unsigned n = 0; n < agents_.size(); ++n) {
for (unsigned i = 0; i < agents_[n].size(); ++i) {
for (AgentHandle::NumaNode_t n = 0; n < agents_.size(); ++n) {
for (AgentHandle::ElementIdx_t i = 0; i < agents_[n].size(); ++i) {
auto* agent = agents_[n][i];
this->uid_ah_map_.Insert(agent->GetUid(), AgentHandle(n, i));
}
Expand Down Expand Up @@ -217,9 +217,9 @@ class ResourceManager {
virtual void ForEachAgent(
const std::function<void(Agent*, AgentHandle)>& function,
Functor<bool, Agent*>* filter = nullptr) {
for (uint64_t n = 0; n < agents_.size(); ++n) {
for (AgentHandle::NumaNode_t n = 0; n < agents_.size(); ++n) {
auto& numa_agents = agents_[n];
for (uint64_t i = 0; i < numa_agents.size(); ++i) {
for (AgentHandle::ElementIdx_t i = 0; i < numa_agents.size(); ++i) {
auto* a = numa_agents[i];
if (!filter || (filter && (*filter)(a))) {
function(a, AgentHandle(n, i));
Expand Down Expand Up @@ -325,8 +325,9 @@ class ResourceManager {
uid_ah_map_.resize(uid.GetIndex() + 1);
}
agents_[numa_node].push_back(agent);
uid_ah_map_.Insert(uid,
AgentHandle(numa_node, agents_[numa_node].size() - 1));
uid_ah_map_.Insert(
uid, AgentHandle(numa_node, static_cast<AgentHandle::ElementIdx_t>(
agents_[numa_node].size() - 1u)));
if (type_index_) {
type_index_->Add(agent);
}
Expand Down Expand Up @@ -368,7 +369,9 @@ class ResourceManager {
uint64_t i = 0;
for (auto* agent : new_agents) {
auto uid = agent->GetUid();
uid_ah_map_.Insert(uid, AgentHandle(numa_node, offset + i));
uid_ah_map_.Insert(
uid, AgentHandle(numa_node,
static_cast<AgentHandle::ElementIdx_t>(offset + i)));
agents_[numa_node][offset + i] = agent;
i++;
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/simulation_backup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ size_t SimulationBackup::GetSimulationStepsFromBackup() {
IntegralTypeWrapper<size_t>* wrapper = nullptr;
bdm::GetPersistentObject(restore_file.c_str(), kSimulationStepName.c_str(),
wrapper);
return wrapper->Get();
if (wrapper != nullptr) {
return wrapper->Get();
} else {
Log::Fatal("SimulationBackup", "Failed to retrieve SimulationSteps.");
return 0;
}
} else {
Log::Fatal("SimulationBackup",
"Requested to restore data, but no restore file given.");
Expand Down
8 changes: 4 additions & 4 deletions src/core/util/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ThreadInfo {
/// metadata.
void Renew() {
max_threads_ = omp_get_max_threads();
numa_nodes_ = numa_num_configured_nodes();
numa_nodes_ = static_cast<uint16_t>(numa_num_configured_nodes());

thread_numa_mapping_.clear();
numa_thread_id_.clear();
Expand All @@ -97,8 +97,8 @@ class ThreadInfo {
// (numa -> number of associated threads), and
// (omp_thread_id -> thread id in numa)
for (uint16_t n = 0; n < numa_nodes_; n++) {
uint64_t cnt = 0;
for (uint64_t t = 0; t < max_threads_; t++) {
int cnt = 0;
for (int t = 0; t < max_threads_; t++) {
int numa = thread_numa_mapping_[t];
if (n == numa) {
numa_thread_id_[t] = cnt;
Expand Down Expand Up @@ -135,7 +135,7 @@ class ThreadInfo {
static std::atomic<uint64_t> thread_counter_;

/// Maximum number of threads for this simulation.
uint64_t max_threads_;
int max_threads_;
/// Number of NUMA nodes on this machine.
uint16_t numa_nodes_;

Expand Down
8 changes: 5 additions & 3 deletions src/core/visualization/paraview/mapped_data_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ struct GetDataMemberForVis {

// -----------------------------------------------------------------------------
struct MappedDataArrayInterface {
MappedDataArrayInterface() = default;
virtual ~MappedDataArrayInterface() = default;
virtual void Update(const std::vector<Agent*>* agents, uint64_t start,
uint64_t end) = 0;
};
Expand Down Expand Up @@ -435,12 +437,12 @@ void MappedDataArray<TScalar, TClass, TDataMember>::GetTuple(vtkIdType tuple_id,
}
}
case Param::MappedDataArrayMode::kZeroCopy: {
auto* data = get_dm_((*agents_)[start_ + tuple_id]);
auto* temporary_data = get_dm_((*agents_)[start_ + tuple_id]);
for (uint64_t i = 0; i < static_cast<uint64_t>(this->NumberOfComponents);
++i) {
tuple[i] = static_cast<double>(data[i]);
tuple[i] = static_cast<double>(temporary_data[i]);
if (mode_ == Param::MappedDataArrayMode::kCache) {
data_[idx + i] = data[i];
data_[idx + i] = temporary_data[i];
is_matching_[idx + i] = match_value_;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/visualization/root/adaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class RootAdaptor {
canvas_->GetListOfPrimitives()->Add(gGeoManager->GetTopVolume(),
opt.c_str());
}
canvas_->SetCanvasSize(w, h);
canvas_->SetCanvasSize(static_cast<UInt_t>(w), static_cast<UInt_t>(h));
canvas_->Update();
canvas_->Draw();
}
Expand Down

0 comments on commit 862a1b0

Please sign in to comment.